Skip to content

Commit

Permalink
Account for multiple issues of the same ID in the syntactic test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
daemontus committed Mar 6, 2024
1 parent cabfa65 commit a3969f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
21 changes: 13 additions & 8 deletions examples/test-suite-syntactic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ fn test_inner(filter: Option<HashSet<String>>) -> TestResults {

for issue in issues {
if test_issue(issue.rule.as_str()) {
if expected.contains_key(&issue.rule) {
expected.remove(&issue.rule);
if let Some(entry) = expected.get_mut(&issue.rule) {
entry.1 -= 1;
} else {
println!(
" >> Found issue {} that is not in the expected list: {}",
Expand All @@ -161,7 +161,11 @@ fn test_inner(filter: Option<HashSet<String>>) -> TestResults {
}
}

for (id, sev) in expected {
for (id, (sev, count)) in expected {
if count == 0 {
// All issues of this type have been discovered.
continue;
}
if test_issue(id.as_str()) {
println!(" >> Missed expected issue {}.", id);
let report = format!(
Expand Down Expand Up @@ -194,10 +198,7 @@ fn test_inner(filter: Option<HashSet<String>>) -> TestResults {
}
}

fn read_expected_issues(result_file: &str) -> HashMap<String, SbmlIssueSeverity> {
// TODO:
// This doesn't really work if the issue appears in the file multiple times.
// But it seems that this is not a problem for the cases that we are testing at the moment?
fn read_expected_issues(result_file: &str) -> HashMap<String, (SbmlIssueSeverity, usize)> {
let content = std::fs::read_to_string(result_file).unwrap();
let mut last_rule = None;
let mut result = HashMap::new();
Expand All @@ -220,7 +221,11 @@ fn read_expected_issues(result_file: &str) -> HashMap<String, SbmlIssueSeverity>
panic!("Unknown severity {}", split[1].trim());
}
};
result.insert(last_rule.as_ref().unwrap().clone(), s);
let key = last_rule.as_ref().unwrap().clone();
let entry = result.entry(key);
let value = entry.or_insert((s, 0));
assert_eq!(value.0, s);
value.1 += 1;
last_rule = None;
}
}
Expand Down
22 changes: 15 additions & 7 deletions src/core/validation/test_suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ fn test_inner(filter: Option<HashSet<String>>) {
if !test_name.ends_with(".xml") {
continue;
}
if !test_name.contains("l3v1") {
// Skip any tests that are not for SBML level 3 version 1.
if !test_name.contains("l3v2") {
// Skip any tests that are not for SBML level 3 version 2.
continue;
}

Expand Down Expand Up @@ -96,8 +96,8 @@ fn test_inner(filter: Option<HashSet<String>>) {

for issue in issues {
if test_issue(issue.rule.as_str()) {
if expected.contains_key(&issue.rule) {
expected.remove(&issue.rule);
if let Some(entry) = expected.get_mut(&issue.rule) {
entry.1 -= 1;
} else {
println!(
" >> Found issue {} that is not in the expected list: {}",
Expand All @@ -116,7 +116,11 @@ fn test_inner(filter: Option<HashSet<String>>) {
}
}

for (id, sev) in expected {
for (id, (sev, count)) in expected {
if count == 0 {
// All issues of this type have been discovered.
continue;
}
if test_issue(id.as_str()) {
println!(" >> Missed expected issue {}.", id);
let report = format!(
Expand All @@ -143,7 +147,7 @@ fn test_inner(filter: Option<HashSet<String>>) {
}
}

fn read_expected_issues(result_file: &str) -> HashMap<String, SbmlIssueSeverity> {
fn read_expected_issues(result_file: &str) -> HashMap<String, (SbmlIssueSeverity, usize)> {
let content = std::fs::read_to_string(result_file).unwrap();
let mut last_rule = None;
let mut result = HashMap::new();
Expand All @@ -166,7 +170,11 @@ fn read_expected_issues(result_file: &str) -> HashMap<String, SbmlIssueSeverity>
panic!("Unknown severity {}", split[1].trim());
}
};
result.insert(last_rule.as_ref().unwrap().clone(), s);
let key = last_rule.as_ref().unwrap().clone();
let entry = result.entry(key);
let value = entry.or_insert((s, 0));
assert_eq!(value.0, s);
value.1 += 1;
last_rule = None;
}
}
Expand Down

0 comments on commit a3969f4

Please sign in to comment.