3
3
//!
4
4
//! See [Eating your own dog food](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) for context
5
5
6
- // Dogfood cannot run on Windows
7
- #![ cfg( not( windows) ) ]
8
6
#![ feature( once_cell) ]
9
7
#![ cfg_attr( feature = "deny-warnings" , deny( warnings) ) ]
10
8
#![ warn( rust_2018_idioms, unused_lifetimes) ]
11
9
12
- use std:: lazy:: SyncLazy ;
13
10
use std:: path:: PathBuf ;
14
11
use std:: process:: Command ;
12
+ use test_utils:: IS_RUSTC_TEST_SUITE ;
15
13
16
- mod cargo;
17
-
18
- static CLIPPY_PATH : SyncLazy < PathBuf > = SyncLazy :: new ( || {
19
- let mut path = std:: env:: current_exe ( ) . unwrap ( ) ;
20
- assert ! ( path. pop( ) ) ; // deps
21
- path. set_file_name ( "cargo-clippy" ) ;
22
- path
23
- } ) ;
14
+ mod test_utils;
24
15
25
16
#[ test]
26
17
fn dogfood_clippy ( ) {
27
- // run clippy on itself and fail the test if lint warnings are reported
28
- if cargo:: is_rustc_test_suite ( ) {
29
- return ;
30
- }
31
- let root_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
32
-
33
- let mut command = Command :: new ( & * CLIPPY_PATH ) ;
34
- command
35
- . current_dir ( root_dir)
36
- . env ( "CARGO_INCREMENTAL" , "0" )
37
- . arg ( "clippy" )
38
- . arg ( "--all-targets" )
39
- . arg ( "--all-features" )
40
- . arg ( "--" )
41
- . args ( & [ "-D" , "clippy::all" ] )
42
- . args ( & [ "-D" , "clippy::pedantic" ] )
43
- . arg ( "-Cdebuginfo=0" ) ; // disable debuginfo to generate less data in the target dir
44
-
45
- // internal lints only exist if we build with the internal feature
46
- if cfg ! ( feature = "internal" ) {
47
- command. args ( & [ "-D" , "clippy::internal" ] ) ;
48
- }
49
-
50
- let output = command. output ( ) . unwrap ( ) ;
51
-
52
- println ! ( "status: {}" , output. status) ;
53
- println ! ( "stdout: {}" , String :: from_utf8_lossy( & output. stdout) ) ;
54
- println ! ( "stderr: {}" , String :: from_utf8_lossy( & output. stderr) ) ;
55
-
56
- assert ! ( output. status. success( ) ) ;
57
- }
58
-
59
- fn test_no_deps_ignores_path_deps_in_workspaces ( ) {
60
- if cargo:: is_rustc_test_suite ( ) {
61
- return ;
62
- }
63
- let root = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
64
- let target_dir = root. join ( "target" ) . join ( "dogfood" ) ;
65
- let cwd = root. join ( "clippy_workspace_tests" ) ;
66
-
67
- // Make sure we start with a clean state
68
- Command :: new ( "cargo" )
69
- . current_dir ( & cwd)
70
- . env ( "CARGO_TARGET_DIR" , & target_dir)
71
- . arg ( "clean" )
72
- . args ( & [ "-p" , "subcrate" ] )
73
- . args ( & [ "-p" , "path_dep" ] )
74
- . output ( )
75
- . unwrap ( ) ;
76
-
77
- // `path_dep` is a path dependency of `subcrate` that would trigger a denied lint.
78
- // Make sure that with the `--no-deps` argument Clippy does not run on `path_dep`.
79
- let output = Command :: new ( & * CLIPPY_PATH )
80
- . current_dir ( & cwd)
81
- . env ( "CARGO_INCREMENTAL" , "0" )
82
- . arg ( "clippy" )
83
- . args ( & [ "-p" , "subcrate" ] )
84
- . arg ( "--no-deps" )
85
- . arg ( "--" )
86
- . arg ( "-Cdebuginfo=0" ) // disable debuginfo to generate less data in the target dir
87
- . args ( & [ "--cfg" , r#"feature="primary_package_test""# ] )
88
- . output ( )
89
- . unwrap ( ) ;
90
- println ! ( "status: {}" , output. status) ;
91
- println ! ( "stdout: {}" , String :: from_utf8_lossy( & output. stdout) ) ;
92
- println ! ( "stderr: {}" , String :: from_utf8_lossy( & output. stderr) ) ;
93
-
94
- assert ! ( output. status. success( ) ) ;
95
-
96
- let lint_path_dep = || {
97
- // Test that without the `--no-deps` argument, `path_dep` is linted.
98
- let output = Command :: new ( & * CLIPPY_PATH )
99
- . current_dir ( & cwd)
100
- . env ( "CARGO_INCREMENTAL" , "0" )
101
- . arg ( "clippy" )
102
- . args ( & [ "-p" , "subcrate" ] )
103
- . arg ( "--" )
104
- . arg ( "-Cdebuginfo=0" ) // disable debuginfo to generate less data in the target dir
105
- . args ( & [ "--cfg" , r#"feature="primary_package_test""# ] )
106
- . output ( )
107
- . unwrap ( ) ;
108
- println ! ( "status: {}" , output. status) ;
109
- println ! ( "stdout: {}" , String :: from_utf8_lossy( & output. stdout) ) ;
110
- println ! ( "stderr: {}" , String :: from_utf8_lossy( & output. stderr) ) ;
111
-
112
- assert ! ( !output. status. success( ) ) ;
113
- assert ! (
114
- String :: from_utf8( output. stderr)
115
- . unwrap( )
116
- . contains( "error: empty `loop {}` wastes CPU cycles" )
117
- ) ;
118
- } ;
119
-
120
- // Make sure Cargo is aware of the removal of `--no-deps`.
121
- lint_path_dep ( ) ;
122
-
123
- let successful_build = || {
124
- let output = Command :: new ( & * CLIPPY_PATH )
125
- . current_dir ( & cwd)
126
- . env ( "CARGO_INCREMENTAL" , "0" )
127
- . arg ( "clippy" )
128
- . args ( & [ "-p" , "subcrate" ] )
129
- . arg ( "--" )
130
- . arg ( "-Cdebuginfo=0" ) // disable debuginfo to generate less data in the target dir
131
- . output ( )
132
- . unwrap ( ) ;
133
- println ! ( "status: {}" , output. status) ;
134
- println ! ( "stdout: {}" , String :: from_utf8_lossy( & output. stdout) ) ;
135
- println ! ( "stderr: {}" , String :: from_utf8_lossy( & output. stderr) ) ;
136
-
137
- assert ! ( output. status. success( ) ) ;
138
-
139
- output
140
- } ;
141
-
142
- // Trigger a sucessful build, so Cargo would like to cache the build result.
143
- successful_build ( ) ;
144
-
145
- // Make sure there's no spurious rebuild when nothing changes.
146
- let stderr = String :: from_utf8 ( successful_build ( ) . stderr ) . unwrap ( ) ;
147
- assert ! ( !stderr. contains( "Compiling" ) ) ;
148
- assert ! ( !stderr. contains( "Checking" ) ) ;
149
- assert ! ( stderr. contains( "Finished" ) ) ;
150
-
151
- // Make sure Cargo is aware of the new `--cfg` flag.
152
- lint_path_dep ( ) ;
153
- }
154
-
155
- #[ test]
156
- fn dogfood_subprojects ( ) {
157
- // run clippy on remaining subprojects and fail the test if lint warnings are reported
158
- if cargo:: is_rustc_test_suite ( ) {
18
+ if IS_RUSTC_TEST_SUITE {
159
19
return ;
160
20
}
161
21
162
- // NOTE: `path_dep` crate is omitted on purpose here
163
- for project in & [
164
- "clippy_workspace_tests" ,
165
- "clippy_workspace_tests/src" ,
166
- "clippy_workspace_tests/subcrate" ,
167
- "clippy_workspace_tests/subcrate/src" ,
168
- "clippy_dev" ,
169
- "clippy_lints" ,
170
- "clippy_utils" ,
171
- "rustc_tools_util" ,
172
- ] {
173
- run_clippy_for_project ( project) ;
22
+ // "" is the root package
23
+ for package in & [ "" , "clippy_dev" , "clippy_lints" , "clippy_utils" , "rustc_tools_util" ] {
24
+ run_clippy_for_package ( package) ;
174
25
}
175
-
176
- // NOTE: Since tests run in parallel we can't run cargo commands on the same workspace at the
177
- // same time, so we test this immediately after the dogfood for workspaces.
178
- test_no_deps_ignores_path_deps_in_workspaces ( ) ;
179
26
}
180
27
181
28
#[ test]
@@ -191,7 +38,7 @@ fn run_metadata_collection_lint() {
191
38
192
39
// Run collection as is
193
40
std:: env:: set_var ( "ENABLE_METADATA_COLLECTION" , "1" ) ;
194
- run_clippy_for_project ( "clippy_lints" ) ;
41
+ run_clippy_for_package ( "clippy_lints" ) ;
195
42
196
43
// Check if cargo caching got in the way
197
44
if let Ok ( file) = File :: open ( metadata_output_path) {
@@ -214,13 +61,13 @@ fn run_metadata_collection_lint() {
214
61
. unwrap ( ) ;
215
62
216
63
// Running the collection again
217
- run_clippy_for_project ( "clippy_lints" ) ;
64
+ run_clippy_for_package ( "clippy_lints" ) ;
218
65
}
219
66
220
- fn run_clippy_for_project ( project : & str ) {
67
+ fn run_clippy_for_package ( project : & str ) {
221
68
let root_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
222
69
223
- let mut command = Command :: new ( & * CLIPPY_PATH ) ;
70
+ let mut command = Command :: new ( & * test_utils :: CARGO_CLIPPY_PATH ) ;
224
71
225
72
command
226
73
. current_dir ( root_dir. join ( project) )
0 commit comments