33#![ feature( once_cell) ]
44
55use std:: lazy:: SyncLazy ;
6- use std:: path:: PathBuf ;
6+ use std:: path:: { Path , PathBuf } ;
77use std:: process:: Command ;
88
99mod cargo;
@@ -41,12 +41,77 @@ fn dogfood_clippy() {
4141
4242#[ test]
4343fn dogfood_subprojects ( ) {
44+ fn test_no_deps_ignores_path_deps_in_workspaces ( ) {
45+ fn clean ( cwd : & Path , target_dir : & Path ) {
46+ Command :: new ( "cargo" )
47+ . current_dir ( cwd)
48+ . env ( "CARGO_TARGET_DIR" , target_dir)
49+ . arg ( "clean" )
50+ . args ( & [ "-p" , "subcrate" ] )
51+ . args ( & [ "-p" , "path_dep" ] )
52+ . output ( )
53+ . unwrap ( ) ;
54+ }
55+
56+ if cargo:: is_rustc_test_suite ( ) {
57+ return ;
58+ }
59+ let root = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
60+ let target_dir = root. join ( "target" ) . join ( "dogfood" ) ;
61+ let cwd = root. join ( "clippy_workspace_tests" ) ;
62+
63+ // Make sure we start with a clean state
64+ clean ( & cwd, & target_dir) ;
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) ) ;
83+
84+ assert ! ( output. status. success( ) ) ;
85+
86+ // Make sure we start with a clean state
87+ clean ( & cwd, & target_dir) ;
88+
89+ // Test that without the `--no-deps` argument, `path_dep` is linted.
90+ let output = Command :: new ( & * CLIPPY_PATH )
91+ . current_dir ( & cwd)
92+ . env ( "CLIPPY_DOGFOOD" , "1" )
93+ . env ( "CARGO_INCREMENTAL" , "0" )
94+ . arg ( "clippy" )
95+ . args ( & [ "-p" , "subcrate" ] )
96+ . arg ( "--" )
97+ . arg ( "-Cdebuginfo=0" ) // disable debuginfo to generate less data in the target dir
98+ . args ( & [ "--cfg" , r#"feature="primary_package_test""# ] )
99+ . output ( )
100+ . unwrap ( ) ;
101+ println ! ( "status: {}" , output. status) ;
102+ println ! ( "stdout: {}" , String :: from_utf8_lossy( & output. stdout) ) ;
103+ println ! ( "stderr: {}" , String :: from_utf8_lossy( & output. stderr) ) ;
104+
105+ assert ! ( !output. status. success( ) ) ;
106+ }
107+
44108 // run clippy on remaining subprojects and fail the test if lint warnings are reported
45109 if cargo:: is_rustc_test_suite ( ) {
46110 return ;
47111 }
48112 let root_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
49113
114+ // NOTE: `path_dep` crate is omitted on purpose here
50115 for d in & [
51116 "clippy_workspace_tests" ,
52117 "clippy_workspace_tests/src" ,
@@ -72,4 +137,8 @@ fn dogfood_subprojects() {
72137
73138 assert ! ( output. status. success( ) ) ;
74139 }
140+
141+ // NOTE: Since tests run in parallel we can't run cargo commands on the same workspace at the
142+ // same time, so we test this immediately after the dogfood for workspaces.
143+ test_no_deps_ignores_path_deps_in_workspaces ( ) ;
75144}
0 commit comments