diff --git a/common/analysis/linter_test_utils.h b/common/analysis/linter_test_utils.h index f0b3431b3..76031c97e 100644 --- a/common/analysis/linter_test_utils.h +++ b/common/analysis/linter_test_utils.h @@ -115,6 +115,8 @@ void RunLintTestCases(std::initializer_list tests, } struct AutoFixInOut { + static constexpr int NO_FIX_AVAILABLE = -1; + absl::string_view code; absl::string_view expected_output; int fix_alternative = 0; // Some rules provide alternative fixes @@ -139,6 +141,12 @@ void RunLintAutoFixCase(const AutoFixInOut &test, CHECK_GT(violations.size(), test.violation_number); const LintViolation &violation = *std::next(violations.begin(), test.violation_number); + + if (test.fix_alternative == AutoFixInOut::NO_FIX_AVAILABLE) { + CHECK_EQ(violation.autofixes.size(), 0); + return; + } + 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());