Skip to content

Commit 8c8bf63

Browse files
committed
test: migrate binary_name to snapbox
1 parent c5a6a6c commit 8c8bf63

File tree

1 file changed

+54
-38
lines changed

1 file changed

+54
-38
lines changed

tests/testsuite/binary_name.rs

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
#![allow(deprecated)]
1+
//! Tests for `cargo-features = ["different-binary-name"]`.
22
3-
use cargo_test_support::install::{
4-
assert_has_installed_exe, assert_has_not_installed_exe, cargo_home,
5-
};
3+
use cargo_test_support::install::assert_has_installed_exe;
4+
use cargo_test_support::install::assert_has_not_installed_exe;
5+
use cargo_test_support::install::cargo_home;
6+
use cargo_test_support::prelude::*;
67
use cargo_test_support::project;
8+
use cargo_test_support::str;
79

810
#[cargo_test]
911
fn gated() {
@@ -29,7 +31,17 @@ fn gated() {
2931
p.cargo("build")
3032
.masquerade_as_nightly_cargo(&["different-binary-name"])
3133
.with_status(101)
32-
.with_stderr_contains("[..]feature `different-binary-name` is required")
34+
.with_stderr_data(str![[r#"
35+
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
36+
37+
Caused by:
38+
feature `different-binary-name` is required
39+
40+
The package requires the Cargo feature called `different-binary-name`, but that feature is not stabilized in this version of Cargo ([..]).
41+
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.
42+
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#different-binary-name for more information about the status of this feature.
43+
44+
"#]])
3345
.run();
3446
}
3547

@@ -97,12 +109,11 @@ fn binary_name1() {
97109
// Run cargo second time, to verify fingerprint.
98110
p.cargo("build -p foo -v")
99111
.masquerade_as_nightly_cargo(&["different-binary-name"])
100-
.with_stderr(
101-
"\
102-
[FRESH] foo [..]
103-
[FINISHED] [..]
104-
",
105-
)
112+
.with_stderr_data(str![[r#"
113+
[FRESH] foo v0.0.1 ([ROOT]/foo)
114+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
115+
116+
"#]])
106117
.run();
107118

108119
// Run cargo clean.
@@ -180,19 +191,30 @@ fn binary_name2() {
180191
// Check if `cargo test` works
181192
p.cargo("test")
182193
.masquerade_as_nightly_cargo(&["different-binary-name"])
183-
.with_stderr(
184-
"\
185-
[COMPILING] foo v0.0.1 ([CWD])
186-
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]
187-
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])",
188-
)
189-
.with_stdout_contains("test tests::check_crabs ... ok")
194+
.with_stderr_data(str![[r#"
195+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
196+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
197+
[RUNNING] unittests src/main.rs (target/debug/deps/foo-[..][EXE])
198+
199+
"#]])
200+
.with_stdout_data(str![[r#"
201+
202+
running 1 test
203+
test tests::check_crabs ... ok
204+
205+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
206+
207+
208+
"#]])
190209
.run();
191210

192211
// Check if `cargo run` is able to execute the binary
193212
p.cargo("run")
194213
.masquerade_as_nightly_cargo(&["different-binary-name"])
195-
.with_stdout("Hello, crabs!")
214+
.with_stdout_data(str![[r#"
215+
Hello, crabs!
216+
217+
"#]])
196218
.run();
197219

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

204226
p.cargo("uninstall")
205-
.with_stderr("[REMOVING] [ROOT]/home/.cargo/bin/007bar[EXE]")
227+
.with_stderr_data(str![[r#"
228+
[REMOVING] [ROOT]/home/.cargo/bin/007bar[EXE]
229+
230+
"#]])
206231
.masquerade_as_nightly_cargo(&["different-binary-name"])
207232
.run();
208233

@@ -253,7 +278,10 @@ fn check_env_vars() {
253278
.run();
254279
p.cargo("run")
255280
.masquerade_as_nightly_cargo(&["different-binary-name"])
256-
.with_stdout("007bar")
281+
.with_stdout_data(str![[r#"
282+
007bar
283+
284+
"#]])
257285
.run();
258286
p.cargo("test")
259287
.masquerade_as_nightly_cargo(&["different-binary-name"])
@@ -284,25 +312,13 @@ fn check_msg_format_json() {
284312
.file("src/main.rs", "fn main() { assert!(true) }")
285313
.build();
286314

287-
let output = r#"
288-
{
289-
"reason": "compiler-artifact",
290-
"package_id": "path+file:///[..]/foo#0.0.1",
291-
"manifest_path": "[CWD]/Cargo.toml",
292-
"target": "{...}",
293-
"profile": "{...}",
294-
"features": [],
295-
"filenames": "{...}",
296-
"executable": "[ROOT]/foo/target/debug/007bar[EXE]",
297-
"fresh": false
298-
}
299-
300-
{"reason":"build-finished", "success":true}
301-
"#;
302-
303315
// Run cargo build.
304316
p.cargo("build --message-format=json")
305317
.masquerade_as_nightly_cargo(&["different-binary-name"])
306-
.with_json(output)
318+
.with_stdout_data(str![[r#"
319+
{"executable":"[ROOT]/foo/target/debug/007bar","features":[],"filenames":["[ROOT]/foo/target/debug/007bar[EXE]"],"fresh":false,"manifest_path":"[ROOT]/foo/Cargo.toml","package_id":"path+[ROOTURL]/foo#0.0.1","profile":{"debug_assertions":true,"debuginfo":2,"opt_level":"0","overflow_checks":true,"test":false},"reason":"compiler-artifact","target":{"crate_types":["bin"],"doc":true,"doctest":false,"edition":"2015","kind":["bin"],"name":"foo","src_path":"[ROOT]/foo/src/main.rs","test":true}}
320+
{"reason":"build-finished","success":true}
321+
322+
"#]].json_lines())
307323
.run();
308324
}

0 commit comments

Comments
 (0)