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;
@@ -45,40 +45,53 @@ fn dogfood_clippy() {
4545 assert ! ( output. status. success( ) ) ;
4646}
4747
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) ) ;
6883
69- // Make sure we start with a clean state
70- clean ( & cwd, & target_dir) ;
84+ assert ! ( output. status. success( ) ) ;
7185
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 .
7488 let output = Command :: new ( & * CLIPPY_PATH )
7589 . current_dir ( & cwd)
7690 . env ( "CLIPPY_DOGFOOD" , "1" )
7791 . env ( "CARGO_INCREMENTAL" , "0" )
7892 . arg ( "clippy" )
7993 . args ( & [ "-p" , "subcrate" ] )
8094 . arg ( "--" )
81- . arg ( "--no-deps" )
8295 . arg ( "-Cdebuginfo=0" ) // disable debuginfo to generate less data in the target dir
8396 . args ( & [ "--cfg" , r#"feature="primary_package_test""# ] )
8497 . output ( )
@@ -87,12 +100,18 @@ fn dogfood_subprojects() {
87100 println ! ( "stdout: {}" , String :: from_utf8_lossy( & output. stdout) ) ;
88101 println ! ( "stderr: {}" , String :: from_utf8_lossy( & output. stderr) ) ;
89102
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+ } ;
91110
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 ( ) ;
94113
95- // Test that without the `--no-deps` argument, `path_dep` is linted.
114+ let successful_build = || {
96115 let output = Command :: new ( & * CLIPPY_PATH )
97116 . current_dir ( & cwd)
98117 . env ( "CLIPPY_DOGFOOD" , "1" )
@@ -101,16 +120,32 @@ fn dogfood_subprojects() {
101120 . args ( & [ "-p" , "subcrate" ] )
102121 . arg ( "--" )
103122 . arg ( "-Cdebuginfo=0" ) // disable debuginfo to generate less data in the target dir
104- . args ( & [ "--cfg" , r#"feature="primary_package_test""# ] )
105123 . output ( )
106124 . unwrap ( ) ;
107125 println ! ( "status: {}" , output. status) ;
108126 println ! ( "stdout: {}" , String :: from_utf8_lossy( & output. stdout) ) ;
109127 println ! ( "stderr: {}" , String :: from_utf8_lossy( & output. stderr) ) ;
110128
111- assert ! ( !output. status. success( ) ) ;
112- }
129+ assert ! ( output. status. success( ) ) ;
113130
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 ( ) {
114149 // run clippy on remaining subprojects and fail the test if lint warnings are reported
115150 if cargo:: is_rustc_test_suite ( ) {
116151 return ;
0 commit comments