Skip to content

Commit 73a480a

Browse files
albertocerroneLee-W
authored andcommitted
test: check if the diff is excluded from message
1 parent 3c7d67d commit 73a480a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/commands/test_check_command.py

+31
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,34 @@ def test_check_command_with_comment_in_messege_file(mocker, capsys):
349349
cli.main()
350350
out, _ = capsys.readouterr()
351351
assert "Commit validation: successful!" in out
352+
353+
354+
def test_check_conventional_commit_succeed_with_git_diff(mocker, capsys):
355+
commit_msg = (
356+
"feat: This is a test commit\n"
357+
"# Please enter the commit message for your changes. Lines starting\n"
358+
"# with '#' will be ignored, and an empty message aborts the commit.\n"
359+
"#\n"
360+
"# On branch ...\n"
361+
"# Changes to be committed:\n"
362+
"# modified: ...\n"
363+
"#\n"
364+
"# ------------------------ >8 ------------------------\n"
365+
"# Do not modify or remove the line above.\n"
366+
"# Everything below it will be ignored.\n"
367+
"diff --git a/... b/...\n"
368+
"index f1234c..1c5678 1234\n"
369+
"--- a/...\n"
370+
"+++ b/...\n"
371+
"@@ -92,3 +92,4 @@ class Command(BaseCommand):\n"
372+
'+ "this is a test"\n'
373+
)
374+
testargs = ["cz", "check", "--commit-msg-file", "some_file"]
375+
mocker.patch.object(sys, "argv", testargs)
376+
mocker.patch(
377+
"commitizen.commands.check.open",
378+
mocker.mock_open(read_data=commit_msg),
379+
)
380+
cli.main()
381+
out, _ = capsys.readouterr()
382+
assert "Commit validation: successful!" in out

0 commit comments

Comments
 (0)