Skip to content

Slightly improve ergonomics of writing Cargo tests #5197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3705,16 +3705,7 @@ fn build_multiple_packages() {
.file("d2/src/main.rs", "fn main() { println!(\"d2\"); }")
.build();

assert_that(
p.cargo("build")
.arg("-p")
.arg("d1")
.arg("-p")
.arg("d2")
.arg("-p")
.arg("foo"),
execs().with_status(0),
);
assert_that(p.cargo("build -p d1 -p d2 -p foo"), execs().with_status(0));

assert_that(&p.bin("foo"), existing_file());
assert_that(
Expand Down
7 changes: 6 additions & 1 deletion tests/testsuite/cargotest/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,12 @@ impl Project {

pub fn cargo(&self, cmd: &str) -> ProcessBuilder {
let mut p = self.process(&cargo_exe());
p.arg(cmd);
for arg in cmd.split_whitespace() {
if arg.contains('"') || arg.contains('\'') {
panic!("shell-style argument parsing is not supported")
}
p.arg(arg);
}
return p;
}

Expand Down
18 changes: 2 additions & 16 deletions tests/testsuite/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,7 @@ fn clean_multiple_packages() {
.file("d2/src/main.rs", "fn main() { println!(\"d2\"); }")
.build();

assert_that(
p.cargo("build")
.arg("-p")
.arg("d1")
.arg("-p")
.arg("d2")
.arg("-p")
.arg("foo"),
execs().with_status(0),
);
assert_that(p.cargo("build -p d1 -p d2 -p foo"), execs().with_status(0));

let d1_path = &p.build_dir()
.join("debug")
Expand All @@ -108,12 +99,7 @@ fn clean_multiple_packages() {
assert_that(d2_path, existing_file());

assert_that(
p.cargo("clean")
.arg("-p")
.arg("d1")
.arg("-p")
.arg("d2")
.cwd(&p.root().join("src")),
p.cargo("clean -p d1 -p d2").cwd(&p.root().join("src")),
execs().with_status(0).with_stdout(""),
);
assert_that(&p.bin("foo"), existing_file());
Expand Down
13 changes: 3 additions & 10 deletions tests/testsuite/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ fn simple_quiet() {
.build();

assert_that(
p.cargo("run").arg("-q"),
p.cargo("run -q"),
execs().with_status(0).with_stdout("hello"),
);

assert_that(
p.cargo("run").arg("--quiet"),
p.cargo("run --quiet"),
execs().with_status(0).with_stdout("hello"),
);
}
Expand Down Expand Up @@ -1133,12 +1133,5 @@ fn explicit_bin_with_args() {
)
.build();

assert_that(
p.cargo("run")
.arg("--bin")
.arg("foo")
.arg("hello")
.arg("world"),
execs().with_status(0),
);
assert_that(p.cargo("run --bin foo hello world"), execs().with_status(0));
}
39 changes: 5 additions & 34 deletions tests/testsuite/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,7 @@ fn build_main_and_allow_unstable_options() {
.build();

assert_that(
p.cargo("rustc")
.arg("-v")
.arg("--bin")
.arg("foo")
.arg("--")
.arg("-C")
.arg("debug-assertions"),
p.cargo("rustc -v --bin foo -- -C debug-assertions"),
execs().with_status(0).with_stderr(&format!(
"\
[COMPILING] {name} v{version} ({url})
Expand Down Expand Up @@ -208,13 +202,7 @@ fn build_with_args_to_one_of_multiple_binaries() {
.build();

assert_that(
p.cargo("rustc")
.arg("-v")
.arg("--bin")
.arg("bar")
.arg("--")
.arg("-C")
.arg("debug-assertions"),
p.cargo("rustc -v --bin bar -- -C debug-assertions"),
execs().with_status(0).with_stderr(format!(
"\
[COMPILING] foo v0.0.1 ({url})
Expand Down Expand Up @@ -292,13 +280,7 @@ fn build_with_args_to_one_of_multiple_tests() {
.build();

assert_that(
p.cargo("rustc")
.arg("-v")
.arg("--test")
.arg("bar")
.arg("--")
.arg("-C")
.arg("debug-assertions"),
p.cargo("rustc -v --test bar -- -C debug-assertions"),
execs().with_status(0).with_stderr(format!(
"\
[COMPILING] foo v0.0.1 ({url})
Expand Down Expand Up @@ -420,13 +402,7 @@ fn build_only_bar_dependency() {
.build();

assert_that(
foo.cargo("rustc")
.arg("-v")
.arg("-p")
.arg("bar")
.arg("--")
.arg("-C")
.arg("debug-assertions"),
foo.cargo("rustc -v -p bar -- -C debug-assertions"),
execs().with_status(0).with_stderr(
"\
[COMPILING] bar v0.1.0 ([..])
Expand Down Expand Up @@ -504,12 +480,7 @@ fn fail_with_multiple_packages() {
.build();

assert_that(
foo.cargo("rustc")
.arg("-v")
.arg("-p")
.arg("bar")
.arg("-p")
.arg("baz"),
foo.cargo("rustc -v -p bar -p baz"),
execs().with_status(1).with_stderr_contains(
"\
error: The argument '--package <SPEC>' was provided more than once, \
Expand Down
26 changes: 3 additions & 23 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2833,14 +2833,7 @@ fn selective_test_wonky_profile() {
let p = p.build();

assert_that(
p.cargo("test")
.arg("-v")
.arg("--no-run")
.arg("--release")
.arg("-p")
.arg("foo")
.arg("-p")
.arg("a"),
p.cargo("test -v --no-run --release -p foo -p a"),
execs().with_status(0),
);
}
Expand Down Expand Up @@ -3051,13 +3044,7 @@ fn panic_abort_multiple() {
.file("a/src/lib.rs", "")
.build();
assert_that(
p.cargo("test")
.arg("--release")
.arg("-v")
.arg("-p")
.arg("foo")
.arg("-p")
.arg("a"),
p.cargo("test --release -v -p foo -p a"),
execs().with_status(0),
);
}
Expand Down Expand Up @@ -3246,14 +3233,7 @@ fn test_many_with_features() {
.build();

assert_that(
p.cargo("test")
.arg("-v")
.arg("-p")
.arg("a")
.arg("-p")
.arg("foo")
.arg("--features")
.arg("foo"),
p.cargo("test -v -p a -p foo --features foo"),
execs().with_status(0),
);
}
Expand Down