From 72ab8890cbc3adf9430a2497a73de66176fa4b7b Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Mon, 30 Nov 2026 16:51:11 +0000 Subject: [PATCH 1/2] feat(coverage): credit shell forms only from their cited cases A [[link]] marked shell = true names forms nearly every statement wraps others in, such as identifiers. Only the cases a shell form's required obligations cite credit it; a refusal counts against it when it names its construct or the whole statement, or when the statement links no other form, and a differing statement only in that last case. A shell form needs a cited obligation, and its links are all shells or none. PostgreSQL marks the identifier link a shell. --- coverage/translation-postgres/form-links.toml | 3 + .../results-baseline.json | 2 +- coverage/translation/README.md | 8 +- .../src/results/_helpers/files.rs | 40 ++++- .../src/results/_helpers/links.rs | 28 ++- .../src/results/_helpers/report.rs | 16 +- .../src/results/models.rs | 3 + .../src/results/tests/test_obligations.rs | 166 +++++++++++++++++- .../src/results/tests/test_types.rs | 18 ++ 9 files changed, 262 insertions(+), 22 deletions(-) diff --git a/coverage/translation-postgres/form-links.toml b/coverage/translation-postgres/form-links.toml index 71db0faaf..b32334709 100644 --- a/coverage/translation-postgres/form-links.toml +++ b/coverage/translation-postgres/form-links.toml @@ -757,9 +757,12 @@ forms = ["pg.expressions.sql-syntax-lexical.binary-integer"] constructs = ["spelling:digit_separators"] forms = ["pg.expressions.sql-syntax-lexical.digit-separators"] +# A shell: nearly every statement names a column or table, so identifier takes credit only from +# its own hand cases and blame only for a refusal of identifiers or of the whole statement. [[link]] constructs = ["spelling:identifier"] forms = ["pg.expressions.sql-syntax-lexical.identifier"] +shell = true [[link]] constructs = ["spelling:quoted_identifier"] diff --git a/coverage/translation-postgres/results-baseline.json b/coverage/translation-postgres/results-baseline.json index 18f67396f..562aab0bc 100644 --- a/coverage/translation-postgres/results-baseline.json +++ b/coverage/translation-postgres/results-baseline.json @@ -3692,7 +3692,7 @@ "pg.expressions.sql-syntax-lexical.function-style-string": "matching", "pg.expressions.sql-syntax-lexical.hex-bit-string": "matching", "pg.expressions.sql-syntax-lexical.hex-integer": "matching", - "pg.expressions.sql-syntax-lexical.identifier": "refused", + "pg.expressions.sql-syntax-lexical.identifier": "matching", "pg.expressions.sql-syntax-lexical.integer": "matching", "pg.expressions.sql-syntax-lexical.line-comment": "matching", "pg.expressions.sql-syntax-lexical.octal-integer": "matching", diff --git a/coverage/translation/README.md b/coverage/translation/README.md index 5f68df554..0cd2bca4b 100644 --- a/coverage/translation/README.md +++ b/coverage/translation/README.md @@ -13,7 +13,13 @@ separately from syntax coverage, and every figure comes from the checker. function form whose grammar calls that name; this file links operators, clauses, casts and the rest, and lists the constructs that name no form of their own. A `[[link]]` with `except_within_ulps = true` skips statements matching only within ULPs: they count neither for - nor against its forms, while every other statement it links still does. + nor against its forms, while every other statement it links still does. A `[[link]]` with + `shell = true` marks its forms as shells, grammar nearly every statement wraps other forms in, + such as identifiers. Only the cases a shell form's own required obligations cite credit it. A + refused statement counts against it when the refusal names one of its constructs or the whole + statement, or when the statement links no form but shells; a statement that differs counts + against it only in that last case. A shell form needs a required obligation citing a case, and + its links are all shells or none. - `argument-types.toml` (optional): for a function name several forms share, the type families each form's first argument takes (`[[form]]` with `id` and `first`), as the dialect's converter names them. A statement recording its calls with their argument types links a call only to the diff --git a/tools/sqlbabel-coverage-check/src/results/_helpers/files.rs b/tools/sqlbabel-coverage-check/src/results/_helpers/files.rs index 83a9d9999..51b8674ee 100644 --- a/tools/sqlbabel-coverage-check/src/results/_helpers/files.rs +++ b/tools/sqlbabel-coverage-check/src/results/_helpers/files.rs @@ -50,7 +50,7 @@ fn is_slug(id: &str) -> bool { }) } -/// Every problem with the links: malformed keys, unknown forms, a construct both linked and not, or a cited form also linked by key. +/// Every problem with the links: malformed keys, unknown forms, a construct both linked and not, a form in shell and other links, or a cited form also linked by key. fn check_links(links: &LinksFile, catalogued: &BTreeSet<&str>) -> Vec { let mut problems: Vec = Vec::new(); let mut linked: BTreeSet<&str> = BTreeSet::new(); @@ -91,6 +91,19 @@ fn check_links(links: &LinksFile, catalogued: &BTreeSet<&str>) -> Vec { } } } + let shells = shell_forms(links); + for link in links.links.iter().filter(|link| !link.shell) { + for form in link + .forms + .iter() + .filter(|form| shells.contains(form.as_str())) + { + problems.push(format!( + "link {}: {form} is a shell form in another link; a form's links are all shells or none", + link.constructs.join(" + ") + )); + } + } let keyed: BTreeSet<&str> = links .links .iter() @@ -319,17 +332,32 @@ pub(crate) fn cited_forms(links: &LinksFile) -> BTreeSet<&str> { .collect() } -/// A problem for each cited form that no required obligation of its own cites a case for. +/// The forms of `[[link]]` entries marked `shell`. +pub(crate) fn shell_forms(links: &LinksFile) -> BTreeSet<&str> { + links + .links + .iter() + .filter(|link| link.shell) + .flat_map(|link| link.forms.iter().map(String::as_str)) + .collect() +} + +/// A problem for each cited or shell form that no required obligation of its own cites a case for, as only those cases credit it. fn uncited_forms(links: &LinksFile, obligations: &[TranslationObligation]) -> Vec { let citing: BTreeSet<&str> = obligations .iter() .filter(|obligation| obligation.required && !obligation.cases.is_empty()) .map(|obligation| obligation.form.as_str()) .collect(); - cited_forms(links) - .difference(&citing) - .map(|form| format!("cited_forms: {form} has no required obligation citing a case")) - .collect() + let cited = cited_forms(links) + .into_iter() + .filter(|form| !citing.contains(form)) + .map(|form| format!("cited_forms: {form} has no required obligation citing a case")); + let shells = shell_forms(links) + .into_iter() + .filter(|form| !citing.contains(form)) + .map(|form| format!("shell link: {form} has no required obligation citing a case")); + cited.chain(shells).collect() } /// The SHA-256 a group's sign-off binds: its reason, then each form on its own line. diff --git a/tools/sqlbabel-coverage-check/src/results/_helpers/links.rs b/tools/sqlbabel-coverage-check/src/results/_helpers/links.rs index 22e5fa7a5..0fa1df772 100644 --- a/tools/sqlbabel-coverage-check/src/results/_helpers/links.rs +++ b/tools/sqlbabel-coverage-check/src/results/_helpers/links.rs @@ -4,6 +4,7 @@ use std::collections::{BTreeMap, BTreeSet}; use crate::formats::main::content_sha256::content_sha256; use crate::formats::models::{FormStatus, SyntaxCoverage}; +use crate::results::_helpers::files::shell_forms; use crate::results::constants::{ CALL, CALL_BARE, CALL_NAMED, CALL_OVER, CALL_PREFIXES, FUNCTION_PREFIX, FUNCTIONS_FAMILY, STATEMENT_REFUSAL, @@ -23,8 +24,11 @@ pub(crate) struct FunctionIndex { /// The forms a statement links to, and those its refusal names. pub(crate) struct StatementLinks { - pub(crate) forms: BTreeSet, - /// The forms of its refused constructs; every linked form when they name none or the whole. + /// The forms it credits when it matches: every linked form but shells. + pub(crate) credited: BTreeSet, + /// The forms a statement that differs counts against: as `credited`, or every linked form when it links only shells. + pub(crate) carried: BTreeSet, + /// The forms of its refused constructs; every linked form when it refuses the whole, and `carried` when its refused constructs name no form. pub(crate) refused_forms: BTreeSet, /// Whether a refusal of it is the whole statement's: it names the whole, or no key names a form. pub(crate) whole_refusal: bool, @@ -239,13 +243,25 @@ pub(crate) fn link_statement( .0, ); } - let whole_refusal = whole || named.is_empty(); - let refused_forms: BTreeSet = match whole_refusal { + let shells = shell_forms(links); + let credited: BTreeSet = forms + .iter() + .filter(|form| !shells.contains(form.as_str())) + .cloned() + .collect(); + let carried = match credited.is_empty() { true => forms.clone(), - false => named, + false => credited.clone(), + }; + let whole_refusal = whole || named.is_empty(); + let refused_forms: BTreeSet = match (whole, named.is_empty()) { + (true, _) => forms, + (false, true) => carried.clone(), + (false, false) => named, }; StatementLinks { - forms, + credited, + carried, refused_forms, whole_refusal, unaccounted, diff --git a/tools/sqlbabel-coverage-check/src/results/_helpers/report.rs b/tools/sqlbabel-coverage-check/src/results/_helpers/report.rs index 80eacd69f..5e96a5f4c 100644 --- a/tools/sqlbabel-coverage-check/src/results/_helpers/report.rs +++ b/tools/sqlbabel-coverage-check/src/results/_helpers/report.rs @@ -4,7 +4,7 @@ use std::collections::{BTreeMap, BTreeSet}; use crate::formats::models::SyntaxCoverage; use crate::results::_helpers::files::{ - cited_forms, declared_sha256, group_sha256, signed, subjects, + cited_forms, declared_sha256, group_sha256, shell_forms, signed, subjects, }; use crate::results::_helpers::forms::{family_tallies, form_result, statement_tally}; use crate::results::_helpers::links::{FunctionIndex, link_statement}; @@ -85,9 +85,10 @@ fn unmapped(construct: &str, references: &[&str]) -> String { ) } -/// The cited forms of the links file by each statement reference their required obligations cite. +/// The cited and shell forms of the links file by each statement reference their required obligations cite. fn cited_cases(files: &ResultsFiles) -> BTreeMap<&str, BTreeSet> { - let forms: BTreeSet<&str> = cited_forms(&files.links); + let mut forms: BTreeSet<&str> = cited_forms(&files.links); + forms.extend(shell_forms(&files.links)); let mut cases: BTreeMap<&str, BTreeSet> = BTreeMap::new(); for obligation in &files.obligations { if !obligation.required || !forms.contains(obligation.form.as_str()) { @@ -104,7 +105,7 @@ fn cited_cases(files: &ResultsFiles) -> BTreeMap<&str, BTreeSet> { cases } -/// The forms each statement counts for: an uncredited one none, a refused one only for the forms its refusal names, and a cited case also for the cited forms its obligations name unless its refusal names other forms. +/// The forms each statement counts for: an uncredited one none, a refused one only for the forms its refusal names, a differing one for its forms other than shells unless it links only shells, any other for its forms other than shells, and a cited case also for the cited and shell forms its obligations name unless its refusal names other forms. pub(crate) fn link_all<'a>( statements: &'a [RecordedStatement], functions: &FunctionIndex, @@ -123,9 +124,10 @@ pub(crate) fn link_all<'a>( .push(&statement.reference); } let refused = statement.outcome.refused(); - let mut forms = match refused { - true => linked.refused_forms, - false => linked.forms, + let mut forms = match (refused, statement.outcome) { + (true, _) => linked.refused_forms, + (false, StatementOutcome::Differs) => linked.carried, + (false, _) => linked.credited, }; if uncredited.contains_key(statement.reference.as_str()) { forms.clear(); diff --git a/tools/sqlbabel-coverage-check/src/results/models.rs b/tools/sqlbabel-coverage-check/src/results/models.rs index e9f6ad8ec..a7f1f1a77 100644 --- a/tools/sqlbabel-coverage-check/src/results/models.rs +++ b/tools/sqlbabel-coverage-check/src/results/models.rs @@ -182,6 +182,9 @@ pub struct FormLink { /// Whether a statement matching only within ULPs skips this link, counting neither for nor against its forms. #[serde(default)] pub except_within_ulps: bool, + /// Whether the forms are shells: grammar most statements wrap other forms in, such as identifiers. A shell form is credited only by the cases its own required obligations cite, and blamed only for a refusal of its own constructs, of the whole statement, or of a statement that links no other form. + #[serde(default)] + pub shell: bool, } /// Forms whose grammar no construct key tells apart, each linked only to the cases its own required obligations cite. diff --git a/tools/sqlbabel-coverage-check/src/results/tests/test_obligations.rs b/tools/sqlbabel-coverage-check/src/results/tests/test_obligations.rs index 19b77d2c2..f017c8b76 100644 --- a/tools/sqlbabel-coverage-check/src/results/tests/test_obligations.rs +++ b/tools/sqlbabel-coverage-check/src/results/tests/test_obligations.rs @@ -16,7 +16,7 @@ use crate::results::tests::helpers::{ use crate::results::tests::test_types::{ CitedFormTestCase, DeclaredRefusalTestCase, ObligationDiffTestCase, ObligationLoadTestCase, ObligationStateTestCase, ObligationsCliTestCase, ResultsArgumentsTestCase, - ResultsRootsTestCase, + ResultsRootsTestCase, ShellLinkTestCase, }; /// The statement under COUNT_IF's form that matches Snowflake, cited by no obligation. @@ -874,3 +874,167 @@ fn given_declared_refusals_when_measuring_then_only_signed_raises_of_the_named_d ); } } + +#[test] +fn given_a_shell_link_when_measuring_then_only_its_cited_cases_credit_it_and_no_refusal_lands_on_no_form() + { + use StatementOutcome::{Differs, Matching, Refused}; + const IDENTIFIER: &[&str] = &["spelling:identifier"]; + const WITH_SELECT: &[&str] = &["spelling:identifier", "node:select"]; + const WITH_COLUMN: &[&str] = &["spelling:identifier", "node:column"]; + let cited = iff_obligation(1, "t001"); + let test_cases = [ + ShellLinkTestCase { + description: "its cited case matches, and a refusal naming another form's construct leaves it matching", + links: "", + obligations: cited.clone(), + cited: (Matching, &[]), + other: (Refused, WITH_SELECT, &["node:select"]), + expected_state: Some(ResultState::Matching), + expected_problem: "", + }, + ShellLinkTestCase { + description: "a match of another form's case does not credit it, so a cited case refused for another form leaves it unmeasured", + links: "", + obligations: cited.clone(), + cited: (Refused, &["node:select"]), + other: (Matching, WITH_SELECT, &[]), + expected_state: Some(ResultState::Unmeasured), + expected_problem: "", + }, + ShellLinkTestCase { + description: "a refusal of its own construct refuses it", + links: "", + obligations: cited.clone(), + cited: (Matching, &[]), + other: (Refused, WITH_SELECT, &["spelling:identifier"]), + expected_state: Some(ResultState::Refused), + expected_problem: "", + }, + ShellLinkTestCase { + description: "a refusal of the whole statement refuses it", + links: "", + obligations: cited.clone(), + cited: (Matching, &[]), + other: (Refused, WITH_SELECT, &["statement"]), + expected_state: Some(ResultState::Refused), + expected_problem: "", + }, + ShellLinkTestCase { + description: "a refusal naming no form, of a statement linking no other form, refuses it", + links: "", + obligations: cited.clone(), + cited: (Matching, &[]), + other: (Refused, WITH_COLUMN, &["node:column"]), + expected_state: Some(ResultState::Refused), + expected_problem: "", + }, + ShellLinkTestCase { + description: "a refusal naming no form, of a statement linking another form, refuses that form instead", + links: "", + obligations: cited.clone(), + cited: (Matching, &[]), + other: ( + Refused, + &["spelling:identifier", "node:column", "node:select"], + &["node:column"], + ), + expected_state: Some(ResultState::Matching), + expected_problem: "", + }, + ShellLinkTestCase { + description: "a statement that differs and links no other form counts against it", + links: "", + obligations: cited.clone(), + cited: (Matching, &[]), + other: (Differs, IDENTIFIER, &[]), + expected_state: Some(ResultState::Differs), + expected_problem: "", + }, + ShellLinkTestCase { + description: "a statement that differs and links another form counts against that form", + links: "", + obligations: cited.clone(), + cited: (Matching, &[]), + other: (Differs, WITH_SELECT, &[]), + expected_state: Some(ResultState::Matching), + expected_problem: "", + }, + ShellLinkTestCase { + description: "its only cited case refused whole: it does not match", + links: "", + obligations: cited.clone(), + cited: (Refused, &[]), + other: (Matching, WITH_SELECT, &[]), + expected_state: Some(ResultState::Refused), + expected_problem: "", + }, + ShellLinkTestCase { + description: "its only cited case differs: it does not match", + links: "", + obligations: cited.clone(), + cited: (Differs, &[]), + other: (Matching, WITH_SELECT, &[]), + expected_state: Some(ResultState::Differs), + expected_problem: "", + }, + ShellLinkTestCase { + description: "a shell form with no required obligation citing a case is a load error", + links: "", + obligations: String::new(), + cited: (Matching, &[]), + other: (Matching, WITH_SELECT, &[]), + expected_state: None, + expected_problem: "shell link: sf.functions.iff has no required obligation citing a case", + }, + ShellLinkTestCase { + description: "a form linked both as a shell and not is a load error", + links: "[[link]]\nconstructs = [\"node:window_function\"]\nforms = [\"sf.functions.iff\"]\n", + obligations: cited.clone(), + cited: (Matching, &[]), + other: (Matching, WITH_SELECT, &[]), + expected_state: None, + expected_problem: "sf.functions.iff is a shell form in another link", + }, + ]; + for test_case in test_cases { + let (cited_outcome, cited_refused) = test_case.cited; + let mut cited = statement( + "translation/functions/iff.toml#t001", + cited_outcome, + WITH_SELECT, + ); + cited.refused = cited_refused.iter().map(|key| (*key).to_owned()).collect(); + let (other_outcome, other_constructs, other_refused) = test_case.other; + let mut other = statement( + "translation/functions/count-if.toml#t009", + other_outcome, + other_constructs, + ); + other.refused = other_refused.iter().map(|key| (*key).to_owned()).collect(); + let links = format!( + "{LINKS}[[link]]\nconstructs = [\"spelling:identifier\"]\nforms = [\"sf.functions.iff\"]\nshell = true\n{}", + test_case.links + ); + let measured = measure_linked(vec![cited, other], &links, (&test_case.obligations, "")); + let state = measured.as_ref().ok().map(|report| { + report + .form_results + .iter() + .find(|form| form.id == "sf.functions.iff") + .expect("form") + .state + }); + let problems = measured.err().unwrap_or_default().join("; "); + assert_eq!( + state, test_case.expected_state, + "{}: {problems}", + test_case.description + ); + assert!( + problems.contains(test_case.expected_problem), + "{}: {problems}", + test_case.description + ); + } +} diff --git a/tools/sqlbabel-coverage-check/src/results/tests/test_types.rs b/tools/sqlbabel-coverage-check/src/results/tests/test_types.rs index 7577847d0..1fbfb618f 100644 --- a/tools/sqlbabel-coverage-check/src/results/tests/test_types.rs +++ b/tools/sqlbabel-coverage-check/src/results/tests/test_types.rs @@ -229,3 +229,21 @@ pub(crate) struct RepeatedUncreditedTestCase { pub(crate) recorded: [(StatementOutcome, &'static [&'static str]); 2], pub(crate) expected_problem: &'static str, } + +/// IFF's form linked as a shell by `spelling:identifier`: its cited case and one other statement, each an outcome with refused keys, and IFF's state or a fragment of the problem. +pub(crate) struct ShellLinkTestCase { + pub(crate) description: &'static str, + /// Links added to the fixture's, after the shell link. + pub(crate) links: &'static str, + pub(crate) obligations: String, + /// IFF's cited case, which uses an identifier and the select. + pub(crate) cited: (StatementOutcome, &'static [&'static str]), + /// Another statement: its outcome, constructs and refused keys. + pub(crate) other: ( + StatementOutcome, + &'static [&'static str], + &'static [&'static str], + ), + pub(crate) expected_state: Option, + pub(crate) expected_problem: &'static str, +} From 4c676b7348891f03f420c7182b3bab1cdbb44d9d Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Mon, 30 Nov 2026 17:00:44 +0000 Subject: [PATCH 2/2] fix(coverage): blame shells when no other linked form takes a refusal A query statement whose only other form takes only effect statements, and a statement linking only shells refused on a key naming a form it does not use, now count against their shells, so no refusal or difference counts against no form. --- .../src/results/_helpers/links.rs | 8 +++-- .../src/results/_helpers/report.rs | 33 +++++++++++++++---- .../src/results/tests/test_obligations.rs | 21 ++++++++++++ 3 files changed, 53 insertions(+), 9 deletions(-) diff --git a/tools/sqlbabel-coverage-check/src/results/_helpers/links.rs b/tools/sqlbabel-coverage-check/src/results/_helpers/links.rs index 0fa1df772..fd8a5962d 100644 --- a/tools/sqlbabel-coverage-check/src/results/_helpers/links.rs +++ b/tools/sqlbabel-coverage-check/src/results/_helpers/links.rs @@ -24,11 +24,13 @@ pub(crate) struct FunctionIndex { /// The forms a statement links to, and those its refusal names. pub(crate) struct StatementLinks { + /// Every form it links, shells included. + pub(crate) forms: BTreeSet, /// The forms it credits when it matches: every linked form but shells. pub(crate) credited: BTreeSet, /// The forms a statement that differs counts against: as `credited`, or every linked form when it links only shells. pub(crate) carried: BTreeSet, - /// The forms of its refused constructs; every linked form when it refuses the whole, and `carried` when its refused constructs name no form. + /// The forms of its refused constructs, with its shells when it links nothing else; every linked form when it refuses the whole, and `carried` when its refused constructs name no form. pub(crate) refused_forms: BTreeSet, /// Whether a refusal of it is the whole statement's: it names the whole, or no key names a form. pub(crate) whole_refusal: bool, @@ -255,11 +257,13 @@ pub(crate) fn link_statement( }; let whole_refusal = whole || named.is_empty(); let refused_forms: BTreeSet = match (whole, named.is_empty()) { - (true, _) => forms, + (true, _) => forms.clone(), (false, true) => carried.clone(), + (false, false) if credited.is_empty() => named.union(&forms).cloned().collect(), (false, false) => named, }; StatementLinks { + forms, credited, carried, refused_forms, diff --git a/tools/sqlbabel-coverage-check/src/results/_helpers/report.rs b/tools/sqlbabel-coverage-check/src/results/_helpers/report.rs index 5e96a5f4c..02de64358 100644 --- a/tools/sqlbabel-coverage-check/src/results/_helpers/report.rs +++ b/tools/sqlbabel-coverage-check/src/results/_helpers/report.rs @@ -105,13 +105,25 @@ fn cited_cases(files: &ResultsFiles) -> BTreeMap<&str, BTreeSet> { cases } -/// The forms each statement counts for: an uncredited one none, a refused one only for the forms its refusal names, a differing one for its forms other than shells unless it links only shells, any other for its forms other than shells, and a cited case also for the cited and shell forms its obligations name unless its refusal names other forms. +/// The forms declaring an effect obligation, which only effect statements count for. +fn effect_forms(files: &ResultsFiles) -> BTreeSet<&str> { + files + .obligations + .iter() + .filter(|obligation| obligation.kind == ObligationKind::Effect) + .map(|obligation| obligation.form.as_str()) + .collect() +} + +/// The forms each statement counts for: an uncredited one none, a refused one only for the forms its refusal names, a refused or differing one also for its shells when no other form it names takes it, any other for its forms other than shells, and a cited case also for the cited and shell forms its obligations name unless its refusal names other forms. pub(crate) fn link_all<'a>( statements: &'a [RecordedStatement], functions: &FunctionIndex, files: &ResultsFiles, ) -> Result, Vec> { let cited = cited_cases(files); + let shells = shell_forms(&files.links); + let effect_forms = effect_forms(files); let uncredited = uncredited_cases(&files.links); let mut links: Links = BTreeMap::new(); let mut unaccounted: BTreeMap> = BTreeMap::new(); @@ -129,6 +141,18 @@ pub(crate) fn link_all<'a>( (false, StatementOutcome::Differs) => linked.carried, (false, _) => linked.credited, }; + let counts = + |form: &String| statement.effect.is_some() || !effect_forms.contains(form.as_str()); + if (refused || statement.outcome == StatementOutcome::Differs) && !forms.iter().any(counts) + { + forms.extend( + linked + .forms + .iter() + .filter(|form| shells.contains(form.as_str())) + .cloned(), + ); + } if uncredited.contains_key(statement.reference.as_str()) { forms.clear(); } else if !refused || linked.whole_refusal { @@ -166,12 +190,7 @@ pub(crate) fn form_results( ) -> Result, Vec> { let mut unmet: BTreeMap<&str, Vec> = BTreeMap::new(); let mut declared: BTreeSet<&str> = BTreeSet::new(); - let effect_forms: BTreeSet<&str> = files - .obligations - .iter() - .filter(|obligation| obligation.kind == ObligationKind::Effect) - .map(|obligation| obligation.form.as_str()) - .collect(); + let effect_forms = effect_forms(files); for obligation in files .obligations .iter() diff --git a/tools/sqlbabel-coverage-check/src/results/tests/test_obligations.rs b/tools/sqlbabel-coverage-check/src/results/tests/test_obligations.rs index f017c8b76..410f7fc02 100644 --- a/tools/sqlbabel-coverage-check/src/results/tests/test_obligations.rs +++ b/tools/sqlbabel-coverage-check/src/results/tests/test_obligations.rs @@ -882,6 +882,9 @@ fn given_a_shell_link_when_measuring_then_only_its_cited_cases_credit_it_and_no_ const IDENTIFIER: &[&str] = &["spelling:identifier"]; const WITH_SELECT: &[&str] = &["spelling:identifier", "node:select"]; const WITH_COLUMN: &[&str] = &["spelling:identifier", "node:column"]; + const COUNT_IF_EFFECT: &str = "[[obligation]]\nid = \"sf.functions.count-if.t001\"\n\ + form = \"sf.functions.count-if\"\nkind = \"effect\"\ntarget = \"no input\"\nnote = \"n\"\n\ + catches = \"c\"\nreading = \"r\"\ncases = []\nrequired = false\nreason = \"r\"\n"; let cited = iff_obligation(1, "t001"); let test_cases = [ ShellLinkTestCase { @@ -960,6 +963,24 @@ fn given_a_shell_link_when_measuring_then_only_its_cited_cases_credit_it_and_no_ expected_state: Some(ResultState::Matching), expected_problem: "", }, + ShellLinkTestCase { + description: "a refusal naming a form the statement does not use, of a statement linking no other form, refuses it too", + links: "", + obligations: cited.clone(), + cited: (Matching, &[]), + other: (Refused, IDENTIFIER, &["node:select"]), + expected_state: Some(ResultState::Refused), + expected_problem: "", + }, + ShellLinkTestCase { + description: "a query statement that differs, whose only other form takes only effect statements, counts against it", + links: "", + obligations: cited.clone() + COUNT_IF_EFFECT, + cited: (Matching, &[]), + other: (Differs, &["spelling:identifier", "fn:COUNT_IF"], &[]), + expected_state: Some(ResultState::Differs), + expected_problem: "", + }, ShellLinkTestCase { description: "its only cited case refused whole: it does not match", links: "",