Skip to content

Commit

Permalink
test: migrate binary_name to snapbox
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Jun 11, 2024
1 parent c5a6a6c commit a438457
Showing 1 changed file with 54 additions and 38 deletions.
92 changes: 54 additions & 38 deletions tests/testsuite/binary_name.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![allow(deprecated)]
//! Tests for `cargo-features = ["different-binary-name"]`.

use cargo_test_support::install::{
assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
};
use cargo_test_support::install::assert_has_installed_exe;
use cargo_test_support::install::assert_has_not_installed_exe;
use cargo_test_support::install::cargo_home;
use cargo_test_support::prelude::*;
use cargo_test_support::project;
use cargo_test_support::str;

#[cargo_test]
fn gated() {
Expand All @@ -29,7 +31,17 @@ fn gated() {
p.cargo("build")
.masquerade_as_nightly_cargo(&["different-binary-name"])
.with_status(101)
.with_stderr_contains("[..]feature `different-binary-name` is required")
.with_stderr_data(str![[r#"
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
Caused by:
feature `different-binary-name` is required
The package requires the Cargo feature called `different-binary-name`, but that feature is not stabilized in this version of Cargo ([..]).
Consider adding `cargo-features = ["different-binary-name"]` to the top of Cargo.toml (above the [package] table) to tell Cargo you are opting in to use this unstable feature.
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#different-binary-name for more information about the status of this feature.
"#]])
.run();
}

Expand Down Expand Up @@ -97,12 +109,11 @@ fn binary_name1() {
// Run cargo second time, to verify fingerprint.
p.cargo("build -p foo -v")
.masquerade_as_nightly_cargo(&["different-binary-name"])
.with_stderr(
"\
[FRESH] foo [..]
[FINISHED] [..]
",
)
.with_stderr_data(str![[r#"
[FRESH] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();

// Run cargo clean.
Expand Down Expand Up @@ -180,19 +191,30 @@ fn binary_name2() {
// Check if `cargo test` works
p.cargo("test")
.masquerade_as_nightly_cargo(&["different-binary-name"])
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])",
)
.with_stdout_contains("test tests::check_crabs ... ok")
.with_stderr_data(str![[r#"
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] unittests src/main.rs (target/debug/deps/foo-[..][EXE])
"#]])
.with_stdout_data(str![[r#"
running 1 test
test tests::check_crabs ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
"#]])
.run();

// Check if `cargo run` is able to execute the binary
p.cargo("run")
.masquerade_as_nightly_cargo(&["different-binary-name"])
.with_stdout("Hello, crabs!")
.with_stdout_data(str![[r#"
Hello, crabs!
"#]])
.run();

p.cargo("install")
Expand All @@ -202,7 +224,10 @@ fn binary_name2() {
assert_has_installed_exe(cargo_home(), "007bar");

p.cargo("uninstall")
.with_stderr("[REMOVING] [ROOT]/home/.cargo/bin/007bar[EXE]")
.with_stderr_data(str![[r#"
[REMOVING] [ROOT]/home/.cargo/bin/007bar[EXE]
"#]])
.masquerade_as_nightly_cargo(&["different-binary-name"])
.run();

Expand Down Expand Up @@ -253,7 +278,10 @@ fn check_env_vars() {
.run();
p.cargo("run")
.masquerade_as_nightly_cargo(&["different-binary-name"])
.with_stdout("007bar")
.with_stdout_data(str![[r#"
007bar
"#]])
.run();
p.cargo("test")
.masquerade_as_nightly_cargo(&["different-binary-name"])
Expand Down Expand Up @@ -284,25 +312,13 @@ fn check_msg_format_json() {
.file("src/main.rs", "fn main() { assert!(true) }")
.build();

let output = r#"
{
"reason": "compiler-artifact",
"package_id": "path+file:///[..]/foo#0.0.1",
"manifest_path": "[CWD]/Cargo.toml",
"target": "{...}",
"profile": "{...}",
"features": [],
"filenames": "{...}",
"executable": "[ROOT]/foo/target/debug/007bar[EXE]",
"fresh": false
}
{"reason":"build-finished", "success":true}
"#;

// Run cargo build.
p.cargo("build --message-format=json")
.masquerade_as_nightly_cargo(&["different-binary-name"])
.with_json(output)
.with_stdout_data(str![[r#"
{"executable":"[ROOT]/foo/target/debug/007bar[EXE]","features":[],"filenames":"{...}","fresh":false,"manifest_path":"[ROOT]/foo/Cargo.toml","package_id":"path+[ROOTURL]/foo#0.0.1","profile":"{...}","reason":"compiler-artifact","target":"{...}"}
{"reason":"build-finished","success":true}
"#]].json_lines())
.run();
}

0 comments on commit a438457

Please sign in to comment.