From 07e56031ab3488863b3d4c484625048c002119f3 Mon Sep 17 00:00:00 2001 From: Sophie Date: Sun, 26 Nov 2023 23:38:54 -0500 Subject: [PATCH] update more tests --- tests/default.rs | 12 ++++-- tests/show.rs | 96 ++++++++++++++++++++++++++---------------------- 2 files changed, 60 insertions(+), 48 deletions(-) diff --git a/tests/default.rs b/tests/default.rs index c12791185..fb9a7479e 100644 --- a/tests/default.rs +++ b/tests/default.rs @@ -84,20 +84,24 @@ fn fuelup_default_nightly() -> Result<()> { #[test] fn fuelup_default_nightly_and_nightly_date() -> Result<()> { testcfg::setup(FuelupState::NightlyAndNightlyDateInstalled, &|cfg| { - let output = cfg.fuelup(&["default", "nightly"]); + let stripped = strip_ansi_escapes::strip(cfg.fuelup(&["default", "nightly"]).stdout); + let stdout = String::from_utf8_lossy(&stripped); + let expected_stdout = format!( "default toolchain set to 'nightly-{}'\n", TargetTriple::from_host().unwrap() ); - assert_eq!(output.stdout, expected_stdout); + assert_eq!(stdout, expected_stdout); - let output = cfg.fuelup(&["default", &format!("nightly-{DATE}")]); + let stripped = + strip_ansi_escapes::strip(cfg.fuelup(&["default", &format!("nightly-{DATE}")]).stdout); + let stdout = String::from_utf8_lossy(&stripped); let expected_stdout = format!( "default toolchain set to 'nightly-{}-{}'\n", DATE, TargetTriple::from_host().unwrap() ); - assert_eq!(output.stdout, expected_stdout); + assert_eq!(stdout, expected_stdout); })?; Ok(()) diff --git a/tests/show.rs b/tests/show.rs index 332b1f742..69b49569b 100644 --- a/tests/show.rs +++ b/tests/show.rs @@ -13,7 +13,8 @@ use testcfg::FuelupState; fn fuelup_show_latest() -> Result<()> { testcfg::setup(FuelupState::AllInstalled, &|cfg| { cfg.fuelup(&["show"]); - let stdout = cfg.fuelup(&["show"]).stdout; + let stripped = strip_ansi_escapes::strip(cfg.fuelup(&["show"]).stdout); + let stdout = String::from_utf8_lossy(&stripped); let target = TargetTriple::from_host().unwrap(); let mut lines = stdout.lines(); @@ -29,7 +30,7 @@ nightly-{target} nightly-2022-08-30-{target} active toolchain ------------------ +---------------- latest-{target} (default) forc : 0.1.0 - forc-client @@ -43,7 +44,7 @@ latest-{target} (default) - forc-tx : 0.1.0 - forc-wallet : 0.1.0 fuel-core : 0.1.0 - fuel-core-keygen - not found + fuel-core-keygen : not found fuel-indexer : 0.1.0 "# ); @@ -57,7 +58,8 @@ latest-{target} (default) fn fuelup_show_and_switch() -> Result<()> { testcfg::setup(FuelupState::AllInstalled, &|cfg| { cfg.fuelup(&["show"]); - let mut stdout = cfg.fuelup(&["show"]).stdout; + let mut stripped = strip_ansi_escapes::strip(cfg.fuelup(&["show"]).stdout); + let mut stdout = String::from_utf8_lossy(&stripped); let mut target = TargetTriple::from_host().unwrap(); let mut lines = stdout.lines(); @@ -73,7 +75,7 @@ nightly-{target} nightly-2022-08-30-{target} active toolchain ------------------ +---------------- latest-{target} (default) forc : 0.1.0 - forc-client @@ -87,7 +89,7 @@ latest-{target} (default) - forc-tx : 0.1.0 - forc-wallet : 0.1.0 fuel-core : 0.1.0 - fuel-core-keygen - not found + fuel-core-keygen : not found fuel-indexer : 0.1.0 "# ); @@ -95,7 +97,8 @@ latest-{target} (default) assert!(!stdout.contains("fuels versions")); cfg.fuelup(&["default", "nightly"]); - stdout = cfg.fuelup(&["show"]).stdout; + stripped = strip_ansi_escapes::strip(cfg.fuelup(&["show"]).stdout); + stdout = String::from_utf8_lossy(&stripped); target = TargetTriple::from_host().unwrap(); let expected_stdout = &format!( @@ -107,7 +110,7 @@ nightly-{target} (default) nightly-2022-08-30-{target} active toolchain ------------------ +---------------- nightly-{target} (default) forc : 0.2.0 - forc-client @@ -121,7 +124,7 @@ nightly-{target} (default) - forc-tx : 0.2.0 - forc-wallet : 0.2.0 fuel-core : 0.2.0 - fuel-core-keygen - not found + fuel-core-keygen : not found fuel-indexer : 0.2.0 "# ); @@ -136,7 +139,8 @@ nightly-{target} (default) fn fuelup_show_custom() -> Result<()> { testcfg::setup(FuelupState::Empty, &|cfg| { cfg.fuelup(&["toolchain", "new", "my_toolchain"]); - let stdout = cfg.fuelup(&["show"]).stdout; + let stripped = strip_ansi_escapes::strip(cfg.fuelup(&["show"]).stdout); + let stdout = String::from_utf8_lossy(&stripped); let mut lines = stdout.lines(); assert_eq!( @@ -151,23 +155,24 @@ installed toolchains my_toolchain (default) active toolchain ------------------ +---------------- my_toolchain (default) - forc - not found + forc : not found - forc-client - - forc-deploy - not found - - forc-run - not found - - forc-doc - not found - - forc-explore - not found - - forc-fmt - not found - - forc-index - not found - - forc-lsp - not found - - forc-tx - not found - - forc-wallet - not found - fuel-core - not found - fuel-core-keygen - not found - fuel-indexer - not found + - forc-deploy : not found + - forc-run : not found + - forc-doc : not found + - forc-explore : not found + - forc-fmt : not found + - forc-index : not found + - forc-lsp : not found + - forc-tx : not found + - forc-wallet : not found + fuel-core : not found + fuel-core-keygen : not found + fuel-indexer : not found "#; + assert!(stdout.contains(expected_stdout)); assert!(!stdout.contains("fuels versions")); })?; @@ -177,7 +182,8 @@ my_toolchain (default) #[test] fn fuelup_show_override() -> Result<()> { testcfg::setup(FuelupState::LatestWithBetaOverride, &|cfg| { - let stdout = cfg.fuelup(&["show"]).stdout; + let stripped = strip_ansi_escapes::strip(cfg.fuelup(&["show"]).stdout); + let stdout = String::from_utf8_lossy(&stripped); let mut lines = stdout.lines(); assert_eq!( @@ -194,22 +200,22 @@ installed toolchains latest-{target} (default) active toolchain ------------------ +---------------- beta-1-{target} (override), path: {} - forc - not found + forc : not found - forc-client - - forc-deploy - not found - - forc-run - not found - - forc-doc - not found - - forc-explore - not found - - forc-fmt - not found - - forc-index - not found - - forc-lsp - not found - - forc-tx - not found - - forc-wallet - not found - fuel-core - not found - fuel-core-keygen - not found - fuel-indexer - not found + - forc-deploy : not found + - forc-run : not found + - forc-doc : not found + - forc-explore : not found + - forc-fmt : not found + - forc-index : not found + - forc-lsp : not found + - forc-tx : not found + - forc-wallet : not found + fuel-core : not found + fuel-core-keygen : not found + fuel-indexer : not found "#, cfg.home.join(FUEL_TOOLCHAIN_TOML_FILE).display() ); @@ -222,7 +228,8 @@ beta-1-{target} (override), path: {} #[test] fn fuelup_show_latest_then_override() -> Result<()> { testcfg::setup(FuelupState::AllInstalled, &|cfg| { - let mut stdout = cfg.fuelup(&["show"]).stdout; + let mut stripped = strip_ansi_escapes::strip(cfg.fuelup(&["show"]).stdout); + let mut stdout = String::from_utf8_lossy(&stripped); let mut lines = stdout.lines(); assert_eq!( @@ -240,7 +247,7 @@ nightly-{target} nightly-2022-08-30-{target} active toolchain ------------------ +---------------- latest-{target} (default) forc : 0.1.0 - forc-client @@ -254,7 +261,7 @@ latest-{target} (default) - forc-tx : 0.1.0 - forc-wallet : 0.1.0 fuel-core : 0.1.0 - fuel-core-keygen - not found + fuel-core-keygen : not found fuel-indexer : 0.1.0 "#, ); @@ -274,7 +281,8 @@ latest-{target} (default) std::fs::write(toolchain_override.path, document.to_string()) .unwrap_or_else(|_| panic!("Failed to write {FUEL_TOOLCHAIN_TOML_FILE}")); - stdout = cfg.fuelup(&["show"]).stdout; + stripped = strip_ansi_escapes::strip(cfg.fuelup(&["show"]).stdout); + stdout = String::from_utf8_lossy(&stripped); let mut lines = stdout.lines(); while let Some(line) = lines.next() { @@ -302,7 +310,7 @@ latest-{target} (default) - forc-tx : 0.2.0 - forc-wallet : 0.2.0 fuel-core : 0.2.0 - fuel-core-keygen - not found + fuel-core-keygen : not found fuel-indexer : 0.2.0 "#; assert!(stdout.contains(expected_stdout));