|
3 | 3 |
|
4 | 4 | pub mod mock; |
5 | 5 |
|
6 | | -use std::env::consts::EXE_SUFFIX; |
7 | 6 | use std::str; |
| 7 | +use std::{env::consts::EXE_SUFFIX, path::Path}; |
8 | 8 |
|
9 | 9 | use rustup::for_host; |
10 | 10 | use rustup::test::this_host_triple; |
@@ -303,50 +303,80 @@ fn rustup_doesnt_prepend_path_unnecessarily() { |
303 | 303 | setup(&|config| { |
304 | 304 | expect_ok(config, &["rustup", "default", "nightly"]); |
305 | 305 |
|
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>| { |
308 | 312 | 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) { |
310 | 333 | clitools::print_command(args, &out); |
311 | 334 | 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 | + ); |
313 | 339 | panic!(); |
314 | 340 | } |
315 | 341 | }; |
316 | 342 |
|
317 | 343 | // For all of these, CARGO_HOME/bin will be auto-prepended. |
318 | 344 | let cargo_home_bin = config.cargodir.join("bin"); |
319 | | - expect_stderr_ok_env_startswith( |
| 345 | + expect_stderr_ok_env_first_then( |
320 | 346 | config, |
321 | 347 | &["cargo", "--echo-path"], |
322 | 348 | &[], |
323 | | - &format!("{}", cargo_home_bin.display()), |
| 349 | + &cargo_home_bin, |
| 350 | + None, |
324 | 351 | ); |
325 | | - expect_stderr_ok_env_startswith( |
| 352 | + expect_stderr_ok_env_first_then( |
326 | 353 | config, |
327 | 354 | &["cargo", "--echo-path"], |
328 | 355 | &[("PATH", "")], |
329 | | - &format!("{}", cargo_home_bin.display()), |
| 356 | + &cargo_home_bin, |
| 357 | + None, |
330 | 358 | ); |
331 | 359 |
|
332 | 360 | // Check that CARGO_HOME/bin is prepended to path. |
333 | | - expect_stderr_ok_env_startswith( |
| 361 | + expect_stderr_ok_env_first_then( |
334 | 362 | config, |
335 | 363 | &["cargo", "--echo-path"], |
336 | 364 | &[("PATH", &format!("{}", config.exedir.display()))], |
337 | | - &format!("{}:{}", cargo_home_bin.display(), config.exedir.display()), |
| 365 | + &cargo_home_bin, |
| 366 | + Some(&config.exedir), |
338 | 367 | ); |
339 | 368 |
|
340 | 369 | // But if CARGO_HOME/bin is already on PATH, it will not be prepended again, |
341 | 370 | // so exedir will take precedence. |
342 | | - expect_stderr_ok_env_startswith( |
| 371 | + expect_stderr_ok_env_first_then( |
343 | 372 | config, |
344 | 373 | &["cargo", "--echo-path"], |
345 | 374 | &[( |
346 | 375 | "PATH", |
347 | 376 | &format!("{}:{}", config.exedir.display(), cargo_home_bin.display()), |
348 | 377 | )], |
349 | | - &format!("{}:{}", config.exedir.display(), cargo_home_bin.display()), |
| 378 | + &config.exedir, |
| 379 | + Some(&cargo_home_bin), |
350 | 380 | ); |
351 | 381 | }); |
352 | 382 | } |
|
0 commit comments