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 Aug 2, 2023
1 parent b8c2d7d commit 939c478
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions common/analysis/linter_test_utils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2020 The Verible Authors.
// Copyright 2017-2023 The Verible Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -131,10 +131,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 939c478

Please sign in to comment.