From c3882ec4b977c9a2698d147888c212051e72716a Mon Sep 17 00:00:00 2001 From: IEncinas10 Date: Thu, 6 Jul 2023 18:23:47 +0200 Subject: [PATCH] AutoFix tests: default to first violation with fix 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. --- common/analysis/linter_test_utils.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/common/analysis/linter_test_utils.h b/common/analysis/linter_test_utils.h index be204d071..9c2a6d6d6 100644 --- a/common/analysis/linter_test_utils.h +++ b/common/analysis/linter_test_utils.h @@ -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;