Skip to content

Commit a6fdc01

Browse files
committed
Move test to cargo_command.rs
1 parent 44970a8 commit a6fdc01

File tree

2 files changed

+84
-83
lines changed

2 files changed

+84
-83
lines changed

tests/testsuite/cargo_command.rs

+84
Original file line numberDiff line numberDiff line change
@@ -573,3 +573,87 @@ fn full_did_you_mean() {
573573
"#]])
574574
.run();
575575
}
576+
577+
#[cargo_test]
578+
fn overwrite_cargo_environment_variable() {
579+
// If passed arguments `arg1 arg2 ...`, this program runs them as a command.
580+
// If passed no arguments, this program simply prints `$CARGO`.
581+
let p = project()
582+
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
583+
.file(
584+
"src/main.rs",
585+
r#"
586+
fn main() {
587+
let mut args = std::env::args().skip(1);
588+
if let Some(arg1) = args.next() {
589+
let status = std::process::Command::new(arg1)
590+
.args(args)
591+
.status()
592+
.unwrap();
593+
assert!(status.success());
594+
} else {
595+
eprintln!("{}", std::env::var("CARGO").unwrap());
596+
}
597+
}
598+
"#,
599+
)
600+
.build();
601+
602+
// Create two other cargo binaries in the project root, one with the wrong
603+
// name and one with the right name.
604+
let cargo_exe = cargo_test_support::cargo_exe();
605+
let wrong_name_path = p
606+
.root()
607+
.join(format!("wrong_name{}", env::consts::EXE_SUFFIX));
608+
let other_cargo_path = p.root().join(cargo_exe.file_name().unwrap());
609+
std::fs::hard_link(&cargo_exe, &wrong_name_path).unwrap();
610+
std::fs::hard_link(&cargo_exe, &other_cargo_path).unwrap();
611+
612+
// The output of each of the following commands should be `path-to-cargo`:
613+
// ```
614+
// cargo run
615+
// cargo run -- cargo run
616+
// cargo run -- wrong_name run
617+
// ```
618+
619+
let cargo = cargo_exe.display().to_string();
620+
let wrong_name = wrong_name_path.display().to_string();
621+
let stderr_cargo = format!(
622+
"{}[EXE]\n",
623+
cargo_exe
624+
.canonicalize()
625+
.unwrap()
626+
.with_extension("")
627+
.to_str()
628+
.unwrap()
629+
);
630+
631+
for cmd in [
632+
"run",
633+
&format!("run -- {cargo} run"),
634+
&format!("run -- {wrong_name} run"),
635+
] {
636+
p.cargo(cmd).with_stderr_contains(&stderr_cargo).run();
637+
}
638+
639+
// The output of the following command should be `path-to-other-cargo`:
640+
// ```
641+
// cargo run -- other_cargo run
642+
// ```
643+
644+
let other_cargo = other_cargo_path.display().to_string();
645+
let stderr_other_cargo = format!(
646+
"{}[EXE]\n",
647+
other_cargo_path
648+
.canonicalize()
649+
.unwrap()
650+
.with_extension("")
651+
.to_str()
652+
.unwrap()
653+
.replace(p.root().parent().unwrap().to_str().unwrap(), "[ROOT]")
654+
);
655+
656+
p.cargo(&format!("run -- {other_cargo} run"))
657+
.with_stderr_contains(stderr_other_cargo)
658+
.run();
659+
}

tests/testsuite/freshness.rs

-83
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Tests for fingerprinting (rebuild detection).
22
3-
use std::env::consts::EXE_SUFFIX;
43
use std::fs::{self, OpenOptions};
54
use std::io;
65
use std::io::prelude::*;
@@ -3183,85 +3182,3 @@ fn use_mtime_cache_in_cargo_home() {
31833182
"#]])
31843183
.run();
31853184
}
3186-
3187-
#[cargo_test]
3188-
fn overwrite_cargo_environment_variable() {
3189-
// If passed arguments `arg1 arg2 ...`, this program runs them as a command.
3190-
// If passed no arguments, this program simply prints `$CARGO`.
3191-
let p = project()
3192-
.file("Cargo.toml", &basic_manifest("foo", "1.0.0"))
3193-
.file(
3194-
"src/main.rs",
3195-
r#"
3196-
fn main() {
3197-
let mut args = std::env::args().skip(1);
3198-
if let Some(arg1) = args.next() {
3199-
let status = std::process::Command::new(arg1)
3200-
.args(args)
3201-
.status()
3202-
.unwrap();
3203-
assert!(status.success());
3204-
} else {
3205-
eprintln!("{}", std::env::var("CARGO").unwrap());
3206-
}
3207-
}
3208-
"#,
3209-
)
3210-
.build();
3211-
3212-
// Create two other cargo binaries in the project root, one with the wrong
3213-
// name and one with the right name.
3214-
let cargo_exe = cargo_test_support::cargo_exe();
3215-
let wrong_name_path = p.root().join(format!("wrong_name{EXE_SUFFIX}"));
3216-
let other_cargo_path = p.root().join(cargo_exe.file_name().unwrap());
3217-
std::fs::hard_link(&cargo_exe, &wrong_name_path).unwrap();
3218-
std::fs::hard_link(&cargo_exe, &other_cargo_path).unwrap();
3219-
3220-
// The output of each of the following commands should be `path-to-cargo`:
3221-
// ```
3222-
// cargo run
3223-
// cargo run -- cargo run
3224-
// cargo run -- wrong_name run
3225-
// ```
3226-
3227-
let cargo = cargo_exe.display().to_string();
3228-
let wrong_name = wrong_name_path.display().to_string();
3229-
let stderr_cargo = format!(
3230-
"{}[EXE]\n",
3231-
cargo_exe
3232-
.canonicalize()
3233-
.unwrap()
3234-
.with_extension("")
3235-
.to_str()
3236-
.unwrap()
3237-
);
3238-
3239-
for cmd in [
3240-
"run",
3241-
&format!("run -- {cargo} run"),
3242-
&format!("run -- {wrong_name} run"),
3243-
] {
3244-
p.cargo(cmd).with_stderr_contains(&stderr_cargo).run();
3245-
}
3246-
3247-
// The output of the following command should be `path-to-other-cargo`:
3248-
// ```
3249-
// cargo run -- other_cargo run
3250-
// ```
3251-
3252-
let other_cargo = other_cargo_path.display().to_string();
3253-
let stderr_other_cargo = format!(
3254-
"{}[EXE]\n",
3255-
other_cargo_path
3256-
.canonicalize()
3257-
.unwrap()
3258-
.with_extension("")
3259-
.to_str()
3260-
.unwrap()
3261-
.replace(p.root().parent().unwrap().to_str().unwrap(), "[ROOT]")
3262-
);
3263-
3264-
p.cargo(&format!("run -- {other_cargo} run"))
3265-
.with_stderr_contains(stderr_other_cargo)
3266-
.run();
3267-
}

0 commit comments

Comments
 (0)