Skip to content

Commit 6c4d59c

Browse files
committed
test: migrate lints_table to snapbox
1 parent f75b4d7 commit 6c4d59c

File tree

1 file changed

+93
-111
lines changed

1 file changed

+93
-111
lines changed

tests/testsuite/lints_table.rs

Lines changed: 93 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//! Tests for `[lints]`
22
3-
#![allow(deprecated)]
4-
53
use cargo_test_support::project;
64
use cargo_test_support::registry::Package;
5+
use cargo_test_support::str;
76

87
#[cargo_test]
98
fn dependency_warning_ignored() {
@@ -43,14 +42,13 @@ fn dependency_warning_ignored() {
4342
.build();
4443

4544
foo.cargo("check")
46-
.with_stderr(
47-
"\
45+
.with_stderr_data(str![[r#"
4846
[LOCKING] 2 packages to latest compatible versions
49-
[CHECKING] [..]
50-
[CHECKING] [..]
51-
[FINISHED] [..]
52-
",
53-
)
47+
[CHECKING] bar v0.0.1 ([ROOT]/bar)
48+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
49+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
50+
51+
"#]])
5452
.run();
5553
}
5654

@@ -74,16 +72,15 @@ fn malformed_on_stable() {
7472

7573
foo.cargo("check")
7674
.with_status(101)
77-
.with_stderr(
78-
"\
75+
.with_stderr_data(str![[r#"
7976
[ERROR] invalid type: integer `20`, expected a lints table
8077
--> Cargo.toml:2:25
8178
|
8279
2 | lints = 20
8380
| ^^
8481
|
85-
",
86-
)
82+
83+
"#]])
8784
.run();
8885
}
8986

@@ -106,16 +103,13 @@ fn fail_on_invalid_tool() {
106103
.file("src/lib.rs", "")
107104
.build();
108105

109-
foo.cargo("check")
110-
.with_stderr(
111-
"\
112-
[WARNING] [CWD]/Cargo.toml: unrecognized lint tool `lints.super-awesome-linter`, specifying unrecognized tools may break in the future.
106+
foo.cargo("check").with_stderr_data(str![[r#"
107+
[WARNING] [ROOT]/foo/Cargo.toml: unrecognized lint tool `lints.super-awesome-linter`, specifying unrecognized tools may break in the future.
113108
supported tools: cargo, clippy, rust, rustdoc
114-
[CHECKING] foo v0.0.1 ([CWD])
115-
[FINISHED] [..]
116-
",
117-
)
118-
.run();
109+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
110+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
111+
112+
"#]]).run();
119113
}
120114

121115
#[cargo_test]
@@ -138,16 +132,15 @@ fn invalid_type_in_lint_value() {
138132

139133
foo.cargo("check")
140134
.with_status(101)
141-
.with_stderr(
142-
"\
135+
.with_stderr_data(str![[r#"
143136
[ERROR] invalid type: integer `-1`, expected a string or map
144137
--> Cargo.toml:8:36
145138
|
146139
8 | rust-2018-idioms = -1
147140
| ^^
148141
|
149-
",
150-
)
142+
143+
"#]])
151144
.run();
152145
}
153146

@@ -172,14 +165,13 @@ fn warn_on_unused_key() {
172165
.build();
173166

174167
foo.cargo("check")
175-
.with_stderr(
176-
"\
177-
[WARNING][..]unused manifest key: `lints.rust.rust-2018-idioms.unused`
178-
[WARNING][..]unused manifest key: `lints.rust.rust-2018-idioms.unused`
179-
[CHECKING] foo v0.0.1 ([CWD])
180-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s
181-
",
182-
)
168+
.with_stderr_data(str![[r#"
169+
[WARNING] [ROOT]/foo/Cargo.toml: unused manifest key: `lints.rust.rust-2018-idioms.unused`
170+
[WARNING] [ROOT]/foo/Cargo.toml: unused manifest key: `lints.rust.rust-2018-idioms.unused`
171+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
172+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
173+
174+
"#]])
183175
.run();
184176
}
185177

@@ -204,14 +196,13 @@ fn fail_on_tool_injection() {
204196

205197
foo.cargo("check")
206198
.with_status(101)
207-
.with_stderr(
208-
"\
209-
[..]
199+
.with_stderr_data(str![[r#"
200+
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
210201
211202
Caused by:
212203
`lints.rust.clippy::cyclomatic_complexity` is not valid lint name; try `lints.clippy.cyclomatic_complexity`
213-
",
214-
)
204+
205+
"#]])
215206
.run();
216207
}
217208

@@ -236,14 +227,13 @@ fn fail_on_redundant_tool() {
236227

237228
foo.cargo("check")
238229
.with_status(101)
239-
.with_stderr(
240-
"\
241-
[..]
230+
.with_stderr_data(str![[r#"
231+
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
242232
243233
Caused by:
244234
`lints.rust.rust::unsafe_code` is not valid lint name; try `lints.rust.unsafe_code`
245-
",
246-
)
235+
236+
"#]])
247237
.run();
248238
}
249239

@@ -268,14 +258,13 @@ fn fail_on_conflicting_tool() {
268258

269259
foo.cargo("check")
270260
.with_status(101)
271-
.with_stderr(
272-
"\
273-
[..]
261+
.with_stderr_data(str![[r#"
262+
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
274263
275264
Caused by:
276265
`lints.rust.super-awesome-tool::unsafe_code` is not a valid lint name
277-
",
278-
)
266+
267+
"#]])
279268
.run();
280269
}
281270

@@ -307,11 +296,11 @@ pub fn foo(num: i32) -> u32 {
307296

308297
foo.cargo("check")
309298
.with_status(101)
310-
.with_stderr_contains(
311-
"\
312-
error: usage of an `unsafe` block
313-
",
314-
)
299+
.with_stderr_data(str![[r#"
300+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
301+
[ERROR] usage of an `unsafe` block
302+
...
303+
"#]])
315304
.run();
316305
}
317306

@@ -346,16 +335,15 @@ pub fn foo(num: i32) -> u32 {
346335

347336
foo.cargo("check")
348337
.with_status(101)
349-
.with_stderr_contains(
350-
"\
351-
error: `workspace` cannot be false
338+
.with_stderr_data(str![[r#"
339+
[ERROR] `workspace` cannot be false
352340
--> Cargo.toml:9:29
353341
|
354342
9 | workspace = false
355343
| ^^^^^
356344
|
357-
",
358-
)
345+
346+
"#]])
359347
.run();
360348
}
361349

@@ -390,11 +378,11 @@ pub fn foo(num: i32) -> u32 {
390378

391379
foo.cargo("check")
392380
.with_status(101)
393-
.with_stderr_contains(
394-
"\
395-
error: usage of an `unsafe` block
396-
",
397-
)
381+
.with_stderr_data(str![[r#"
382+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
383+
[ERROR] usage of an `unsafe` block
384+
...
385+
"#]])
398386
.run();
399387
}
400388

@@ -431,14 +419,13 @@ pub fn foo(num: i32) -> u32 {
431419

432420
foo.cargo("check")
433421
.with_status(101)
434-
.with_stderr(
435-
"\
436-
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
422+
.with_stderr_data(str![[r#"
423+
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
437424
438425
Caused by:
439426
cannot override `workspace.lints` in `lints`, either remove the overrides or `lints.workspace = true` and manually specify the lints
440-
",
441-
)
427+
428+
"#]])
442429
.run();
443430
}
444431

@@ -616,11 +603,11 @@ pub fn foo() -> u32 {
616603

617604
foo.cargo("check")
618605
.with_status(101)
619-
.with_stderr_contains(
620-
"\
621-
error: unused extern crate
622-
",
623-
)
606+
.with_stderr_data(str![[r#"
607+
...
608+
[ERROR] unused extern crate
609+
...
610+
"#]])
624611
.run();
625612
}
626613

@@ -689,11 +676,11 @@ pub fn foo() -> u32 {
689676

690677
foo.cargo("doc")
691678
.with_status(101)
692-
.with_stderr_contains(
693-
"\
694-
error: unresolved link to `bar`
695-
",
696-
)
679+
.with_stderr_data(str![[r#"
680+
[DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
681+
[ERROR] unresolved link to `bar`
682+
...
683+
"#]])
697684
.run();
698685
}
699686

@@ -732,22 +719,20 @@ pub const Ĕ: i32 = 2;
732719
.build();
733720

734721
foo.cargo("check")
735-
.with_stderr(
736-
"\
737-
[CHECKING] foo v0.0.1 ([CWD])
738-
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s
739-
",
740-
)
722+
.with_stderr_data(str![[r#"
723+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
724+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
725+
726+
"#]])
741727
.run();
742728

743729
foo.cargo("test --doc")
744-
.with_stderr(
745-
"\
746-
[COMPILING] foo v0.0.1 ([CWD])
747-
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [..]s
730+
.with_stderr_data(str![[r#"
731+
[COMPILING] foo v0.0.1 ([ROOT]/foo)
732+
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
748733
[DOCTEST] foo
749-
",
750-
)
734+
735+
"#]])
751736
.run();
752737
}
753738

@@ -770,17 +755,16 @@ authors = []
770755
.build();
771756

772757
foo.cargo("check")
773-
.with_stderr(
774-
"\
758+
.with_stderr_data(str![[r#"
775759
[WARNING] unused manifest key `lints.cargo` (may be supported in a future version)
776760
777761
this Cargo does not support nightly features, but if you
778762
switch to nightly channel you can pass
779763
`-Zcargo-lints` to enable this feature.
780-
[CHECKING] foo v0.0.1 ([CWD])
781-
[FINISHED] [..]
782-
",
783-
)
764+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
765+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
766+
767+
"#]])
784768
.run();
785769
}
786770

@@ -807,15 +791,14 @@ im-a-teapot = true
807791

808792
foo.cargo("check")
809793
.masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"])
810-
.with_stderr(
811-
"\
794+
.with_stderr_data(str![[r#"
812795
[WARNING] unused manifest key `lints.cargo` (may be supported in a future version)
813796
814797
consider passing `-Zcargo-lints` to enable this feature.
815-
[CHECKING] foo v0.0.1 ([CWD])
816-
[FINISHED] [..]
817-
",
818-
)
798+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
799+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
800+
801+
"#]])
819802
.run();
820803
}
821804

@@ -843,18 +826,17 @@ im_a_teapot = "warn"
843826

844827
p.cargo("check -Zcargo-lints")
845828
.masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"])
846-
.with_stderr(
847-
"\
848-
warning: `im_a_teapot` is specified
829+
.with_stderr_data(str![[r#"
830+
[WARNING] `im_a_teapot` is specified
849831
--> Cargo.toml:9:1
850832
|
851833
9 | im-a-teapot = true
852834
| ------------------
853835
|
854-
= note: `cargo::im_a_teapot` is set to `warn` in `[lints]`
855-
[CHECKING] foo v0.0.1 ([CWD])
856-
[FINISHED] [..]
857-
",
858-
)
836+
= [NOTE] `cargo::im_a_teapot` is set to `warn` in `[lints]`
837+
[CHECKING] foo v0.0.1 ([ROOT]/foo)
838+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
839+
840+
"#]])
859841
.run();
860842
}

0 commit comments

Comments
 (0)