Skip to content

Commit ba19274

Browse files
committed
test: migrate testsuite message_format to snapbox
1 parent c7c28d9 commit ba19274

File tree

1 file changed

+54
-26
lines changed

1 file changed

+54
-26
lines changed

tests/testsuite/message_format.rs

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Tests for --message-format flag.
22
3-
#![allow(deprecated)]
4-
5-
use cargo_test_support::{basic_lib_manifest, basic_manifest, project};
3+
use cargo_test_support::{basic_lib_manifest, basic_manifest, project, str};
64

75
#[cargo_test]
86
fn cannot_specify_two() {
@@ -13,12 +11,14 @@ fn cannot_specify_two() {
1311

1412
let formats = ["human", "json", "short"];
1513

16-
let two_kinds = "error: cannot specify two kinds of `message-format` arguments\n";
1714
for a in formats.iter() {
1815
for b in formats.iter() {
1916
p.cargo(&format!("build --message-format {},{}", a, b))
2017
.with_status(101)
21-
.with_stderr(two_kinds)
18+
.with_stderr_data(str![[r#"
19+
[ERROR] cannot specify two kinds of `message-format` arguments
20+
21+
"#]])
2222
.run();
2323
}
2424
}
@@ -66,17 +66,23 @@ fn cargo_renders() {
6666

6767
p.cargo("check --message-format json-render-diagnostics")
6868
.with_status(101)
69-
.with_stdout(
70-
"{\"reason\":\"compiler-artifact\",[..]\n\
71-
{\"reason\":\"build-finished\",\"success\":false}",
72-
)
73-
.with_stderr_contains(
74-
"\
75-
[CHECKING] bar [..]
76-
[CHECKING] foo [..]
77-
error[..]`main`[..]
78-
",
79-
)
69+
.with_stdout_data(str![[r#"
70+
{"reason":"compiler-artifact","package_id":"path+[ROOTURL]/foo/bar#0.1.0","manifest_path":"[..]","target":{"kind":["lib"],"crate_types":["lib"],"name":"bar","src_path":"[..]","edition":"2015","doc":true,"doctest":true,"test":true},"profile":{"opt_level":"0","debuginfo":2,"debug_assertions":true,"overflow_checks":true,"test":false},"features":[],"filenames":["[..]"],"executable":null,"fresh":false}
71+
{"reason":"build-finished","success":false}
72+
73+
"#]])
74+
.with_stderr_data(str![[r#"
75+
[LOCKING] 2 packages to latest compatible versions
76+
[CHECKING] bar v0.1.0 ([ROOT]/foo/bar)
77+
[CHECKING] foo v0.1.0 ([ROOT]/foo)
78+
error[E0601]: `main` function not found in crate `foo`
79+
|
80+
= [NOTE] consider adding a `main` function to `src/main.rs`
81+
82+
For more information about this error, try `rustc --explain E0601`.
83+
[ERROR] could not compile `foo` (bin "foo") due to 1 previous error
84+
85+
"#]])
8086
.run();
8187
}
8288

@@ -89,13 +95,12 @@ fn cargo_renders_short() {
8995

9096
p.cargo("check --message-format json-render-diagnostics,json-diagnostic-short")
9197
.with_status(101)
92-
.with_stderr_contains(
93-
"\
94-
[CHECKING] foo [..]
95-
error[..]`main`[..]
96-
",
97-
)
98-
.with_stderr_does_not_contain("note:")
98+
.with_stderr_data(str![[r#"
99+
[CHECKING] foo v0.1.0 ([ROOT]/foo)
100+
error[E0601]: `main` function not found in crate `foo`
101+
[ERROR] could not compile `foo` (bin "foo") due to 1 previous error
102+
103+
"#]])
99104
.run();
100105
}
101106

@@ -108,7 +113,13 @@ fn cargo_renders_ansi() {
108113

109114
p.cargo("check --message-format json-diagnostic-rendered-ansi")
110115
.with_status(101)
111-
.with_stdout_contains("[..]\\u001b[38;5;9merror[..]")
116+
.with_stdout_data(str![[r#"
117+
{"reason":"compiler-message","package_id":"path+[ROOTURL]/foo#0.1.0","manifest_path":"[..]","target":{"kind":["bin"],"crate_types":["bin"],"name":"foo","src_path":"[..]","edition":"2015","doc":true,"doctest":false,"test":true},"message":{"$message_type":"diagnostic","message":"`main` function not found in crate `foo`","code":{"code":"E0601","explanation":"No `main` function was found in a binary crate./n/nTo fix this error, add a `main` function:/n/n```/nfn main() {/n // Your program will start here./n println!(/"Hello world!/");/n}/n```/n/nIf you don't know the basics of Rust, you can look at the/n[Rust Book][rust-book] to get started./n/n[rust-book]: https://doc.rust-lang.org/book//n"},"level":"error","spans":[{"file_name":"src/main.rs","byte_start":0,"byte_end":0,"line_start":0,"line_end":0,"column_start":1,"column_end":1,"is_primary":true,"text":[],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"consider adding a `main` function to `src/main.rs`","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"[..]error[E0601][..]: `main` function not found in crate `foo`[..]|[..]= [..]: consider adding a `main` function to `src/main.rs`[..]/n/n"}}
118+
{"reason":"compiler-message","package_id":"path+[ROOTURL]/foo#0.1.0","manifest_path":"[..]","target":{"kind":["bin"],"crate_types":["bin"],"name":"foo","src_path":"[..]","edition":"2015","doc":true,"doctest":false,"test":true},"message":{"$message_type":"diagnostic","message":"aborting due to 1 previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"[..]error[..]: aborting due to 1 previous error[..]/n/n"}}
119+
{"reason":"compiler-message","package_id":"path+[ROOTURL]/foo#0.1.0","manifest_path":"[..]","target":{"kind":["bin"],"crate_types":["bin"],"name":"foo","src_path":"[..]","edition":"2015","doc":true,"doctest":false,"test":true},"message":{"$message_type":"diagnostic","message":"For more information about this error, try `rustc --explain E0601`.","code":null,"level":"failure-note","spans":[],"children":[],"rendered":"[..]For more information about this error, try `rustc --explain E0601`.[..]/n"}}
120+
{"reason":"build-finished","success":false}
121+
122+
"#]])
112123
.run();
113124
}
114125

@@ -129,7 +140,24 @@ fn cargo_renders_doctests() {
129140

130141
p.cargo("test --doc --message-format short")
131142
.with_status(101)
132-
.with_stdout_contains("src/lib.rs:2:1: error[E0425]:[..]")
133-
.with_stdout_contains("[..]src/lib.rs - bar (line 1)[..]")
143+
.with_stdout_data(str![[r#"
144+
145+
running 1 test
146+
test src/lib.rs - bar (line 1) ... FAILED
147+
148+
failures:
149+
150+
---- src/lib.rs - bar (line 1) stdout ----
151+
src/lib.rs:2:1: error[E0425]: cannot find function `bar` in this scope
152+
[ERROR] aborting due to 1 previous error
153+
Couldn't compile the test.
154+
155+
failures:
156+
src/lib.rs - bar (line 1)
157+
158+
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s
159+
160+
161+
"#]])
134162
.run();
135163
}

0 commit comments

Comments
 (0)