3
3
#![ feature( once_cell) ]
4
4
5
5
use std:: lazy:: SyncLazy ;
6
- use std:: path:: PathBuf ;
6
+ use std:: path:: { Path , PathBuf } ;
7
7
use std:: process:: Command ;
8
8
9
9
mod cargo;
@@ -41,12 +41,77 @@ fn dogfood_clippy() {
41
41
42
42
#[ test]
43
43
fn 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
+
44
108
// run clippy on remaining subprojects and fail the test if lint warnings are reported
45
109
if cargo:: is_rustc_test_suite ( ) {
46
110
return ;
47
111
}
48
112
let root_dir = PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
49
113
114
+ // NOTE: `path_dep` crate is omitted on purpose here
50
115
for d in & [
51
116
"clippy_workspace_tests" ,
52
117
"clippy_workspace_tests/src" ,
@@ -72,4 +137,8 @@ fn dogfood_subprojects() {
72
137
73
138
assert ! ( output. status. success( ) ) ;
74
139
}
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 ( ) ;
75
144
}
0 commit comments