Skip to content

Commit 6d930db

Browse files
author
Jon Gjengset
committed
Don't be as strict in test
On Windows for example, another path is added into the mix, but it doesn't affect what we want to test for.
1 parent 9a69da5 commit 6d930db

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

tests/cli-misc.rs

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
44
pub mod mock;
55

6-
use std::env::consts::EXE_SUFFIX;
76
use std::str;
7+
use std::{env::consts::EXE_SUFFIX, path::Path};
88

99
use rustup::for_host;
1010
use rustup::test::this_host_triple;
@@ -303,50 +303,80 @@ fn rustup_doesnt_prepend_path_unnecessarily() {
303303
setup(&|config| {
304304
expect_ok(config, &["rustup", "default", "nightly"]);
305305

306-
let expect_stderr_ok_env_startswith =
307-
|config: &Config, args: &[&str], env: &[(&str, &str)], expected: &str| {
306+
let expect_stderr_ok_env_first_then =
307+
|config: &Config,
308+
args: &[&str],
309+
env: &[(&str, &str)],
310+
first: &Path,
311+
second: Option<&Path>| {
308312
let out = run(config, args[0], &args[1..], env);
309-
if !out.ok || !out.stderr.starts_with(expected) {
313+
let first_then_second = |list: &str| -> bool {
314+
let mut saw_first = false;
315+
let mut saw_second = false;
316+
for path in std::env::split_paths(list) {
317+
if path == first {
318+
if saw_second {
319+
return false;
320+
}
321+
saw_first = true;
322+
}
323+
if Some(&*path) == second {
324+
if !saw_first {
325+
return false;
326+
}
327+
saw_second = true;
328+
}
329+
}
330+
true
331+
};
332+
if !out.ok || !first_then_second(&out.stderr) {
310333
clitools::print_command(args, &out);
311334
println!("expected.ok: true");
312-
clitools::print_indented("expected.stderr.starts_with", expected);
335+
clitools::print_indented(
336+
"expected.stderr.first_then",
337+
&format!("{} comes before {:?}", first.display(), second),
338+
);
313339
panic!();
314340
}
315341
};
316342

317343
// For all of these, CARGO_HOME/bin will be auto-prepended.
318344
let cargo_home_bin = config.cargodir.join("bin");
319-
expect_stderr_ok_env_startswith(
345+
expect_stderr_ok_env_first_then(
320346
config,
321347
&["cargo", "--echo-path"],
322348
&[],
323-
&format!("{}", cargo_home_bin.display()),
349+
&cargo_home_bin,
350+
None,
324351
);
325-
expect_stderr_ok_env_startswith(
352+
expect_stderr_ok_env_first_then(
326353
config,
327354
&["cargo", "--echo-path"],
328355
&[("PATH", "")],
329-
&format!("{}", cargo_home_bin.display()),
356+
&cargo_home_bin,
357+
None,
330358
);
331359

332360
// Check that CARGO_HOME/bin is prepended to path.
333-
expect_stderr_ok_env_startswith(
361+
expect_stderr_ok_env_first_then(
334362
config,
335363
&["cargo", "--echo-path"],
336364
&[("PATH", &format!("{}", config.exedir.display()))],
337-
&format!("{}:{}", cargo_home_bin.display(), config.exedir.display()),
365+
&cargo_home_bin,
366+
Some(&config.exedir),
338367
);
339368

340369
// But if CARGO_HOME/bin is already on PATH, it will not be prepended again,
341370
// so exedir will take precedence.
342-
expect_stderr_ok_env_startswith(
371+
expect_stderr_ok_env_first_then(
343372
config,
344373
&["cargo", "--echo-path"],
345374
&[(
346375
"PATH",
347376
&format!("{}:{}", config.exedir.display(), cargo_home_bin.display()),
348377
)],
349-
&format!("{}:{}", config.exedir.display(), cargo_home_bin.display()),
378+
&config.exedir,
379+
Some(&cargo_home_bin),
350380
);
351381
});
352382
}

0 commit comments

Comments
 (0)