@@ -7,6 +7,7 @@ use std::mem;
7
7
use std:: path:: { Path , PathBuf } ;
8
8
use std:: process:: { Command , Stdio } ;
9
9
use std:: str:: Chars ;
10
+ use std:: thread;
10
11
11
12
use crate :: config:: { Color , Config , EmitMode , FileName , NewlineStyle , ReportTactic } ;
12
13
use crate :: formatting:: { ReportedErrors , SourceFile } ;
@@ -25,6 +26,32 @@ const SKIP_FILE_WHITE_LIST: &[&str] = &[
25
26
"issue-3434/no_entry.rs" ,
26
27
] ;
27
28
29
+ struct TestSetting {
30
+ /// The size of the stack of the thread that run tests.
31
+ stack_size : usize ,
32
+ }
33
+
34
+ impl Default for TestSetting {
35
+ fn default ( ) -> Self {
36
+ TestSetting {
37
+ stack_size : 8388608 , // 8MB
38
+ }
39
+ }
40
+ }
41
+
42
+ fn run_test_with < F > ( test_setting : & TestSetting , f : F )
43
+ where
44
+ F : FnOnce ( ) ,
45
+ F : Send + ' static ,
46
+ {
47
+ thread:: Builder :: new ( )
48
+ . stack_size ( test_setting. stack_size )
49
+ . spawn ( f)
50
+ . expect ( "Failed to create a test thread" )
51
+ . join ( )
52
+ . expect ( "Failed to join a test thread" )
53
+ }
54
+
28
55
fn is_file_skip ( path : & Path ) -> bool {
29
56
SKIP_FILE_WHITE_LIST
30
57
. iter ( )
@@ -114,13 +141,15 @@ fn write_message(msg: &str) {
114
141
// exactly.
115
142
#[ test]
116
143
fn system_tests ( ) {
117
- // Get all files in the tests/source directory.
118
- let files = get_test_files ( Path :: new ( "tests/source" ) , true ) ;
119
- let ( _reports, count, fails) = check_files ( files, & None ) ;
120
-
121
- // Display results.
122
- println ! ( "Ran {} system tests." , count) ;
123
- assert_eq ! ( fails, 0 , "{} system tests failed" , fails) ;
144
+ run_test_with ( & TestSetting :: default ( ) , || {
145
+ // Get all files in the tests/source directory.
146
+ let files = get_test_files ( Path :: new ( "tests/source" ) , true ) ;
147
+ let ( _reports, count, fails) = check_files ( files, & None ) ;
148
+
149
+ // Display results.
150
+ println ! ( "Ran {} system tests." , count) ;
151
+ assert_eq ! ( fails, 0 , "{} system tests failed" , fails) ;
152
+ } ) ;
124
153
}
125
154
126
155
// Do the same for tests/coverage-source directory.
@@ -228,17 +257,19 @@ fn assert_output(source: &Path, expected_filename: &Path) {
228
257
// rustfmt.
229
258
#[ test]
230
259
fn idempotence_tests ( ) {
231
- match option_env ! ( "CFG_RELEASE_CHANNEL" ) {
232
- None | Some ( "nightly" ) => { }
233
- _ => return , // these tests require nightly
234
- }
235
- // Get all files in the tests/target directory.
236
- let files = get_test_files ( Path :: new ( "tests/target" ) , true ) ;
237
- let ( _reports, count, fails) = check_files ( files, & None ) ;
238
-
239
- // Display results.
240
- println ! ( "Ran {} idempotent tests." , count) ;
241
- assert_eq ! ( fails, 0 , "{} idempotent tests failed" , fails) ;
260
+ run_test_with ( & TestSetting :: default ( ) , || {
261
+ match option_env ! ( "CFG_RELEASE_CHANNEL" ) {
262
+ None | Some ( "nightly" ) => { }
263
+ _ => return , // these tests require nightly
264
+ }
265
+ // Get all files in the tests/target directory.
266
+ let files = get_test_files ( Path :: new ( "tests/target" ) , true ) ;
267
+ let ( _reports, count, fails) = check_files ( files, & None ) ;
268
+
269
+ // Display results.
270
+ println ! ( "Ran {} idempotent tests." , count) ;
271
+ assert_eq ! ( fails, 0 , "{} idempotent tests failed" , fails) ;
272
+ } ) ;
242
273
}
243
274
244
275
// Run rustfmt on itself. This operation must be idempotent. We also check that
0 commit comments