diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-10-13 05:34:54 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-10-13 05:34:54 +0000 |
commit | b8d423e7d13686d6627571d6c4adf12661d82147 (patch) | |
tree | 11d64ff26fb53c3c01ee35d062ca0c51fb883550 /qa/test_commits.py | |
parent | Adding upstream version 0.15.1. (diff) | |
download | gitlint-7f9eae8e5939f911ce10870f5e2caaae6d546b7f.tar.xz gitlint-7f9eae8e5939f911ce10870f5e2caaae6d546b7f.zip |
Adding upstream version 0.16.0.upstream/0.16.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'qa/test_commits.py')
-rw-r--r-- | qa/test_commits.py | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/qa/test_commits.py b/qa/test_commits.py index 389ad66..92e1087 100644 --- a/qa/test_commits.py +++ b/qa/test_commits.py @@ -40,19 +40,60 @@ class CommitsTests(BaseTestCase): expected_kwargs = {'commit_sha1': commit_sha1, 'commit_sha2': commit_sha2} self.assertEqualStdout(output, self.get_expected("test_commits/test_violations_1", expected_kwargs)) + def test_lint_empty_commit_range(self): + """ Tests `gitlint --commits <sha>^...<sha>` --fail-without-commits where the provided range is empty. """ + self.create_simple_commit("Sïmple title.\n") + self.create_simple_commit("Sïmple title2.\n") + commit_sha = self.get_last_commit_hash() + # git revspec -> 2 dots: <exclusive sha>..<inclusive sha> -> empty range when using same start and end sha + refspec = f"{commit_sha}..{commit_sha}" + + # Regular gitlint invocation should run without issues + output = gitlint("--commits", refspec, _cwd=self.tmp_git_repo, _tty_in=True) + self.assertEqual(output.exit_code, 0) + self.assertEqualStdout(output, "") + + # Gitlint should fail when --fail-without-commits is used + output = gitlint("--commits", refspec, "--fail-without-commits", _cwd=self.tmp_git_repo, _tty_in=True, + _ok_code=[self.GITLINT_USAGE_ERROR]) + self.assertEqual(output.exit_code, self.GITLINT_USAGE_ERROR) + self.assertEqualStdout(output, f"Error: No commits in range \"{refspec}\"\n") + def test_lint_single_commit(self): - """ Tests `gitlint --commits <sha>` """ + """ Tests `gitlint --commits <sha>^...<same sha>` """ self.create_simple_commit("Sïmple title.\n") + first_commit_sha = self.get_last_commit_hash() self.create_simple_commit("Sïmple title2.\n") commit_sha = self.get_last_commit_hash() refspec = f"{commit_sha}^...{commit_sha}" self.create_simple_commit("Sïmple title3.\n") - output = gitlint("--commits", refspec, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2]) + expected = ("1: T3 Title has trailing punctuation (.): \"Sïmple title2.\"\n" + "3: B6 Body message is missing\n") + + # Lint using --commit <commit sha> + output = gitlint("--commit", commit_sha, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2]) self.assertEqual(output.exit_code, 2) self.assertEqualStdout(output, expected) + # Lint a single commit using --commits <refspec> pointing to the single commit + output = gitlint("--commits", refspec, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2]) + self.assertEqual(output.exit_code, 2) + self.assertEqualStdout(output, expected) + + # Lint the first commit in the repository. This is a use-case that is not supported by --commits + # As <sha>^...<sha> is not correct refspec in case <sha> points to the initial commit (which has no parents) + expected = ("1: T3 Title has trailing punctuation (.): \"Sïmple title.\"\n" + + "3: B6 Body message is missing\n") + output = gitlint("--commit", first_commit_sha, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[2]) + self.assertEqual(output.exit_code, 2) + self.assertEqualStdout(output, expected) + + # Assert that indeed --commits <refspec> is not supported when <refspec> points the the first commit + refspec = f"{first_commit_sha}^...{first_commit_sha}" + output = gitlint("--commits", refspec, _cwd=self.tmp_git_repo, _tty_in=True, _ok_code=[254]) + self.assertEqual(output.exit_code, 254) + def test_lint_staged_stdin(self): """ Tests linting a staged commit. Gitint should lint the passed commit message andfetch additional meta-data from the underlying repository. The easiest way to test this is by inspecting `--debug` output. @@ -139,7 +180,7 @@ class CommitsTests(BaseTestCase): self.assertEqualStdout(output, self.get_expected("test_commits/test_lint_head_1", expected_kwargs)) def test_ignore_commits(self): - """ Tests multiple commits of which some rules get igonored because of ignore-* rules """ + """ Tests multiple commits of which some rules get ignored because of ignore-* rules """ # Create repo and some commits tmp_git_repo = self.create_tmp_git_repo() self.create_simple_commit("Sïmple title.\n\nSimple bödy describing the commit", git_repo=tmp_git_repo) |