Skip to content

Commit 2dc9cfc

Browse files
authored
Merge pull request rust-lang#3477 from topecongiro/test-with-larger-stack-size
Test with larger stack size
2 parents a373e73 + a7728d3 commit 2dc9cfc

File tree

3 files changed

+50
-20
lines changed

3 files changed

+50
-20
lines changed

Diff for: .travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ script:
4646
- |
4747
if [ -z ${INTEGRATION} ]; then
4848
cargo build
49-
RUST_MIN_STACK=8388608 cargo test
49+
cargo test
5050
else
5151
./ci/integration.sh
5252
fi

Diff for: appveyor.yml

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# and modified (mainly removal of deployment) to suit rustfmt.
33

44
environment:
5-
RUST_MIN_STACK: 8388608
65
global:
76
PROJECT_NAME: rustfmt
87
matrix:

Diff for: src/test/mod.rs

+49-18
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::mem;
77
use std::path::{Path, PathBuf};
88
use std::process::{Command, Stdio};
99
use std::str::Chars;
10+
use std::thread;
1011

1112
use crate::config::{Color, Config, EmitMode, FileName, NewlineStyle, ReportTactic};
1213
use crate::formatting::{ReportedErrors, SourceFile};
@@ -25,6 +26,32 @@ const SKIP_FILE_WHITE_LIST: &[&str] = &[
2526
"issue-3434/no_entry.rs",
2627
];
2728

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+
2855
fn is_file_skip(path: &Path) -> bool {
2956
SKIP_FILE_WHITE_LIST
3057
.iter()
@@ -114,13 +141,15 @@ fn write_message(msg: &str) {
114141
// exactly.
115142
#[test]
116143
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+
});
124153
}
125154

126155
// Do the same for tests/coverage-source directory.
@@ -228,17 +257,19 @@ fn assert_output(source: &Path, expected_filename: &Path) {
228257
// rustfmt.
229258
#[test]
230259
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+
});
242273
}
243274

244275
// Run rustfmt on itself. This operation must be idempotent. We also check that

0 commit comments

Comments
 (0)