Skip to content

Commit

Permalink
fix: latest version panic (#315)
Browse files Browse the repository at this point in the history
* fix parsing version strings

* fix error message

* delete toolchain_override

* use .get() in plugins check as well

* fix clippy

* update fuelup_check tests

* clippy
  • Loading branch information
eightfilms authored Dec 15, 2022
1 parent 1309f6b commit ee798df
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 48 deletions.
73 changes: 36 additions & 37 deletions src/ops/fuelup_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
target_triple::TargetTriple,
toolchain::{DistToolchainDescription, Toolchain},
};
use anyhow::{bail, Result};
use anyhow::Result;
use component::{self, Components};
use semver::Version;
use std::io::Write;
Expand Down Expand Up @@ -111,50 +111,49 @@ fn check_toolchain(toolchain: &str, verbose: bool) -> Result<()> {
bold(|s| writeln!(s, "{}", &toolchain.name));

for component in Components::collect_exclude_plugins()? {
let component_executable = toolchain.bin_path.join(&component.name);
let mut latest_version = &latest_package_versions[&component.name];
match Command::new(&component_executable)
.arg("--version")
.output()
{
Ok(o) => {
let output = String::from_utf8_lossy(&o.stdout).into_owned();

match output.split_whitespace().last() {
Some(v) => {
let version = Version::parse(v)?;
bold(|s| write!(s, " {} - ", &component.name));
compare_and_print_versions(&version, latest_version)?;
}
None => {
error!(" {} - Error getting version string", &component.name);
if let Some(latest_version) = latest_package_versions.get(&component.name) {
let component_executable = toolchain.bin_path.join(&component.name);
match Command::new(&component_executable)
.arg("--version")
.output()
{
Ok(o) => {
let output = String::from_utf8_lossy(&o.stdout).into_owned();

match output.split_whitespace().last() {
Some(v) => {
let version = Version::parse(v)?;
bold(|s| write!(s, " {} - ", &component.name));
compare_and_print_versions(&version, latest_version)?;
}
None => {
error!(" {} - Error getting version string", &component.name);
}
}
}
}
Err(_) => bail!(""),
};
Err(_) => error!(" {} - Error getting version string", &component.name),
};

if verbose && component.name == component::FORC {
for plugin in component::Components::collect_plugins()? {
if !plugin.is_main_executable() {
bold(|s| writeln!(s, " - {}", plugin.name));
}
if verbose && component.name == component::FORC {
for plugin in component::Components::collect_plugins()? {
if !plugin.is_main_executable() {
bold(|s| writeln!(s, " - {}", plugin.name));
}

for (index, executable) in plugin.executables.iter().enumerate() {
let plugin_executable = toolchain.bin_path.join(executable);
for (index, executable) in plugin.executables.iter().enumerate() {
let plugin_executable = toolchain.bin_path.join(executable);

let mut plugin_name = &plugin.name;
let mut plugin_name = &plugin.name;

if !plugin.is_main_executable() {
print!(" ");
plugin_name = &plugin.executables[index];
}
if !plugin.is_main_executable() {
print!(" ");
plugin_name = &plugin.executables[index];
}

if latest_package_versions.contains_key(&plugin.name) {
latest_version = &latest_package_versions[&plugin.name];
if let Some(latest_version) = latest_package_versions.get(&plugin.name) {
check_plugin(&plugin_executable, plugin_name, latest_version)?;
}
}

check_plugin(&plugin_executable, plugin_name, latest_version)?;
}
}
}
Expand Down
28 changes: 17 additions & 11 deletions tests/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,29 +239,35 @@ fn fuelup_toolchain_uninstall_active_switches_default() -> Result<()> {

#[test]
fn fuelup_check() -> Result<()> {
let latest = format!("latest-{}\n", TargetTriple::from_host().unwrap());
let beta_1 = format!("beta-1-{}\n", TargetTriple::from_host().unwrap());
let forc = "forc -";
let fuel_core = "fuel-core -";
let fuel_indexer = "fuel-indexer -";
testcfg::setup(FuelupState::Empty, &|cfg| {
let output = cfg.fuelup(&["check"]);
assert!(output.status.success());
assert!(!output.stdout.contains(&latest));
assert!(!output.stdout.contains(forc));
assert!(!output.stdout.contains(fuel_core));
assert!(!output.stdout.contains(fuel_indexer));
})?;

// Test that only the 'latest' toolchain shows.
testcfg::setup(FuelupState::LatestAndCustomInstalled, &|cfg| {
let output = cfg.fuelup(&["check"]);
assert_eq!(
output.stdout,
format!("latest-{}\n\n", TargetTriple::from_host().unwrap())
);
assert!(output.status.success());
assert!(output.stdout.contains(&latest));
assert!(output.stdout.contains(forc));
assert!(output.stdout.contains(fuel_core));
assert!(output.stdout.contains(fuel_indexer));
})?;

// Test that toolchain names with '-' inside are parsed correctly.
testcfg::setup(FuelupState::Beta1Installed, &|cfg| {
let output = cfg.fuelup(&["check"]);
assert_eq!(
output.stdout,
format!("beta-1-{}\n\n", TargetTriple::from_host().unwrap())
);
assert!(output.status.success());
assert!(output.stdout.contains(&beta_1));
assert!(output.stdout.contains(forc));
assert!(output.stdout.contains(fuel_core));
assert!(!output.stdout.contains(fuel_indexer));
})?;

Ok(())
Expand Down

0 comments on commit ee798df

Please sign in to comment.