Skip to content

Commit

Permalink
AutoFix tests: default to first violation with fix
Browse files Browse the repository at this point in the history
Previously, whenever we encountered a test when there were more than
one violation, we failed.

This commits changes it so that we default to the first violation
that has an available autofix.
  • Loading branch information
IEncinas10 committed May 12, 2024
1 parent b76667d commit 007a79d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions common/analysis/linter_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,18 @@ void RunLintAutoFixCase(const AutoFixInOut &test,
const LintRuleStatus rule_status = lint_runner.Run(analyzer.Data(), "");
const auto &violations(rule_status.violations);

CHECK_EQ(violations.size(), 1) << "TODO: apply multi-violation fixes";
CHECK_GT(violations.begin()->autofixes.size(), test.fix_alternative);
const verible::AutoFix &fix =
rule_status.violations.begin()->autofixes[test.fix_alternative];
// Default to first violation with available autofix
const auto itr =
std::find_if(begin(violations), end(violations),
[](const LintViolation &v) { return v.autofixes.size(); });
EXPECT_TRUE(itr != end(violations))
<< "There must be at least one violation with an available autofix";

const LintViolation &violation = *itr;

// Extract selected fix
CHECK_GT(violation.autofixes.size(), test.fix_alternative);
const verible::AutoFix &fix = violation.autofixes[test.fix_alternative];
std::string fix_out = fix.Apply(analyzer.Data().Contents());

EXPECT_EQ(test.expected_output, fix_out) << "For input " << test.code;
Expand Down

0 comments on commit 007a79d

Please sign in to comment.