Skip to content

Commit

Permalink
Merge pull request #3477 from topecongiro/test-with-larger-stack-size
Browse files Browse the repository at this point in the history
Test with larger stack size
  • Loading branch information
topecongiro authored Mar 27, 2019
2 parents a373e73 + a7728d3 commit 2dc9cfc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ script:
- |
if [ -z ${INTEGRATION} ]; then
cargo build
RUST_MIN_STACK=8388608 cargo test
cargo test
else
./ci/integration.sh
fi
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# and modified (mainly removal of deployment) to suit rustfmt.

environment:
RUST_MIN_STACK: 8388608
global:
PROJECT_NAME: rustfmt
matrix:
Expand Down
67 changes: 49 additions & 18 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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()
Expand Down Expand Up @@ -114,13 +141,15 @@ fn write_message(msg: &str) {
// exactly.
#[test]
fn system_tests() {
// 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);

// Display results.
println!("Ran {} system tests.", count);
assert_eq!(fails, 0, "{} system tests failed", fails);
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);

// Display results.
println!("Ran {} system tests.", count);
assert_eq!(fails, 0, "{} system tests failed", fails);
});
}

// Do the same for tests/coverage-source directory.
Expand Down Expand Up @@ -228,17 +257,19 @@ fn assert_output(source: &Path, expected_filename: &Path) {
// rustfmt.
#[test]
fn idempotence_tests() {
match option_env!("CFG_RELEASE_CHANNEL") {
None | Some("nightly") => {}
_ => return, // these tests require nightly
}
// Get all files in the tests/target directory.
let files = get_test_files(Path::new("tests/target"), true);
let (_reports, count, fails) = check_files(files, &None);

// Display results.
println!("Ran {} idempotent tests.", count);
assert_eq!(fails, 0, "{} idempotent tests failed", fails);
run_test_with(&TestSetting::default(), || {
match option_env!("CFG_RELEASE_CHANNEL") {
None | Some("nightly") => {}
_ => return, // these tests require nightly
}
// Get all files in the tests/target directory.
let files = get_test_files(Path::new("tests/target"), true);
let (_reports, count, fails) = check_files(files, &None);

// 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
Expand Down

0 comments on commit 2dc9cfc

Please sign in to comment.