11//! Tests for `[lints]`
22
3- #![ allow( deprecated) ]
4-
53use cargo_test_support:: project;
64use cargo_test_support:: registry:: Package ;
5+ use cargo_test_support:: str;
76
87#[ cargo_test]
98fn dependency_warning_ignored ( ) {
@@ -42,16 +41,13 @@ fn dependency_warning_ignored() {
4241 . file ( "src/lib.rs" , "" )
4342 . build ( ) ;
4443
45- foo. cargo ( "check" )
46- . with_stderr (
47- "\
44+ foo. cargo ( "check" ) . with_stderr_data ( str![ [ r#"
4845[LOCKING] 2 packages to latest compatible versions
49- [CHECKING] [..]
50- [CHECKING] [..]
51- [FINISHED] [..]
52- " ,
53- )
54- . run ( ) ;
46+ [CHECKING] bar v0.0.1 ([ROOT]/bar)
47+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
48+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
49+
50+ "# ] ] ) . run ( ) ;
5551}
5652
5753#[ cargo_test]
@@ -74,16 +70,15 @@ fn malformed_on_stable() {
7470
7571 foo. cargo ( "check" )
7672 . with_status ( 101 )
77- . with_stderr (
78- "\
73+ . with_stderr_data ( str![ [ r#"
7974[ERROR] invalid type: integer `20`, expected a lints table
8075 --> Cargo.toml:2:25
8176 |
82772 | lints = 20
8378 | ^^
8479 |
85- " ,
86- )
80+
81+ "# ] ] )
8782 . run ( ) ;
8883}
8984
@@ -106,16 +101,13 @@ fn fail_on_invalid_tool() {
106101 . file ( "src/lib.rs" , "" )
107102 . build ( ) ;
108103
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.
104+ foo. cargo ( "check" ) . with_stderr_data ( str![ [ r#"
105+ [WARNING] [ROOT]/foo/Cargo.toml: unrecognized lint tool `lints.super-awesome-linter`, specifying unrecognized tools may break in the future.
113106supported tools: cargo, clippy, rust, rustdoc
114- [CHECKING] foo v0.0.1 ([CWD])
115- [FINISHED] [..]
116- " ,
117- )
118- . run ( ) ;
107+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
108+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
109+
110+ "# ] ] ) . run ( ) ;
119111}
120112
121113#[ cargo_test]
@@ -138,16 +130,15 @@ fn invalid_type_in_lint_value() {
138130
139131 foo. cargo ( "check" )
140132 . with_status ( 101 )
141- . with_stderr (
142- "\
133+ . with_stderr_data ( str![ [ r#"
143134[ERROR] invalid type: integer `-1`, expected a string or map
144135 --> Cargo.toml:8:36
145136 |
1461378 | rust-2018-idioms = -1
147138 | ^^
148139 |
149- " ,
150- )
140+
141+ "# ] ] )
151142 . run ( ) ;
152143}
153144
@@ -171,16 +162,13 @@ fn warn_on_unused_key() {
171162 . file ( "src/lib.rs" , "" )
172163 . build ( ) ;
173164
174- 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- )
183- . run ( ) ;
165+ foo. cargo ( "check" ) . with_stderr_data ( str![ [ r#"
166+ [WARNING] [ROOT]/foo/Cargo.toml: unused manifest key: `lints.rust.rust-2018-idioms.unused`
167+ [WARNING] [ROOT]/foo/Cargo.toml: unused manifest key: `lints.rust.rust-2018-idioms.unused`
168+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
169+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
170+
171+ "# ] ] ) . run ( ) ;
184172}
185173
186174#[ cargo_test]
@@ -204,14 +192,13 @@ fn fail_on_tool_injection() {
204192
205193 foo. cargo ( "check" )
206194 . with_status ( 101 )
207- . with_stderr (
208- "\
209- [..]
195+ . with_stderr_data ( str![ [ r#"
196+ [ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
210197
211198Caused by:
212199 `lints.rust.clippy::cyclomatic_complexity` is not valid lint name; try `lints.clippy.cyclomatic_complexity`
213- " ,
214- )
200+
201+ "# ] ] )
215202 . run ( ) ;
216203}
217204
@@ -236,14 +223,13 @@ fn fail_on_redundant_tool() {
236223
237224 foo. cargo ( "check" )
238225 . with_status ( 101 )
239- . with_stderr (
240- "\
241- [..]
226+ . with_stderr_data ( str![ [ r#"
227+ [ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
242228
243229Caused by:
244230 `lints.rust.rust::unsafe_code` is not valid lint name; try `lints.rust.unsafe_code`
245- " ,
246- )
231+
232+ "# ] ] )
247233 . run ( ) ;
248234}
249235
@@ -268,14 +254,13 @@ fn fail_on_conflicting_tool() {
268254
269255 foo. cargo ( "check" )
270256 . with_status ( 101 )
271- . with_stderr (
272- "\
273- [..]
257+ . with_stderr_data ( str![ [ r#"
258+ [ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
274259
275260Caused by:
276261 `lints.rust.super-awesome-tool::unsafe_code` is not a valid lint name
277- " ,
278- )
262+
263+ "# ] ] )
279264 . run ( ) ;
280265}
281266
@@ -307,11 +292,11 @@ pub fn foo(num: i32) -> u32 {
307292
308293 foo. cargo ( "check" )
309294 . with_status ( 101 )
310- . with_stderr_contains (
311- " \
312- error: usage of an `unsafe` block
313- " ,
314- )
295+ . with_stderr_data ( str! [ [ r#"
296+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
297+ [ERROR] usage of an `unsafe` block
298+ ...
299+ "# ] ] )
315300 . run ( ) ;
316301}
317302
@@ -346,16 +331,15 @@ pub fn foo(num: i32) -> u32 {
346331
347332 foo. cargo ( "check" )
348333 . with_status ( 101 )
349- . with_stderr_contains (
350- "\
351- error: `workspace` cannot be false
334+ . with_stderr_data ( str![ [ r#"
335+ [ERROR] `workspace` cannot be false
352336 --> Cargo.toml:9:29
353337 |
3543389 | workspace = false
355339 | ^^^^^
356340 |
357- " ,
358- )
341+
342+ "# ] ] )
359343 . run ( ) ;
360344}
361345
@@ -390,11 +374,11 @@ pub fn foo(num: i32) -> u32 {
390374
391375 foo. cargo ( "check" )
392376 . with_status ( 101 )
393- . with_stderr_contains (
394- " \
395- error: usage of an `unsafe` block
396- " ,
397- )
377+ . with_stderr_data ( str! [ [ r#"
378+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
379+ [ERROR] usage of an `unsafe` block
380+ ...
381+ "# ] ] )
398382 . run ( ) ;
399383}
400384
@@ -431,14 +415,13 @@ pub fn foo(num: i32) -> u32 {
431415
432416 foo. cargo ( "check" )
433417 . with_status ( 101 )
434- . with_stderr (
435- "\
436- [ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
418+ . with_stderr_data ( str![ [ r#"
419+ [ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
437420
438421Caused by:
439422 cannot override `workspace.lints` in `lints`, either remove the overrides or `lints.workspace = true` and manually specify the lints
440- " ,
441- )
423+
424+ "# ] ] )
442425 . run ( ) ;
443426}
444427
@@ -616,11 +599,11 @@ pub fn foo() -> u32 {
616599
617600 foo. cargo ( "check" )
618601 . with_status ( 101 )
619- . with_stderr_contains (
620- " \
621- error: unused extern crate
622- " ,
623- )
602+ . with_stderr_data ( str! [ [ r#"
603+ ...
604+ [ERROR] unused extern crate
605+ ...
606+ "# ] ] )
624607 . run ( ) ;
625608}
626609
@@ -689,11 +672,11 @@ pub fn foo() -> u32 {
689672
690673 foo. cargo ( "doc" )
691674 . with_status ( 101 )
692- . with_stderr_contains (
693- " \
694- error: unresolved link to `bar`
695- " ,
696- )
675+ . with_stderr_data ( str! [ [ r#"
676+ [DOCUMENTING] foo v0.0.1 ([ROOT]/foo)
677+ [ERROR] unresolved link to `bar`
678+ ...
679+ "# ] ] )
697680 . run ( ) ;
698681}
699682
@@ -731,24 +714,18 @@ pub const Ĕ: i32 = 2;
731714 )
732715 . build ( ) ;
733716
734- 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- )
741- . run ( ) ;
717+ foo. cargo ( "check" ) . with_stderr_data ( str![ [ r#"
718+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
719+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
742720
743- 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
721+ "# ] ] ) . run ( ) ;
722+
723+ foo . cargo ( "test --doc" ) . with_stderr_data ( str! [ [ r#"
724+ [COMPILING] foo v0.0.1 ([ROOT]/foo )
725+ [FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED ]s
748726[DOCTEST] foo
749- " ,
750- )
751- . run ( ) ;
727+
728+ "# ] ] ) . run ( ) ;
752729}
753730
754731#[ cargo_test]
@@ -769,19 +746,16 @@ authors = []
769746 . file ( "src/lib.rs" , "" )
770747 . build ( ) ;
771748
772- foo. cargo ( "check" )
773- . with_stderr (
774- "\
749+ foo. cargo ( "check" ) . with_stderr_data ( str![ [ r#"
775750[WARNING] unused manifest key `lints.cargo` (may be supported in a future version)
776751
777752this Cargo does not support nightly features, but if you
778753switch to nightly channel you can pass
779754`-Zcargo-lints` to enable this feature.
780- [CHECKING] foo v0.0.1 ([CWD])
781- [FINISHED] [..]
782- " ,
783- )
784- . run ( ) ;
755+ [CHECKING] foo v0.0.1 ([ROOT]/foo)
756+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
757+
758+ "# ] ] ) . run ( ) ;
785759}
786760
787761#[ cargo_test]
@@ -807,15 +781,14 @@ im-a-teapot = true
807781
808782 foo. cargo ( "check" )
809783 . masquerade_as_nightly_cargo ( & [ "cargo-lints" , "test-dummy-unstable" ] )
810- . with_stderr (
811- "\
784+ . with_stderr_data ( str![ [ r#"
812785[WARNING] unused manifest key `lints.cargo` (may be supported in a future version)
813786
814787consider passing `-Zcargo-lints` to enable this feature.
815- [CHECKING] foo v0.0.1 ([CWD] )
816- [FINISHED] [..]
817- " ,
818- )
788+ [CHECKING] foo v0.0.1 ([ROOT]/foo )
789+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
790+
791+ "# ] ] )
819792 . run ( ) ;
820793}
821794
@@ -843,18 +816,17 @@ im_a_teapot = "warn"
843816
844817 p. cargo ( "check -Zcargo-lints" )
845818 . masquerade_as_nightly_cargo ( & [ "cargo-lints" , "test-dummy-unstable" ] )
846- . with_stderr (
847- "\
848- warning: `im_a_teapot` is specified
819+ . with_stderr_data ( str![ [ r#"
820+ [WARNING] `im_a_teapot` is specified
849821 --> Cargo.toml:9:1
850822 |
8518239 | im-a-teapot = true
852824 | ------------------
853825 |
854- = note: `cargo::im_a_teapot` is set to `warn` in `[lints]`
855- [CHECKING] foo v0.0.1 ([CWD] )
856- [FINISHED] [..]
857- " ,
858- )
826+ = [NOTE] `cargo::im_a_teapot` is set to `warn` in `[lints]`
827+ [CHECKING] foo v0.0.1 ([ROOT]/foo )
828+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
829+
830+ "# ] ] )
859831 . run ( ) ;
860832}
0 commit comments