Run tests in a thread with larger stack size
@@ -7,6 +7,7 @@ use std::mem;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::str::Chars;
+use std::thread;
use crate::config::{Color, Config, EmitMode, FileName, NewlineStyle, ReportTactic};
use crate::formatting::{ReportedErrors, SourceFile};
@@ -25,6 +26,32 @@ const SKIP_FILE_WHITE_LIST: &[&str] = &[
"issue-3434/no_entry.rs",
];
+struct TestSetting {
+ /// The size of the stack of the thread that run tests.
+ stack_size: usize,
+}
+
+impl Default for TestSetting {
+ fn default() -> Self {
+ TestSetting {
+ stack_size: 8388608, // 8MB
+ }
+ }
+}
+
+fn run_test_with<F>(test_setting: &TestSetting, f: F)
+where
+ F: FnOnce(),
+ F: Send + 'static,
+{
+ thread::Builder::new()
+ .stack_size(test_setting.stack_size)
+ .spawn(f)
+ .expect("Failed to create a test thread")
+ .join()
+ .expect("Failed to join a test thread")
+}
+
fn is_file_skip(path: &Path) -> bool {
SKIP_FILE_WHITE_LIST
.iter()
@@ -114,6 +141,7 @@ fn write_message(msg: &str) {
// exactly.
#[test]
fn system_tests() {
+ run_test_with(&TestSetting::default(), || {
// Get all files in the tests/source directory.
let files = get_test_files(Path::new("tests/source"), true);
let (_reports, count, fails) = check_files(files, &None);
@@ -121,6 +149,7 @@ fn system_tests() {
// Display results.
println!("Ran {} system tests.", count);
assert_eq!(fails, 0, "{} system tests failed", fails);
+ });
}
// Do the same for tests/coverage-source directory.
@@ -228,6 +257,7 @@ fn assert_output(source: &Path, expected_filename: &Path) {
// rustfmt.
#[test]
fn idempotence_tests() {
+ run_test_with(&TestSetting::default(), || {
match option_env!("CFG_RELEASE_CHANNEL") {
None | Some("nightly") => {}
_ => return, // these tests require nightly
@@ -239,6 +269,7 @@ fn idempotence_tests() {
// Display results.
println!("Ran {} idempotent tests.", count);
assert_eq!(fails, 0, "{} idempotent tests failed", fails);
+ });
}
// Run rustfmt on itself. This operation must be idempotent. We also check that
