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