Skip to content

Commit

Permalink
fix: fuelup check (#273)
Browse files Browse the repository at this point in the history
* fix: fuelup check

* add more comprehensive tests for 'fuelup check'

* use TargetTriple from host
  • Loading branch information
eightfilms authored Nov 16, 2022
1 parent 8234768 commit a193d26
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
20 changes: 12 additions & 8 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,21 @@ impl Config {

pub(crate) fn list_dist_toolchains(&self) -> Result<Vec<String>> {
if self.toolchains_dir.is_dir() {
let toolchains: Vec<String> = fs::read_dir(&self.toolchains_dir)?
let mut dist_toolchains: Vec<String> = Vec::new();
let installed_toolchains: Vec<String> = fs::read_dir(&self.toolchains_dir)?
.filter_map(io::Result::ok)
.filter(|e| {
e.file_type().map(|f| f.is_dir()).unwrap_or(false)
&& RESERVED_TOOLCHAIN_NAMES.iter().any(|t| {
e.file_name().to_string_lossy() == format_toolchain_with_target(t)
})
})
.filter(|e| e.file_type().map(|f| f.is_dir()).unwrap_or(false))
.map(|e| e.file_name().into_string().ok().unwrap_or_default())
.collect();
Ok(toolchains)

for name in RESERVED_TOOLCHAIN_NAMES {
let dist_toolchain = format_toolchain_with_target(name);
if installed_toolchains.contains(&dist_toolchain) {
dist_toolchains.push(name.to_string())
}
}

Ok(dist_toolchains)
} else {
Ok(Vec::new())
}
Expand Down
4 changes: 1 addition & 3 deletions src/ops/fuelup_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ pub fn check(command: CheckCommand) -> Result<()> {
let cfg = Config::from_env()?;

for toolchain in cfg.list_dist_toolchains()? {
// TODO: remove once date/target are supported
let name = toolchain.split_once('-').unwrap_or_default().0;
check_toolchain(name, verbose)?;
check_toolchain(&toolchain, verbose)?;
}

check_fuelup()?;
Expand Down
20 changes: 20 additions & 0 deletions tests/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,26 @@ fn fuelup_check() -> Result<()> {
assert!(output.status.success());
})?;

// 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());
})?;

// 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());
})?;

Ok(())
}

Expand Down
10 changes: 10 additions & 0 deletions tests/testcfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum FuelupState {
LatestAndCustomInstalled,
LatestAndNightlyInstalled,
NightlyAndNightlyDateInstalled,
Beta1Installed,
}

pub struct TestCfg {
Expand Down Expand Up @@ -140,6 +141,7 @@ pub fn setup(state: FuelupState, f: &dyn Fn(&mut TestCfg)) -> Result<()> {
let target = TargetTriple::from_host().unwrap();
let latest = format!("latest-{}", target);
let nightly = format!("nightly-{}", target);
let beta_1 = format!("beta-1-{}", target);

match state {
FuelupState::Empty => {}
Expand Down Expand Up @@ -188,6 +190,14 @@ pub fn setup(state: FuelupState, f: &dyn Fn(&mut TestCfg)) -> Result<()> {
)?;
setup_settings_file(&tmp_fuelup_root_path, &nightly)?;
}
FuelupState::Beta1Installed => {
setup_toolchain(&tmp_fuelup_root_path, &beta_1)?;
setup_toolchain(
&tmp_fuelup_root_path,
&format!("beta-1-{}-{}", DATE, target),
)?;
setup_settings_file(&tmp_fuelup_root_path, &beta_1)?;
}
}

f(&mut TestCfg::new(
Expand Down

0 comments on commit a193d26

Please sign in to comment.