File: git-auto-commit-mode-tests.el

package info (click to toggle)
git-auto-commit-mode 4.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 136 kB
  • sloc: lisp: 284; makefile: 2
file content (146 lines) | stat: -rw-r--r-- 5,191 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
;;; git-auto-commit-mode-tests.el --- Tests for git-auto-commit-mode  -*- lexical-binding: t; -*-

;; Copyright (C) 2019  Tom Willemse

;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords:

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;;

;;; Code:

(require 'buttercup)
(require 'git-auto-commit-mode)

(describe "In a git repository"
  :var (temp-dir current-directory)

  (before-each
    (setq temp-dir (make-temp-file "gac-" t)
          current-directory default-directory
          default-directory temp-dir)
    (shell-command "git init")
    (shell-command "git config user.email user@example.com")
    (shell-command "git config user.name \"User Example\""))

  (after-each
    (delete-directory temp-dir t)
    (setq temp-dir nil
          default-directory current-directory
          current-directory nil))

  (describe "New files"
    (describe "When ‘gac-automatically-add-new-files’ is t"
      (it "Should be added to git"
        (let* ((gac-automatically-add-new-files-p t)
               (temp-file (expand-file-name "test" 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-match (rx string-start "test" string-end)))))

    (describe "When ‘gac-automatically-add-new-files’ is nil"
      (it "Shouldn’t be added to git"
        (let* ((gac-automatically-add-new-files-p nil)
               (temp-file (expand-file-name "test" 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")
                  :not :to-match (rx string-start "test" string-end))))))

  (describe "Getting a relative path"
    (it "should return the file name for files in the project root"
      (let* ((temp-file (expand-file-name "test" temp-dir))
             (buffer (find-file-noselect temp-file)))
        (with-current-buffer buffer
          (git-auto-commit-mode)
          (insert "test")
          (save-buffer))

        (expect (gac-relative-file-name temp-file)
                :to-equal "test")))

    (it "should return the file name and directory name for nested files"
      (mkdir (expand-file-name "test" temp-dir))

      (let* ((temp-file (expand-file-name "test/test.txt" temp-dir))
             (buffer (find-file-noselect temp-file)))
        (with-current-buffer buffer
          (git-auto-commit-mode)
          (insert "test")
          (save-buffer))

        (expect (gac-relative-file-name temp-file)
                :to-equal "test/test.txt")))

    (it "should handle ‘[]’ in the filename"
      (let* ((temp-file (expand-file-name "[test]-test.txt" temp-dir))
             (buffer (find-file-noselect temp-file)))
        (with-current-buffer buffer
          (git-auto-commit-mode)
          (insert "test")
          (save-buffer))

        (expect (gac-relative-file-name temp-file)
                :to-equal "[test]-test.txt")))

    (it "should handle ‘[]’ in the directory name"
      (mkdir (expand-file-name "[test]-test" temp-dir))

      (let* ((temp-file (expand-file-name "[test]-test/testing.txt" temp-dir))
             (buffer (find-file-noselect temp-file)))
        (with-current-buffer buffer
          (git-auto-commit-mode)
          (insert "test")
          (save-buffer))

        (expect (gac-relative-file-name temp-file)
                :to-equal "[test]-test/testing.txt")))

    (it "should handle ‘[’ in the directory name"
      (let* ((temp-file (expand-file-name "testing.txt" temp-dir))
             (buffer (find-file-noselect temp-file)))
        (with-current-buffer buffer
          (git-auto-commit-mode)
          (insert "test")
          (save-buffer))

        (expect (gac-relative-file-name temp-file)
                :to-equal "testing.txt")))

    (it "should handle ‘[’ in the file name"
      (let* ((temp-file (expand-file-name "[test-test.txt" temp-dir))
             (buffer (find-file-noselect temp-file)))
        (with-current-buffer buffer
          (git-auto-commit-mode)
          (insert "test")
          (save-buffer))

        (expect (gac-relative-file-name temp-file)
                :to-equal "[test-test.txt")))))

(provide 'git-auto-commit-mode-tests)
;;; git-auto-commit-mode-tests.el ends here