1
1
use colored:: * ;
2
2
use regex:: Regex ;
3
3
use std:: path:: { Path , PathBuf } ;
4
- use std:: { env, ffi :: OsString , process:: Command } ;
5
- use ui_test:: { color_eyre:: Result , Config , DependencyBuilder , Mode , OutputConflictHandling } ;
4
+ use std:: { env, process:: Command } ;
5
+ use ui_test:: { color_eyre:: Result , Config , Mode , OutputConflictHandling } ;
6
6
7
7
fn miri_path ( ) -> PathBuf {
8
8
PathBuf :: from ( option_env ! ( "MIRI" ) . unwrap_or ( env ! ( "CARGO_BIN_EXE_miri" ) ) )
@@ -43,30 +43,40 @@ fn run_tests(
43
43
target : Option < String > ,
44
44
with_dependencies : bool ,
45
45
) -> Result < ( ) > {
46
+ let mut config = Config {
47
+ target,
48
+ stderr_filters : STDERR . clone ( ) ,
49
+ stdout_filters : STDOUT . clone ( ) ,
50
+ root_dir : PathBuf :: from ( path) ,
51
+ mode,
52
+ program : miri_path ( ) ,
53
+ quiet : false ,
54
+ ..Config :: default ( )
55
+ } ;
56
+
46
57
let in_rustc_test_suite = option_env ! ( "RUSTC_STAGE" ) . is_some ( ) ;
47
58
48
59
// Add some flags we always want.
49
- let mut flags: Vec < OsString > = Vec :: new ( ) ;
50
- flags. push ( "--edition" . into ( ) ) ;
51
- flags. push ( "2018" . into ( ) ) ;
60
+ config. args . push ( "--edition" . into ( ) ) ;
61
+ config. args . push ( "2018" . into ( ) ) ;
52
62
if in_rustc_test_suite {
53
63
// Less aggressive warnings to make the rustc toolstate management less painful.
54
64
// (We often get warnings when e.g. a feature gets stabilized or some lint gets added/improved.)
55
- flags . push ( "-Astable-features" . into ( ) ) ;
56
- flags . push ( "-Aunused" . into ( ) ) ;
65
+ config . args . push ( "-Astable-features" . into ( ) ) ;
66
+ config . args . push ( "-Aunused" . into ( ) ) ;
57
67
} else {
58
- flags . push ( "-Dwarnings" . into ( ) ) ;
59
- flags . push ( "-Dunused" . into ( ) ) ;
68
+ config . args . push ( "-Dwarnings" . into ( ) ) ;
69
+ config . args . push ( "-Dunused" . into ( ) ) ;
60
70
}
61
71
if let Ok ( extra_flags) = env:: var ( "MIRIFLAGS" ) {
62
72
for flag in extra_flags. split_whitespace ( ) {
63
- flags . push ( flag. into ( ) ) ;
73
+ config . args . push ( flag. into ( ) ) ;
64
74
}
65
75
}
66
- flags . push ( "-Zui-testing" . into ( ) ) ;
67
- if let Some ( target) = & target {
68
- flags . push ( "--target" . into ( ) ) ;
69
- flags . push ( target. into ( ) ) ;
76
+ config . args . push ( "-Zui-testing" . into ( ) ) ;
77
+ if let Some ( target) = & config . target {
78
+ config . args . push ( "--target" . into ( ) ) ;
79
+ config . args . push ( target. into ( ) ) ;
70
80
}
71
81
72
82
// If we're on linux, and we're testing the extern-so functionality,
@@ -76,57 +86,43 @@ fn run_tests(
76
86
let so_file_path = build_so_for_c_ffi_tests ( ) ;
77
87
let mut flag = std:: ffi:: OsString :: from ( "-Zmiri-extern-so-file=" ) ;
78
88
flag. push ( so_file_path. into_os_string ( ) ) ;
79
- flags . push ( flag) ;
89
+ config . args . push ( flag) ;
80
90
}
81
91
82
92
let skip_ui_checks = env:: var_os ( "MIRI_SKIP_UI_CHECKS" ) . is_some ( ) ;
83
93
84
- let output_conflict_handling = match ( env:: var_os ( "MIRI_BLESS" ) . is_some ( ) , skip_ui_checks) {
94
+ config . output_conflict_handling = match ( env:: var_os ( "MIRI_BLESS" ) . is_some ( ) , skip_ui_checks) {
85
95
( false , false ) => OutputConflictHandling :: Error ,
86
96
( true , false ) => OutputConflictHandling :: Bless ,
87
97
( false , true ) => OutputConflictHandling :: Ignore ,
88
98
( true , true ) => panic ! ( "cannot use MIRI_BLESS and MIRI_SKIP_UI_CHECKS at the same time" ) ,
89
99
} ;
90
100
91
- // Pass on all unknown arguments as filters.
92
- let mut quiet = false ;
93
- let path_filter = std:: env:: args ( ) . skip ( 1 ) . filter ( |arg| {
101
+ // Handle command-line arguments.
102
+ config. path_filter . extend ( std:: env:: args ( ) . skip ( 1 ) . filter ( |arg| {
94
103
match & * * arg {
95
104
"--quiet" => {
96
- quiet = true ;
105
+ config . quiet = true ;
97
106
false
98
107
}
99
108
_ => true ,
100
109
}
101
- } ) ;
110
+ } ) ) ;
102
111
103
112
let use_std = env:: var_os ( "MIRI_NO_STD" ) . is_none ( ) ;
104
113
105
- let config = Config {
106
- args : flags,
107
- target,
108
- stderr_filters : STDERR . clone ( ) ,
109
- stdout_filters : STDOUT . clone ( ) ,
110
- root_dir : PathBuf :: from ( path) ,
111
- mode,
112
- path_filter : path_filter. collect ( ) ,
113
- program : miri_path ( ) ,
114
- output_conflict_handling,
115
- dependencies_crate_manifest_path : ( with_dependencies && use_std)
116
- . then ( || Path :: new ( "test_dependencies" ) . join ( "Cargo.toml" ) ) ,
117
- dependency_builder : Some ( DependencyBuilder {
118
- program : std:: env:: var_os ( "CARGO" ) . unwrap ( ) . into ( ) ,
119
- args : vec ! [
120
- "run" . into( ) ,
121
- "--manifest-path" . into( ) ,
122
- "cargo-miri/Cargo.toml" . into( ) ,
123
- "--" . into( ) ,
124
- "miri" . into( ) ,
125
- ] ,
126
- envs : vec ! [ ] ,
127
- } ) ,
128
- quiet,
129
- } ;
114
+ if with_dependencies && use_std {
115
+ config. dependencies_crate_manifest_path =
116
+ Some ( Path :: new ( "test_dependencies" ) . join ( "Cargo.toml" ) ) ;
117
+ config. dependency_builder . args = vec ! [
118
+ "run" . into( ) ,
119
+ "--manifest-path" . into( ) ,
120
+ "cargo-miri/Cargo.toml" . into( ) ,
121
+ "--" . into( ) ,
122
+ "miri" . into( ) ,
123
+ "run" . into( ) , // There is no `cargo miri build` so we just use `cargo miri run`.
124
+ ] ;
125
+ }
130
126
ui_test:: run_tests ( config)
131
127
}
132
128
@@ -214,10 +210,10 @@ fn main() -> Result<()> {
214
210
ui ( Mode :: Pass , "tests/pass" , WithoutDependencies ) ?;
215
211
ui ( Mode :: Pass , "tests/pass-dep" , WithDependencies ) ?;
216
212
ui ( Mode :: Panic , "tests/panic" , WithDependencies ) ?;
217
- ui ( Mode :: Fail , "tests/fail" , WithDependencies ) ?;
213
+ ui ( Mode :: Fail { require_patterns : true } , "tests/fail" , WithDependencies ) ?;
218
214
if cfg ! ( target_os = "linux" ) {
219
215
ui ( Mode :: Pass , "tests/extern-so/pass" , WithoutDependencies ) ?;
220
- ui ( Mode :: Fail , "tests/extern-so/fail" , WithDependencies ) ?;
216
+ ui ( Mode :: Fail { require_patterns : true } , "tests/extern-so/fail" , WithDependencies ) ?;
221
217
}
222
218
223
219
Ok ( ( ) )
0 commit comments