From 7b628c0ce0bde4e88a1b4558c1e2ebfcea801c36 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 7 Dec 2022 07:23:08 -0800 Subject: [PATCH] =?UTF-8?q?Add=20a=20few=20tests=20for=20the=20=E2=80=98ga?= =?UTF-8?q?c-default-message=E2=80=99=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/git-auto-commit-mode-tests.el | 40 ++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/git-auto-commit-mode-tests.el b/tests/git-auto-commit-mode-tests.el index ace9807..5ebb7b2 100644 --- a/tests/git-auto-commit-mode-tests.el +++ b/tests/git-auto-commit-mode-tests.el @@ -140,7 +140,45 @@ (save-buffer)) (expect (gac-relative-file-name temp-file) - :to-equal "[test-test.txt"))))) + :to-equal "[test-test.txt")))) + + (describe "Getting a commit message" + (it "should default to the relative file name" + (let* ((temp-file (expand-file-name "test.txt" temp-dir)) + (buffer (find-file-noselect temp-file))) + (with-current-buffer buffer + (git-auto-commit-mode) + (insert "test") + (save-buffer)) + + (expect (shell-command-to-string "git log --format=format:%s") + :to-equal "test.txt"))) + + (it "should use the message specified in ‘gac-default-message’" + (let* ((temp-file (expand-file-name "test.txt" temp-dir)) + (buffer (find-file-noselect temp-file)) + (gac-default-message "I made a commit!")) + (with-current-buffer buffer + (git-auto-commit-mode) + (insert "test") + (save-buffer)) + + (expect (shell-command-to-string "git log --format=format:%s") + :to-equal "I made a commit!"))) + + (it "should use the function result if ‘gac-default-message’ is a function" + (let* ((temp-file (expand-file-name "test.txt" temp-dir)) + (buffer (find-file-noselect temp-file)) + (gac-default-message + (lambda (f) + (concat "wip " (gac-relative-file-name f))))) + (with-current-buffer buffer + (git-auto-commit-mode) + (insert "test") + (save-buffer)) + + (expect (shell-command-to-string "git log --format=format:%s") + :to-equal "wip test.txt"))))) (provide 'git-auto-commit-mode-tests) ;;; git-auto-commit-mode-tests.el ends here