Skip to content

Commit

Permalink
fix(cli): keep skipped tests unchanged in the test/corpus
Browse files Browse the repository at this point in the history
  • Loading branch information
jetjinser authored and amaanq committed Sep 7, 2024
1 parent 26c1202 commit fd190f1
Showing 1 changed file with 59 additions and 47 deletions.
106 changes: 59 additions & 47 deletions cli/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
collections::{BTreeMap, HashSet},
collections::BTreeMap,
ffi::OsStr,
fs,
io::{self, Write},
Expand Down Expand Up @@ -517,64 +517,76 @@ fn run_tests(
}
TestEntry::Group {
name,
mut children,
children,
file_path,
} => {
// track which tests are being skipped to maintain consistent numbering while using
// filters
let mut skipped_tests = HashSet::new();
if children.is_empty() {
return Ok(true);
}

indent_level += 1;
let mut advance_counter = opts.test_num;
children.retain(|child| match child {
let failure_count = failures.len();
let mut has_printed = false;
let mut skipped_tests = 0;

let matches_filter = |name: &str, opts: &TestOptions| {
if let Some(filter) = opts.filter {
name.contains(filter)
} else if let Some(include) = &opts.include {
include.is_match(name)
} else if let Some(exclude) = &opts.exclude {
!exclude.is_match(name)
} else {
true
}
};

let mut should_skip = |entry: &TestEntry, opts: &TestOptions| match entry {
TestEntry::Example { name, .. } => {
if let Some(filter) = opts.filter {
if !name.contains(filter) {
skipped_tests.insert(advance_counter);
advance_counter += 1;
return false;
}
}
if let Some(include) = &opts.include {
if !include.is_match(name) {
skipped_tests.insert(advance_counter);
advance_counter += 1;
return false;
}
}
if let Some(exclude) = &opts.exclude {
if exclude.is_match(name) {
skipped_tests.insert(advance_counter);
advance_counter += 1;
return false;
}
}
advance_counter += 1;
true
!matches_filter(name, opts)
}
TestEntry::Group { .. } => {
advance_counter += count_subtests(child);
true
advance_counter += count_subtests(entry);
false
}
});

if children.is_empty() {
opts.test_num = advance_counter;
return Ok(true);
}

if indent_level > 0 {
print!("{}", " ".repeat(indent_level as usize));
println!("{name}:");
}

let failure_count = failures.len();
};

indent_level += 1;
for child in children {
if let TestEntry::Example { .. } = child {
while skipped_tests.remove(&opts.test_num) {
if let TestEntry::Example {
ref name,
ref input,
ref output,
ref attributes_str,
header_delim_len,
divider_delim_len,
..
} = child
{
if should_skip(&child, opts) {
let input = String::from_utf8(input.clone()).unwrap();
let output = format_sexp(output, 0);
corrected_entries.push((
name.clone(),
input,
output,
attributes_str.clone(),
header_delim_len,
divider_delim_len,
));

opts.test_num += 1;
skipped_tests += 1;

continue;
}
}
if !has_printed && indent_level > 1 {
has_printed = true;
print!("{}", " ".repeat((indent_level - 1) as usize));
println!("{name}:");
}
if !run_tests(
parser,
child,
Expand All @@ -589,7 +601,7 @@ fn run_tests(
}
}

opts.test_num += skipped_tests.len();
opts.test_num += skipped_tests;

if let Some(file_path) = file_path {
if opts.update && failures.len() - failure_count > 0 {
Expand Down

0 comments on commit fd190f1

Please sign in to comment.