Skip to content

Commit

Permalink
Merge pull request #44 from ltratt/fix_incorrect_capture_of_mut_variable
Browse files Browse the repository at this point in the history
Fix bug where the outer `num_ignored` variable was ignored.
  • Loading branch information
jacob-hughes authored Nov 26, 2019
2 parents 4b03037 + 8309a1f commit d9fe4b1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use std::{
path::{Path, PathBuf},
process::{self, Command, ExitStatus},
str,
sync::{Arc, Mutex},
sync::{
atomic::{AtomicUsize, Ordering},
Arc, Mutex,
},
thread::sleep,
time::{Duration, Instant},
};
Expand Down Expand Up @@ -460,11 +463,12 @@ fn test_file(
inner: Arc<LangTesterPooler>,
) -> (Vec<(String, TestFailure)>, usize) {
let failures = Arc::new(Mutex::new(Vec::new()));
let mut num_ignored = 0;
let num_ignored = Arc::new(AtomicUsize::new(0));
let pool = ThreadPool::new(inner.test_threads);
for p in test_files {
let test_fname = p.file_stem().unwrap().to_str().unwrap().to_owned();

let num_ignored = num_ignored.clone();
let failures = failures.clone();
let inner = inner.clone();
pool.execute(move || {
Expand All @@ -479,26 +483,26 @@ fn test_file(

if test_str.is_empty() {
write_ignored(test_fname.as_str(), "test string is empty", inner);
num_ignored += 1;
num_ignored.fetch_add(1, Ordering::Relaxed);
return;
}

let tests = parse_tests(&test_str);
if (inner.ignored && !tests.ignore) || (!inner.ignored && tests.ignore) {
write_ignored(test_fname.as_str(), "", inner);
num_ignored += 1;
num_ignored.fetch_add(1, Ordering::Relaxed);
return;
}

if run_tests(Arc::clone(&inner), tests.tests, p, failures) {
num_ignored += 1;
num_ignored.fetch_add(1, Ordering::Relaxed);
}
});
}
pool.join();
let failures = Mutex::into_inner(Arc::try_unwrap(failures).unwrap()).unwrap();

(failures, num_ignored)
(failures, Arc::try_unwrap(num_ignored).unwrap().into_inner())
}

/// Run the tests for `path`.
Expand Down

0 comments on commit d9fe4b1

Please sign in to comment.