Skip to content

Commit

Permalink
update more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sdankel committed Nov 27, 2023
1 parent 5d048ca commit 07e5603
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 48 deletions.
12 changes: 8 additions & 4 deletions tests/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
96 changes: 52 additions & 44 deletions tests/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -29,7 +30,7 @@ nightly-{target}
nightly-2022-08-30-{target}
active toolchain
-----------------
----------------
latest-{target} (default)
forc : 0.1.0
- forc-client
Expand All @@ -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
"#
);
Expand All @@ -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();
Expand All @@ -73,7 +75,7 @@ nightly-{target}
nightly-2022-08-30-{target}
active toolchain
-----------------
----------------
latest-{target} (default)
forc : 0.1.0
- forc-client
Expand All @@ -87,15 +89,16 @@ 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
"#
);
assert!(stdout.contains(expected_stdout));
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!(
Expand All @@ -107,7 +110,7 @@ nightly-{target} (default)
nightly-2022-08-30-{target}
active toolchain
-----------------
----------------
nightly-{target} (default)
forc : 0.2.0
- forc-client
Expand All @@ -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
"#
);
Expand All @@ -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!(
Expand All @@ -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"));
})?;
Expand All @@ -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!(
Expand All @@ -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()
);
Expand All @@ -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!(
Expand All @@ -240,7 +247,7 @@ nightly-{target}
nightly-2022-08-30-{target}
active toolchain
-----------------
----------------
latest-{target} (default)
forc : 0.1.0
- forc-client
Expand All @@ -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
"#,
);
Expand All @@ -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() {
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 07e5603

Please sign in to comment.