Skip to content

Commit 944386d

Browse files
committed
refactor(test): clean up test filtering logic
Also, only update the expected output of a case when it is skipped if the `update` flag has been passed
1 parent ef03a3f commit 944386d

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

crates/cli/src/test.rs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -421,12 +421,11 @@ impl TestCorrection {
421421
}
422422

423423
/// This will return false if we want to "fail fast". It will bail and not parse any more tests.
424-
#[allow(clippy::too_many_arguments)]
425424
fn run_tests(
426425
parser: &mut Parser,
427426
test_entry: TestEntry,
428427
opts: &mut TestOptions,
429-
mut indent_level: u32,
428+
indent_level: u32,
430429
failures: &mut Vec<TestFailure>,
431430
corrected_entries: &mut Vec<TestCorrection>,
432431
has_parse_errors: &mut bool,
@@ -660,7 +659,6 @@ fn run_tests(
660659
return Ok(true);
661660
}
662661

663-
indent_level += 1;
664662
let failure_count = failures.len();
665663
let mut has_printed = false;
666664

@@ -680,16 +678,10 @@ fn run_tests(
680678
}
681679
};
682680

683-
let should_skip = |entry: &TestEntry, opts: &TestOptions| match entry {
684-
TestEntry::Example {
685-
name, file_name, ..
686-
} => !matches_filter(name, file_name, opts),
687-
TestEntry::Group { .. } => false,
688-
};
689-
690681
for child in children {
691682
if let TestEntry::Example {
692683
ref name,
684+
ref file_name,
693685
ref input,
694686
ref output,
695687
ref attributes_str,
@@ -698,37 +690,38 @@ fn run_tests(
698690
..
699691
} = child
700692
{
701-
if should_skip(&child, opts) {
702-
let input = String::from_utf8(input.clone()).unwrap();
703-
let output = format_sexp(output, 0);
704-
corrected_entries.push(TestCorrection::new(
705-
name,
706-
input,
707-
output,
708-
attributes_str,
709-
header_delim_len,
710-
divider_delim_len,
711-
));
693+
if !matches_filter(name, file_name, opts) {
694+
if opts.update {
695+
let input = String::from_utf8(input.clone()).unwrap();
696+
let output = format_sexp(output, 0);
697+
corrected_entries.push(TestCorrection::new(
698+
name,
699+
input,
700+
output,
701+
attributes_str,
702+
header_delim_len,
703+
divider_delim_len,
704+
));
705+
}
712706

713707
opts.test_num += 1;
714-
715708
continue;
716709
}
717710
}
718-
if !has_printed && indent_level > 1 {
711+
if !has_printed && indent_level > 0 {
719712
has_printed = true;
720713
writeln!(
721714
opts.output,
722715
"{}{name}:",
723-
" ".repeat((indent_level - 1) as usize)
716+
" ".repeat(indent_level as usize)
724717
)?;
725718
opts.parse_rates.push((false, None));
726719
}
727720
if !run_tests(
728721
parser,
729722
child,
730723
opts,
731-
indent_level,
724+
indent_level + 1,
732725
failures,
733726
corrected_entries,
734727
has_parse_errors,

0 commit comments

Comments
 (0)