33#![ feature( once_cell) ]
44
55use std:: lazy:: SyncLazy ;
6- use std:: path:: { Path , PathBuf } ;
6+ use std:: path:: PathBuf ;
77use std:: process:: Command ;
88
99mod cargo;
@@ -49,17 +49,6 @@ fn dogfood_clippy() {
4949#[ test]
5050fn dogfood_subprojects ( ) {
5151 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-
6352 if cargo:: is_rustc_test_suite ( ) {
6453 return ;
6554 }
@@ -68,7 +57,14 @@ fn dogfood_subprojects() {
6857 let cwd = root. join ( "clippy_workspace_tests" ) ;
6958
7059 // 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 ( ) ;
7268
7369 // `path_dep` is a path dependency of `subcrate` that would trigger a denied lint.
7470 // Make sure that with the `--no-deps` argument Clippy does not run on `path_dep`.
@@ -90,26 +86,65 @@ fn dogfood_subprojects() {
9086
9187 assert ! ( output. status. success( ) ) ;
9288
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) ) ;
95131
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" ) ) ;
111145
112- assert ! ( !output. status. success( ) ) ;
146+ // Make sure Cargo is aware of the new `--cfg` flag.
147+ lint_path_dep ( ) ;
113148 }
114149
115150 // run clippy on remaining subprojects and fail the test if lint warnings are reported
0 commit comments