Skip to content

Commit

Permalink
Add tests for rule aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
wsipak committed Sep 17, 2021
1 parent 965bad2 commit 493b714
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
13 changes: 13 additions & 0 deletions verilog/analysis/lint_rule_registry_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,25 @@ class TextRule1 : public TextStructureLintRule {
};

VERILOG_REGISTER_LINT_RULE(TextRule1);
VERILOG_ALIAS_LINT_RULE(TextRule1, "alias-text-rule1", "alias-text-rule2");

// Verifies that a known text-structure-based rule is registered.
TEST(LintRuleRegistryTest, ContainsTextRuleTrue) {
EXPECT_TRUE(IsRegisteredLintRule("text-rule-1"));
}

// Verifies that the alias can be translated to a registered rule name.
TEST(LintRuleRegistryTest, CanBeAliasedTrue) {
EXPECT_TRUE(IsRegisteredLintRule(TranslateAliasIfExists("alias-text-rule1")));
EXPECT_TRUE(IsRegisteredLintRule(TranslateAliasIfExists("alias-text-rule2")));
}

// Verifies that an invalid alias doesn't translate to a registered rule name
TEST(LintRuleRegistryTest, TranslateInvalidAlias) {
EXPECT_FALSE(IsRegisteredLintRule(
TranslateAliasIfExists("invalid-alias")));
}

// Verifies that a nonexistent text-structure-based rule yields a nullptr.
TEST(LintRuleRegistryTest, CreateTextLintRuleInvalid) {
EXPECT_EQ(CreateTextStructureLintRule("invalid-id"), nullptr);
Expand Down
25 changes: 25 additions & 0 deletions verilog/analysis/verilog_linter_configuration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ VERILOG_REGISTER_LINT_RULE(TestRule2);
VERILOG_REGISTER_LINT_RULE(TestRule3);
VERILOG_REGISTER_LINT_RULE(TestRule4);
VERILOG_REGISTER_LINT_RULE(TestRule5);
VERILOG_ALIAS_LINT_RULE(TestRule1, "test-rule-1-alias", "test-rule-1-alias2");

// Dummy text structure with a single empty root node for syntax tree.
class FakeTextStructureView : public TextStructureView {
Expand Down Expand Up @@ -654,6 +655,30 @@ TEST(RuleBundleTest, ParseRuleBundleEmpty) {
EXPECT_TRUE(bundle.rules.empty());
}

TEST(RuleBundleTest, ParseRuleWithAlias) {
auto text = "+test-rule-1-alias";
RuleBundle bundle;
std::string error;
bool success = bundle.ParseConfiguration(text, ',', &error);
ASSERT_TRUE(success) << error;
ASSERT_THAT(bundle.rules, SizeIs(1));
EXPECT_TRUE(error.empty());

EXPECT_TRUE(bundle.rules["test-rule-1"].enabled);
}

TEST(RuleBundleTest, ParseRuleWithAliases) {
auto text = "+test-rule-1,-test-rule-1-alias,+test-rule-1-alias2";
RuleBundle bundle;
std::string error;
bool success = bundle.ParseConfiguration(text, ',', &error);
ASSERT_TRUE(success) << error;
ASSERT_THAT(bundle.rules, SizeIs(1));
EXPECT_TRUE(error.empty());
EXPECT_TRUE(bundle.rules["test-rule-1"].enabled);
EXPECT_TRUE(bundle.rules["test-rule-1"].configuration.empty());
}

TEST(RuleBundleTest, ParseRuleBundleAcceptSeveral) {
// Allow for an optional '+' to enable a rule for symmetry with '-' disable
std::string text = "test-rule-1,test-rule-2,+test-rule-3";
Expand Down

0 comments on commit 493b714

Please sign in to comment.