1+ #![ feature( test) ]
2+
13extern crate compiletest_rs as compiletest;
4+ extern crate test;
25
3- use std:: path:: PathBuf ;
6+ use std:: path:: { PathBuf , Path } ;
47use std:: env:: { set_var, var} ;
58
69fn clippy_driver_path ( ) -> PathBuf {
@@ -11,16 +14,37 @@ fn clippy_driver_path() -> PathBuf {
1114 }
1215}
1316
14- fn run_mode ( dir : & ' static str , mode : & ' static str ) {
17+ fn host_libs ( ) -> PathBuf {
18+ if let Some ( path) = option_env ! ( "HOST_LIBS" ) {
19+ PathBuf :: from ( path)
20+ } else {
21+ Path :: new ( "target" ) . join ( env ! ( "PROFILE" ) )
22+ }
23+ }
24+
25+ fn rustc_test_suite ( ) -> Option < PathBuf > {
26+ option_env ! ( "RUSTC_TEST_SUITE" ) . map ( PathBuf :: from)
27+ }
28+
29+ fn rustc_lib_path ( ) -> PathBuf {
30+ option_env ! ( "RUSTC_LIB_PATH" ) . unwrap ( ) . into ( )
31+ }
32+
33+ fn config ( dir : & ' static str , mode : & ' static str ) -> compiletest:: Config {
1534 let mut config = compiletest:: Config :: default ( ) ;
1635
1736 let cfg_mode = mode. parse ( ) . expect ( "Invalid mode" ) ;
18- config. target_rustcflags = Some ( "-L target/debug/ -L target/debug/deps -Dwarnings" . to_owned ( ) ) ;
1937 if let Ok ( name) = var :: < & str > ( "TESTNAME" ) {
2038 let s: String = name. to_owned ( ) ;
2139 config. filter = Some ( s)
2240 }
2341
42+ if rustc_test_suite ( ) . is_some ( ) {
43+ config. run_lib_path = rustc_lib_path ( ) ;
44+ config. compile_lib_path = rustc_lib_path ( ) ;
45+ }
46+ config. target_rustcflags = Some ( format ! ( "-L {0} -L {0}/deps -Dwarnings" , host_libs( ) . display( ) ) ) ;
47+
2448 config. mode = cfg_mode;
2549 config. build_base = {
2650 let mut path = std:: env:: current_dir ( ) . unwrap ( ) ;
@@ -29,8 +53,11 @@ fn run_mode(dir: &'static str, mode: &'static str) {
2953 } ;
3054 config. src_base = PathBuf :: from ( format ! ( "tests/{}" , dir) ) ;
3155 config. rustc_path = clippy_driver_path ( ) ;
56+ config
57+ }
3258
33- compiletest:: run_tests ( & config) ;
59+ fn run_mode ( dir : & ' static str , mode : & ' static str ) {
60+ compiletest:: run_tests ( & config ( dir, mode) ) ;
3461}
3562
3663fn prepare_env ( ) {
@@ -45,3 +72,21 @@ fn compile_test() {
4572 run_mode ( "run-pass" , "run-pass" ) ;
4673 run_mode ( "ui" , "ui" ) ;
4774}
75+
76+ #[ test]
77+ fn dogfood ( ) {
78+ prepare_env ( ) ;
79+ let files = [ "src/main.rs" , "src/driver.rs" , "src/lib.rs" , "clippy_lints/src/lib.rs" ] ;
80+ let mut config = config ( "dogfood" , "ui" ) ;
81+ config. target_rustcflags = config. target_rustcflags . map ( |flags| format ! ( "{} -Dclippy -Dclippy_pedantic -Dclippy_internal" , flags) ) ;
82+
83+ for file in & files {
84+ let paths = test:: TestPaths {
85+ base : PathBuf :: new ( ) ,
86+ file : PathBuf :: from ( file) ,
87+ relative_dir : PathBuf :: new ( ) ,
88+ } ;
89+
90+ compiletest:: runtest:: run ( config. clone ( ) , & paths) ;
91+ }
92+ }
0 commit comments