diff options
Diffstat (limited to 'qa')
-rw-r--r-- | qa/expected/test_user_defined/test_user_defined_rules_examples_2 | 4 | ||||
-rw-r--r-- | qa/expected/test_user_defined/test_user_defined_rules_extra_1 | 3 | ||||
-rw-r--r-- | qa/samples/user_rules/extra/extra_rules.py | 28 | ||||
-rw-r--r-- | qa/test_user_defined.py | 14 |
4 files changed, 41 insertions, 8 deletions
diff --git a/qa/expected/test_user_defined/test_user_defined_rules_examples_2 b/qa/expected/test_user_defined/test_user_defined_rules_examples_2 new file mode 100644 index 0000000..31a9280 --- /dev/null +++ b/qa/expected/test_user_defined/test_user_defined_rules_examples_2 @@ -0,0 +1,4 @@ +1: UC2 Body does not contain a 'Signed-Off-By' line +1: UC3 Branch name 'master' does not start with one of ['feature/', 'hotfix/', 'release/'] +1: UL1 Title contains the special character '$' +2: B4 Second line is not empty diff --git a/qa/expected/test_user_defined/test_user_defined_rules_extra_1 b/qa/expected/test_user_defined/test_user_defined_rules_extra_1 index 65f3507..8e769f4 100644 --- a/qa/expected/test_user_defined/test_user_defined_rules_extra_1 +++ b/qa/expected/test_user_defined/test_user_defined_rules_extra_1 @@ -2,4 +2,5 @@ 1: UC1 GitContext.current_branch: master 1: UC1 GitContext.commentchar: # 1: UC2 GitCommit.branches: ['master'] -2: B4 Second line is not empty: "Content on the second line" +1: UC2 GitCommit.custom_prop: foöbar +4: B2 Line has trailing whitespace: "{repo-path} " diff --git a/qa/samples/user_rules/extra/extra_rules.py b/qa/samples/user_rules/extra/extra_rules.py index 8109299..aeda1ae 100644 --- a/qa/samples/user_rules/extra/extra_rules.py +++ b/qa/samples/user_rules/extra/extra_rules.py @@ -1,4 +1,6 @@ -from gitlint.rules import CommitRule, RuleViolation +# -*- coding: utf-8 -*- + +from gitlint.rules import CommitRule, RuleViolation, ConfigurationRule from gitlint.utils import sstr @@ -9,8 +11,8 @@ class GitContextRule(CommitRule): def validate(self, commit): violations = [ - RuleViolation(self.id, "GitContext.current_branch: {0}".format(commit.context.current_branch), line_nr=1), - RuleViolation(self.id, "GitContext.commentchar: {0}".format(commit.context.commentchar), line_nr=1) + RuleViolation(self.id, u"GitContext.current_branch: {0}".format(commit.context.current_branch), line_nr=1), + RuleViolation(self.id, u"GitContext.commentchar: {0}".format(commit.context.commentchar), line_nr=1) ] return violations @@ -23,7 +25,25 @@ class GitCommitRule(CommitRule): def validate(self, commit): violations = [ - RuleViolation(self.id, "GitCommit.branches: {0}".format(sstr(commit.branches)), line_nr=1), + RuleViolation(self.id, u"GitCommit.branches: {0}".format(sstr(commit.branches)), line_nr=1), + RuleViolation(self.id, u"GitCommit.custom_prop: {0}".format(commit.custom_prop), line_nr=1), ] return violations + + +class GitlintConfigurationRule(ConfigurationRule): + """ Rule that tests whether we can correctly access the config as well as modify the commit message """ + name = "gitcommit" + id = "UC3" + + def apply(self, config, commit): + # We add a line to the commit message body that pulls a value from config, this proves we can modify the body + # and read the config contents + commit.message.body.append("{0} ".format(config.target)) # trailing whitespace deliberate to trigger violation + + # We set a custom property that we access in CommitRule, to prove we can add extra properties to the commit + commit.custom_prop = u"foöbar" + + # We also ignore some extra rules, proving that we can modify the config + config.ignore.append("B4") diff --git a/qa/test_user_defined.py b/qa/test_user_defined.py index cf7effd..9153c2a 100644 --- a/qa/test_user_defined.py +++ b/qa/test_user_defined.py @@ -7,13 +7,20 @@ from qa.base import BaseTestCase class UserDefinedRuleTests(BaseTestCase): """ Integration tests for user-defined rules.""" - def test_user_defined_rules_examples(self): + def test_user_defined_rules_examples1(self): extra_path = self.get_example_path() commit_msg = u"WIP: Thi$ is å title\nContent on the second line" self.create_simple_commit(commit_msg) output = gitlint("--extra-path", extra_path, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[5]) self.assertEqualStdout(output, self.get_expected("test_user_defined/test_user_defined_rules_examples_1")) + def test_user_defined_rules_examples2(self): + extra_path = self.get_example_path() + commit_msg = u"Release: Thi$ is å title\nContent on the second line\n$This line is ignored \nThis isn't\t\n" + self.create_simple_commit(commit_msg) + output = gitlint("--extra-path", extra_path, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[4]) + self.assertEqualStdout(output, self.get_expected("test_user_defined/test_user_defined_rules_examples_2")) + def test_user_defined_rules_examples_with_config(self): extra_path = self.get_example_path() commit_msg = u"WIP: Thi$ is å title\nContent on the second line" @@ -27,8 +34,9 @@ class UserDefinedRuleTests(BaseTestCase): extra_path = self.get_sample_path("user_rules/extra") commit_msg = u"WIP: Thi$ is å title\nContent on the second line" self.create_simple_commit(commit_msg) - output = gitlint("--extra-path", extra_path, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[5]) - self.assertEqualStdout(output, self.get_expected("test_user_defined/test_user_defined_rules_extra_1")) + output = gitlint("--extra-path", extra_path, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[6]) + self.assertEqualStdout(output, self.get_expected("test_user_defined/test_user_defined_rules_extra_1", + {'repo-path': self.tmp_git_repo})) def test_invalid_user_defined_rules(self): extra_path = self.get_sample_path("user_rules/incorrect_linerule") |