diff --git a/tests/Lint/main.cpp b/tests/Lint/main.cpp index 8db7f3b..556b540 100644 --- a/tests/Lint/main.cpp +++ b/tests/Lint/main.cpp @@ -629,7 +629,9 @@ int main() { Scratch s("ast"); s.Write("f", Source); Configuration cfg = s.Config({"f"}); - cfg.AddAstLintRule("ast", [](LintContext& ctx) { + bool ran = false; + cfg.AddAstLintRule("ast", [&ran](LintContext& ctx) { + ran = true; Check(ctx.AstAvailable(), std::format("ast: parse succeeded ({})", ctx.AstUnavailableReason())); std::span decls = ctx.Decls(); Check(!decls.empty(), "ast: declarations found"); @@ -688,7 +690,13 @@ int main() { Check(std::string_view(ctx.content).substr(count->begin, count->end - count->begin) == "int count", "ast: extent brackets exactly the declaration"); } }); - RunLint(cfg, Mode(LintMode::Report)); + const LintSummary summary = RunLint(cfg, Mode(LintMode::Report)); + // The driver runs a rule that reads the AST only on a file it could + // parse, so when the parse fails every check above goes untried and + // the run's error is all that is left to see. In crafter-build's + // Flatpak this file's was not found, and the case passed + // (issue #46). + Check(ran && summary.errors == 0, "ast: the rule ran on the parsed file (why not is on stderr)"); } // A module interface unit. libclang reports `export namespace X { … }` as a @@ -710,7 +718,9 @@ int main() { std::array ifaces = { "Demo" }; std::array impls = {}; cfg.GetInterfacesAndImplementations(ifaces, impls); - cfg.AddAstLintRule("ast-module", [](LintContext& ctx) { + bool ran = false; + cfg.AddAstLintRule("ast-module", [&ran](LintContext& ctx) { + ran = true; Check(ctx.AstAvailable(), std::format("ast-module: parse succeeded ({})", ctx.AstUnavailableReason())); std::span decls = ctx.Decls(); auto find = [&](LintDeclKind kind, std::string_view name) -> const LintDecl* { @@ -732,7 +742,9 @@ int main() { Check(count != nullptr && count->line == 18, "ast-module: field line matches"); Check(exported != nullptr && exported->line == 20, "ast-module: exported variable line matches"); }); - RunLint(cfg, Mode(LintMode::Report)); + const LintSummary summary = RunLint(cfg, Mode(LintMode::Report)); + // As in the case above: the checks only count if the rule ran. + Check(ran && summary.errors == 0, "ast-module: the rule ran on the parsed file (why not is on stderr)"); } // An unavailable AST must fail the run, never look like a clean file. A