Skip to content

Commit d9fe4b1

Browse files
authored
Merge pull request #44 from ltratt/fix_incorrect_capture_of_mut_variable
Fix bug where the outer `num_ignored` variable was ignored.
2 parents 4b03037 + 8309a1f commit d9fe4b1

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/tester.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use std::{
77
path::{Path, PathBuf},
88
process::{self, Command, ExitStatus},
99
str,
10-
sync::{Arc, Mutex},
10+
sync::{
11+
atomic::{AtomicUsize, Ordering},
12+
Arc, Mutex,
13+
},
1114
thread::sleep,
1215
time::{Duration, Instant},
1316
};
@@ -460,11 +463,12 @@ fn test_file(
460463
inner: Arc<LangTesterPooler>,
461464
) -> (Vec<(String, TestFailure)>, usize) {
462465
let failures = Arc::new(Mutex::new(Vec::new()));
463-
let mut num_ignored = 0;
466+
let num_ignored = Arc::new(AtomicUsize::new(0));
464467
let pool = ThreadPool::new(inner.test_threads);
465468
for p in test_files {
466469
let test_fname = p.file_stem().unwrap().to_str().unwrap().to_owned();
467470

471+
let num_ignored = num_ignored.clone();
468472
let failures = failures.clone();
469473
let inner = inner.clone();
470474
pool.execute(move || {
@@ -479,26 +483,26 @@ fn test_file(
479483

480484
if test_str.is_empty() {
481485
write_ignored(test_fname.as_str(), "test string is empty", inner);
482-
num_ignored += 1;
486+
num_ignored.fetch_add(1, Ordering::Relaxed);
483487
return;
484488
}
485489

486490
let tests = parse_tests(&test_str);
487491
if (inner.ignored && !tests.ignore) || (!inner.ignored && tests.ignore) {
488492
write_ignored(test_fname.as_str(), "", inner);
489-
num_ignored += 1;
493+
num_ignored.fetch_add(1, Ordering::Relaxed);
490494
return;
491495
}
492496

493497
if run_tests(Arc::clone(&inner), tests.tests, p, failures) {
494-
num_ignored += 1;
498+
num_ignored.fetch_add(1, Ordering::Relaxed);
495499
}
496500
});
497501
}
498502
pool.join();
499503
let failures = Mutex::into_inner(Arc::try_unwrap(failures).unwrap()).unwrap();
500504

501-
(failures, num_ignored)
505+
(failures, Arc::try_unwrap(num_ignored).unwrap().into_inner())
502506
}
503507

504508
/// Run the tests for `path`.

0 commit comments

Comments
 (0)