1
1
//! Tests for `[lints]`
2
2
3
- #![ allow( deprecated) ]
4
-
5
3
use cargo_test_support:: project;
6
4
use cargo_test_support:: registry:: Package ;
5
+ use cargo_test_support:: str;
7
6
8
7
#[ cargo_test]
9
8
fn dependency_warning_ignored ( ) {
@@ -43,14 +42,13 @@ fn dependency_warning_ignored() {
43
42
. build ( ) ;
44
43
45
44
foo. cargo ( "check" )
46
- . with_stderr (
47
- "\
45
+ . with_stderr_data ( str![ [ r#"
48
46
[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
+ "# ] ] )
54
52
. run ( ) ;
55
53
}
56
54
@@ -74,16 +72,15 @@ fn malformed_on_stable() {
74
72
75
73
foo. cargo ( "check" )
76
74
. with_status ( 101 )
77
- . with_stderr (
78
- "\
75
+ . with_stderr_data ( str![ [ r#"
79
76
[ERROR] invalid type: integer `20`, expected a lints table
80
77
--> Cargo.toml:2:25
81
78
|
82
79
2 | lints = 20
83
80
| ^^
84
81
|
85
- " ,
86
- )
82
+
83
+ "# ] ] )
87
84
. run ( ) ;
88
85
}
89
86
@@ -106,16 +103,13 @@ fn fail_on_invalid_tool() {
106
103
. file ( "src/lib.rs" , "" )
107
104
. build ( ) ;
108
105
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.
113
108
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 ( ) ;
119
113
}
120
114
121
115
#[ cargo_test]
@@ -138,16 +132,15 @@ fn invalid_type_in_lint_value() {
138
132
139
133
foo. cargo ( "check" )
140
134
. with_status ( 101 )
141
- . with_stderr (
142
- "\
135
+ . with_stderr_data ( str![ [ r#"
143
136
[ERROR] invalid type: integer `-1`, expected a string or map
144
137
--> Cargo.toml:8:36
145
138
|
146
139
8 | rust-2018-idioms = -1
147
140
| ^^
148
141
|
149
- " ,
150
- )
142
+
143
+ "# ] ] )
151
144
. run ( ) ;
152
145
}
153
146
@@ -172,14 +165,13 @@ fn warn_on_unused_key() {
172
165
. build ( ) ;
173
166
174
167
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
+ "# ] ] )
183
175
. run ( ) ;
184
176
}
185
177
@@ -204,14 +196,13 @@ fn fail_on_tool_injection() {
204
196
205
197
foo. cargo ( "check" )
206
198
. 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`
210
201
211
202
Caused by:
212
203
`lints.rust.clippy::cyclomatic_complexity` is not valid lint name; try `lints.clippy.cyclomatic_complexity`
213
- " ,
214
- )
204
+
205
+ "# ] ] )
215
206
. run ( ) ;
216
207
}
217
208
@@ -236,14 +227,13 @@ fn fail_on_redundant_tool() {
236
227
237
228
foo. cargo ( "check" )
238
229
. 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`
242
232
243
233
Caused by:
244
234
`lints.rust.rust::unsafe_code` is not valid lint name; try `lints.rust.unsafe_code`
245
- " ,
246
- )
235
+
236
+ "# ] ] )
247
237
. run ( ) ;
248
238
}
249
239
@@ -268,14 +258,13 @@ fn fail_on_conflicting_tool() {
268
258
269
259
foo. cargo ( "check" )
270
260
. 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`
274
263
275
264
Caused by:
276
265
`lints.rust.super-awesome-tool::unsafe_code` is not a valid lint name
277
- " ,
278
- )
266
+
267
+ "# ] ] )
279
268
. run ( ) ;
280
269
}
281
270
@@ -307,11 +296,11 @@ pub fn foo(num: i32) -> u32 {
307
296
308
297
foo. cargo ( "check" )
309
298
. 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
+ "# ] ] )
315
304
. run ( ) ;
316
305
}
317
306
@@ -346,16 +335,15 @@ pub fn foo(num: i32) -> u32 {
346
335
347
336
foo. cargo ( "check" )
348
337
. 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
352
340
--> Cargo.toml:9:29
353
341
|
354
342
9 | workspace = false
355
343
| ^^^^^
356
344
|
357
- " ,
358
- )
345
+
346
+ "# ] ] )
359
347
. run ( ) ;
360
348
}
361
349
@@ -390,11 +378,11 @@ pub fn foo(num: i32) -> u32 {
390
378
391
379
foo. cargo ( "check" )
392
380
. 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
+ "# ] ] )
398
386
. run ( ) ;
399
387
}
400
388
@@ -431,14 +419,13 @@ pub fn foo(num: i32) -> u32 {
431
419
432
420
foo. cargo ( "check" )
433
421
. 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`
437
424
438
425
Caused by:
439
426
cannot override `workspace.lints` in `lints`, either remove the overrides or `lints.workspace = true` and manually specify the lints
440
- " ,
441
- )
427
+
428
+ "# ] ] )
442
429
. run ( ) ;
443
430
}
444
431
@@ -616,11 +603,11 @@ pub fn foo() -> u32 {
616
603
617
604
foo. cargo ( "check" )
618
605
. 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
+ "# ] ] )
624
611
. run ( ) ;
625
612
}
626
613
@@ -689,11 +676,11 @@ pub fn foo() -> u32 {
689
676
690
677
foo. cargo ( "doc" )
691
678
. 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
+ "# ] ] )
697
684
. run ( ) ;
698
685
}
699
686
@@ -732,22 +719,20 @@ pub const Ĕ: i32 = 2;
732
719
. build ( ) ;
733
720
734
721
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
+ "# ] ] )
741
727
. run ( ) ;
742
728
743
729
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
748
733
[DOCTEST] foo
749
- " ,
750
- )
734
+
735
+ "# ] ] )
751
736
. run ( ) ;
752
737
}
753
738
@@ -770,17 +755,16 @@ authors = []
770
755
. build ( ) ;
771
756
772
757
foo. cargo ( "check" )
773
- . with_stderr (
774
- "\
758
+ . with_stderr_data ( str![ [ r#"
775
759
[WARNING] unused manifest key `lints.cargo` (may be supported in a future version)
776
760
777
761
this Cargo does not support nightly features, but if you
778
762
switch to nightly channel you can pass
779
763
`-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
+ "# ] ] )
784
768
. run ( ) ;
785
769
}
786
770
@@ -807,15 +791,14 @@ im-a-teapot = true
807
791
808
792
foo. cargo ( "check" )
809
793
. masquerade_as_nightly_cargo ( & [ "cargo-lints" , "test-dummy-unstable" ] )
810
- . with_stderr (
811
- "\
794
+ . with_stderr_data ( str![ [ r#"
812
795
[WARNING] unused manifest key `lints.cargo` (may be supported in a future version)
813
796
814
797
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
+ "# ] ] )
819
802
. run ( ) ;
820
803
}
821
804
@@ -843,18 +826,17 @@ im_a_teapot = "warn"
843
826
844
827
p. cargo ( "check -Zcargo-lints" )
845
828
. 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
849
831
--> Cargo.toml:9:1
850
832
|
851
833
9 | im-a-teapot = true
852
834
| ------------------
853
835
|
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
+ "# ] ] )
859
841
. run ( ) ;
860
842
}
0 commit comments