3
3
#![ feature( once_cell) ]
4
4
5
5
use std:: lazy:: SyncLazy ;
6
- use std:: path:: { Path , PathBuf } ;
6
+ use std:: path:: PathBuf ;
7
7
use std:: process:: Command ;
8
8
9
9
mod cargo;
@@ -49,17 +49,6 @@ fn dogfood_clippy() {
49
49
#[ test]
50
50
fn dogfood_subprojects ( ) {
51
51
fn test_no_deps_ignores_path_deps_in_workspaces ( ) {
52
- fn clean ( cwd : & Path , target_dir : & Path ) {
53
- Command :: new ( "cargo" )
54
- . current_dir ( cwd)
55
- . env ( "CARGO_TARGET_DIR" , target_dir)
56
- . arg ( "clean" )
57
- . args ( & [ "-p" , "subcrate" ] )
58
- . args ( & [ "-p" , "path_dep" ] )
59
- . output ( )
60
- . unwrap ( ) ;
61
- }
62
-
63
52
if cargo:: is_rustc_test_suite ( ) {
64
53
return ;
65
54
}
@@ -68,7 +57,14 @@ fn dogfood_subprojects() {
68
57
let cwd = root. join ( "clippy_workspace_tests" ) ;
69
58
70
59
// Make sure we start with a clean state
71
- clean ( & cwd, & target_dir) ;
60
+ Command :: new ( "cargo" )
61
+ . current_dir ( & cwd)
62
+ . env ( "CARGO_TARGET_DIR" , & target_dir)
63
+ . arg ( "clean" )
64
+ . args ( & [ "-p" , "subcrate" ] )
65
+ . args ( & [ "-p" , "path_dep" ] )
66
+ . output ( )
67
+ . unwrap ( ) ;
72
68
73
69
// `path_dep` is a path dependency of `subcrate` that would trigger a denied lint.
74
70
// Make sure that with the `--no-deps` argument Clippy does not run on `path_dep`.
@@ -90,26 +86,65 @@ fn dogfood_subprojects() {
90
86
91
87
assert ! ( output. status. success( ) ) ;
92
88
93
- // Make sure we start with a clean state
94
- clean ( & cwd, & target_dir) ;
89
+ let lint_path_dep = || {
90
+ // Test that without the `--no-deps` argument, `path_dep` is linted.
91
+ let output = Command :: new ( & * CLIPPY_PATH )
92
+ . current_dir ( & cwd)
93
+ . env ( "CLIPPY_DOGFOOD" , "1" )
94
+ . env ( "CARGO_INCREMENTAL" , "0" )
95
+ . arg ( "clippy" )
96
+ . args ( & [ "-p" , "subcrate" ] )
97
+ . arg ( "--" )
98
+ . arg ( "-Cdebuginfo=0" ) // disable debuginfo to generate less data in the target dir
99
+ . args ( & [ "--cfg" , r#"feature="primary_package_test""# ] )
100
+ . output ( )
101
+ . unwrap ( ) ;
102
+ println ! ( "status: {}" , output. status) ;
103
+ println ! ( "stdout: {}" , String :: from_utf8_lossy( & output. stdout) ) ;
104
+ println ! ( "stderr: {}" , String :: from_utf8_lossy( & output. stderr) ) ;
105
+
106
+ assert ! ( !output. status. success( ) ) ;
107
+ assert ! (
108
+ String :: from_utf8( output. stderr)
109
+ . unwrap( )
110
+ . contains( "error: empty `loop {}` wastes CPU cycles" )
111
+ ) ;
112
+ } ;
113
+
114
+ // Make sure Cargo is aware of the removal of `--no-deps`.
115
+ lint_path_dep ( ) ;
116
+
117
+ let successful_build = || {
118
+ let output = Command :: new ( & * CLIPPY_PATH )
119
+ . current_dir ( & cwd)
120
+ . env ( "CLIPPY_DOGFOOD" , "1" )
121
+ . env ( "CARGO_INCREMENTAL" , "0" )
122
+ . arg ( "clippy" )
123
+ . args ( & [ "-p" , "subcrate" ] )
124
+ . arg ( "--" )
125
+ . arg ( "-Cdebuginfo=0" ) // disable debuginfo to generate less data in the target dir
126
+ . output ( )
127
+ . unwrap ( ) ;
128
+ println ! ( "status: {}" , output. status) ;
129
+ println ! ( "stdout: {}" , String :: from_utf8_lossy( & output. stdout) ) ;
130
+ println ! ( "stderr: {}" , String :: from_utf8_lossy( & output. stderr) ) ;
95
131
96
- // Test that without the `--no-deps` argument, `path_dep` is linted.
97
- let output = Command :: new ( & * CLIPPY_PATH )
98
- . current_dir ( & cwd)
99
- . env ( "CLIPPY_DOGFOOD" , "1" )
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) ) ;
132
+ assert ! ( output. status. success( ) ) ;
133
+
134
+ output
135
+ } ;
136
+
137
+ // Trigger a sucessful build, so Cargo would like to cache the build result.
138
+ successful_build ( ) ;
139
+
140
+ // Make sure there's no spurious rebuild when nothing changes.
141
+ let stderr = String :: from_utf8 ( successful_build ( ) . stderr ) . unwrap ( ) ;
142
+ assert ! ( !stderr. contains( "Compiling" ) ) ;
143
+ assert ! ( !stderr. contains( "Checking" ) ) ;
144
+ assert ! ( stderr. contains( "Finished" ) ) ;
111
145
112
- assert ! ( !output. status. success( ) ) ;
146
+ // Make sure Cargo is aware of the new `--cfg` flag.
147
+ lint_path_dep ( ) ;
113
148
}
114
149
115
150
// run clippy on remaining subprojects and fail the test if lint warnings are reported
0 commit comments