1
- //! To run this test, use
1
+ //! This test is meant to only be run in CI. To run it locally use:
2
+ //!
2
3
//! `env INTEGRATION=rust-lang/log cargo test --test integration --features=integration`
3
4
//!
4
5
//! You can use a different `INTEGRATION` value to test different repositories.
6
+ //!
7
+ //! This test will clone the specified repository and run Clippy on it. The test succeeds, if
8
+ //! Clippy doesn't produce an ICE. Lint warnings are ignored by this test.
5
9
6
10
#![ cfg( feature = "integration" ) ]
7
11
#![ cfg_attr( feature = "deny-warnings" , deny( warnings) ) ]
8
12
#![ warn( rust_2018_idioms, unused_lifetimes) ]
9
13
14
+ use std:: env;
10
15
use std:: ffi:: OsStr ;
11
- use std:: path:: { Path , PathBuf } ;
12
16
use std:: process:: Command ;
13
- use std:: { env, eprintln} ;
14
17
15
18
#[ cfg( not( windows) ) ]
16
19
const CARGO_CLIPPY : & str = "cargo-clippy" ;
17
20
#[ cfg( windows) ]
18
21
const CARGO_CLIPPY : & str = "cargo-clippy.exe" ;
19
22
20
- // NOTE: arguments passed to the returned command will be `clippy-driver` args, not `cargo-clippy`
21
- // args. Use `cargo_args` to pass arguments to cargo-clippy.
22
- fn clippy_command ( repo_dir : & Path , cargo_args : & [ & str ] ) -> Command {
23
- let root_dir = std:: path:: PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
24
- let target_dir = option_env ! ( "CARGO_TARGET_DIR" ) . map_or_else ( || root_dir. join ( "target" ) , PathBuf :: from) ;
25
- let clippy_binary = target_dir. join ( env ! ( "PROFILE" ) ) . join ( CARGO_CLIPPY ) ;
26
-
27
- let mut cargo_clippy = Command :: new ( clippy_binary) ;
28
- cargo_clippy
29
- . current_dir ( repo_dir)
30
- . env ( "RUST_BACKTRACE" , "full" )
31
- . env ( "CARGO_TARGET_DIR" , root_dir. join ( "target" ) )
32
- . args ( [ "clippy" , "--all-targets" , "--all-features" ] )
33
- . args ( cargo_args)
34
- . args ( [ "--" , "--cap-lints" , "warn" , "-Wclippy::pedantic" , "-Wclippy::nursery" ] ) ;
35
- cargo_clippy
36
- }
37
-
38
- /// Return a directory with a checkout of the repository in `INTEGRATION`.
39
- fn repo_dir ( repo_name : & str ) -> PathBuf {
23
+ #[ cfg_attr( feature = "integration" , test) ]
24
+ fn integration_test ( ) {
25
+ let repo_name = env:: var ( "INTEGRATION" ) . expect ( "`INTEGRATION` var not set" ) ;
40
26
let repo_url = format ! ( "https://github.com/{repo_name}" ) ;
41
27
let crate_name = repo_name
42
28
. split ( '/' )
@@ -57,19 +43,28 @@ fn repo_dir(repo_name: &str) -> PathBuf {
57
43
. expect ( "unable to run git" ) ;
58
44
assert ! ( st. success( ) ) ;
59
45
60
- repo_dir
61
- }
46
+ let root_dir = std:: path:: PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) ) ;
47
+ let target_dir = std:: path:: Path :: new ( & root_dir) . join ( "target" ) ;
48
+ let clippy_binary = target_dir. join ( env ! ( "PROFILE" ) ) . join ( CARGO_CLIPPY ) ;
62
49
63
- #[ cfg_attr( feature = "integration" , test) ]
64
- fn integration_test ( ) {
65
- let repo_name = env:: var ( "INTEGRATION" ) . expect ( "`INTEGRATION` var not set" ) ;
66
- let repo_dir = repo_dir ( & repo_name) ;
67
- let output = clippy_command ( & repo_dir, & [ ] ) . output ( ) . expect ( "failed to run clippy" ) ;
68
- let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
69
- if !stderr. is_empty ( ) {
70
- eprintln ! ( "{stderr}" ) ;
71
- }
50
+ let output = Command :: new ( clippy_binary)
51
+ . current_dir ( repo_dir)
52
+ . env ( "RUST_BACKTRACE" , "full" )
53
+ . env ( "CARGO_TARGET_DIR" , target_dir)
54
+ . args ( [
55
+ "clippy" ,
56
+ "--all-targets" ,
57
+ "--all-features" ,
58
+ "--" ,
59
+ "--cap-lints" ,
60
+ "warn" ,
61
+ "-Wclippy::pedantic" ,
62
+ "-Wclippy::nursery" ,
63
+ ] )
64
+ . output ( )
65
+ . expect ( "unable to run clippy" ) ;
72
66
67
+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
73
68
if let Some ( backtrace_start) = stderr. find ( "error: internal compiler error" ) {
74
69
static BACKTRACE_END_MSG : & str = "end of query stack" ;
75
70
let backtrace_end = stderr[ backtrace_start..]
@@ -104,38 +99,3 @@ fn integration_test() {
104
99
None => panic ! ( "Process terminated by signal" ) ,
105
100
}
106
101
}
107
-
108
- #[ cfg_attr( feature = "integration" , test) ]
109
- fn test_sysroot ( ) {
110
- #[ track_caller]
111
- fn verify_cmd ( cmd : & mut Command ) {
112
- // Test that SYSROOT is ignored if `--sysroot` is passed explicitly.
113
- cmd. env ( "SYSROOT" , "/dummy/value/does/not/exist" ) ;
114
- // We don't actually care about emitting lints, we only want to verify clippy doesn't give a hard
115
- // error.
116
- cmd. arg ( "-Awarnings" ) ;
117
- let output = cmd. output ( ) . expect ( "failed to run clippy" ) ;
118
- let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
119
- assert ! ( stderr. is_empty( ) , "clippy printed an error: {stderr}" ) ;
120
- assert ! ( output. status. success( ) , "clippy exited with an error" ) ;
121
- }
122
-
123
- let rustc = std:: env:: var ( "RUSTC" ) . unwrap_or ( "rustc" . to_string ( ) ) ;
124
- let rustc_output = Command :: new ( rustc)
125
- . args ( [ "--print" , "sysroot" ] )
126
- . output ( )
127
- . expect ( "unable to run rustc" ) ;
128
- assert ! ( rustc_output. status. success( ) ) ;
129
- let sysroot = String :: from_utf8 ( rustc_output. stdout ) . unwrap ( ) ;
130
- let sysroot = sysroot. trim_end ( ) ;
131
-
132
- // This is a fairly small repo; we want to avoid checking out anything heavy twice, so just
133
- // hard-code it.
134
- let repo_name = "rust-lang/log" ;
135
- let repo_dir = repo_dir ( repo_name) ;
136
- // Pass the sysroot through RUSTFLAGS.
137
- verify_cmd ( clippy_command ( & repo_dir, & [ "--quiet" ] ) . env ( "RUSTFLAGS" , format ! ( "--sysroot={sysroot}" ) ) ) ;
138
- // NOTE: we don't test passing the arguments directly to clippy-driver (with `-- --sysroot`)
139
- // because it breaks for some reason. I (@jyn514) haven't taken time to track down the bug
140
- // because rust-lang/rust uses RUSTFLAGS and nearly no one else uses --sysroot.
141
- }
0 commit comments