1
- #![ feature( slice_concat_ext) ]
2
-
3
- extern crate compiletest_rs as compiletest;
4
- extern crate colored;
5
-
6
- use colored:: * ;
1
+ #![ feature( slice_concat_ext, custom_test_frameworks) ]
2
+ #![ test_runner( test_runner) ]
7
3
8
4
use std:: slice:: SliceConcatExt ;
9
5
use std:: path:: { PathBuf , Path } ;
10
6
use std:: io:: Write ;
7
+ use std:: env;
11
8
12
- macro_rules! eprintln {
13
- ( $( $arg: tt) * ) => {
14
- let stderr = std:: io:: stderr( ) ;
15
- writeln!( stderr. lock( ) , $( $arg) * ) . unwrap( ) ;
16
- }
17
- }
9
+ use compiletest_rs as compiletest;
10
+ use colored:: * ;
18
11
19
12
fn miri_path ( ) -> PathBuf {
20
13
if rustc_test_suite ( ) . is_some ( ) {
@@ -37,9 +30,21 @@ fn have_fullmir() -> bool {
37
30
std:: env:: var ( "MIRI_SYSROOT" ) . is_ok ( ) || rustc_test_suite ( ) . is_some ( )
38
31
}
39
32
33
+ fn mk_config ( mode : & str ) -> compiletest:: Config {
34
+ let mut config = compiletest:: Config :: default ( ) ;
35
+ config. mode = mode. parse ( ) . expect ( "Invalid mode" ) ;
36
+ config. rustc_path = miri_path ( ) ;
37
+ if rustc_test_suite ( ) . is_some ( ) {
38
+ config. run_lib_path = rustc_lib_path ( ) ;
39
+ config. compile_lib_path = rustc_lib_path ( ) ;
40
+ }
41
+ config. filter = env:: args ( ) . nth ( 1 ) ;
42
+ config
43
+ }
44
+
40
45
fn compile_fail ( sysroot : & Path , path : & str , target : & str , host : & str , need_fullmir : bool , opt : bool ) {
41
46
if need_fullmir && !have_fullmir ( ) {
42
- eprintln ! ( "{}" , format!(
47
+ eprintln ! ( "{}\n " , format!(
43
48
"## Skipping compile-fail tests in {} against miri for target {} due to missing mir" ,
44
49
path,
45
50
target
@@ -65,23 +70,17 @@ fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, need_fullm
65
70
flags. push ( "-Zmir-opt-level=1" . to_owned ( ) ) ;
66
71
}
67
72
68
- let mut config = compiletest:: Config :: default ( ) . tempdir ( ) ;
69
- config. mode = "compile-fail" . parse ( ) . expect ( "Invalid mode" ) ;
70
- config. rustc_path = miri_path ( ) ;
71
- if rustc_test_suite ( ) . is_some ( ) {
72
- config. run_lib_path = rustc_lib_path ( ) ;
73
- config. compile_lib_path = rustc_lib_path ( ) ;
74
- }
75
- config. src_base = PathBuf :: from ( path. to_string ( ) ) ;
76
- config. target_rustcflags = Some ( flags. join ( " " ) ) ;
73
+ let mut config = mk_config ( "compile-fail" ) ;
74
+ config. src_base = PathBuf :: from ( path) ;
77
75
config. target = target. to_owned ( ) ;
78
76
config. host = host. to_owned ( ) ;
79
- compiletest:: run_tests ( & config) ;
77
+ config. target_rustcflags = Some ( flags. join ( " " ) ) ;
78
+ compiletest:: run_tests ( & config. tempdir ( ) ) ; // FIXME: `tempdir` can be done by `mk_config` once `ConfigWithTemp` is exposed as type from compiletest
80
79
}
81
80
82
81
fn miri_pass ( sysroot : & Path , path : & str , target : & str , host : & str , need_fullmir : bool , opt : bool ) {
83
82
if need_fullmir && !have_fullmir ( ) {
84
- eprintln ! ( "{}" , format!(
83
+ eprintln ! ( "{}\n " , format!(
85
84
"## Skipping run-pass tests in {} against miri for target {} due to missing mir" ,
86
85
path,
87
86
target
@@ -104,18 +103,12 @@ fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, need_fullmir:
104
103
flags. push ( "-Zmir-opt-level=3" . to_owned ( ) ) ;
105
104
}
106
105
107
- let mut config = compiletest:: Config :: default ( ) . tempdir ( ) ;
108
- config. mode = "ui" . parse ( ) . expect ( "Invalid mode" ) ;
106
+ let mut config = mk_config ( "ui" ) ;
109
107
config. src_base = PathBuf :: from ( path) ;
110
108
config. target = target. to_owned ( ) ;
111
109
config. host = host. to_owned ( ) ;
112
- config. rustc_path = miri_path ( ) ;
113
- if rustc_test_suite ( ) . is_some ( ) {
114
- config. run_lib_path = rustc_lib_path ( ) ;
115
- config. compile_lib_path = rustc_lib_path ( ) ;
116
- }
117
110
config. target_rustcflags = Some ( flags. join ( " " ) ) ;
118
- compiletest:: run_tests ( & config) ;
111
+ compiletest:: run_tests ( & config. tempdir ( ) ) ; // FIXME: `tempdir` can be done by `mk_config` once `ConfigWithTemp` is exposed as type from compiletest
119
112
}
120
113
121
114
fn is_target_dir < P : Into < PathBuf > > ( path : P ) -> bool {
@@ -151,7 +144,6 @@ fn get_sysroot() -> PathBuf {
151
144
152
145
fn get_host ( ) -> String {
153
146
let rustc = rustc_test_suite ( ) . unwrap_or ( PathBuf :: from ( "rustc" ) ) ;
154
- println ! ( "using rustc at {}" , rustc. display( ) ) ;
155
147
let host = std:: process:: Command :: new ( rustc)
156
148
. arg ( "-vV" )
157
149
. output ( )
@@ -184,8 +176,7 @@ fn compile_fail_miri(opt: bool) {
184
176
compile_fail ( & sysroot, "tests/compile-fail-fullmir" , & host, & host, true , opt) ;
185
177
}
186
178
187
- #[ test]
188
- fn test ( ) {
179
+ fn test_runner ( _tests : & [ & ( ) ] ) {
189
180
// We put everything into a single test to avoid the parallelism `cargo test`
190
181
// introduces. We still get parallelism within our tests because `compiletest`
191
182
// uses `libtest` which runs jobs in parallel.
0 commit comments