aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKévin Le Gouguec2025-02-13 23:52:06 +0100
committerKévin Le Gouguec2025-02-17 21:47:14 +0100
commit15d2fc6498db433131bd4364aae1d508a12bd925 (patch)
tree921cbfba31324c6f9ba8749379203c1ca354181b
parent53a5dada413662389a17c551a00d215e51f5049f (diff)
downloademacs-15d2fc6498db433131bd4364aae1d508a12bd925.tar.gz
emacs-15d2fc6498db433131bd4364aae1d508a12bd925.zip
Test vc-git-dir-extra-headers directly (bug#76187)
* test/lisp/vc/vc-git-tests.el (vc-git-test--run): Make sure to log output from failing Git commands. (vc-git-test--dir-headers): Stop bothering with vc-dir internals and just invoke the branch-munging and header-formatting code we mean to test. (vc-git-test-dir-branch-headers): Stop invoking vc-dir; just set default-directory to be able to pass it to the backend function.
-rw-r--r--test/lisp/vc/vc-git-tests.el122
1 files changed, 63 insertions, 59 deletions
diff --git a/test/lisp/vc/vc-git-tests.el b/test/lisp/vc/vc-git-tests.el
index 4b5cb75df01..3cb12d5f86e 100644
--- a/test/lisp/vc/vc-git-tests.el
+++ b/test/lisp/vc/vc-git-tests.el
@@ -104,9 +104,14 @@ allow `git commit' to determine identities for authors and committers."
104 ,@body))) 104 ,@body)))
105 105
106(defun vc-git-test--run (&rest args) 106(defun vc-git-test--run (&rest args)
107 "Run git ARGS…, check for non-zero status, and return output." 107 "Run git ARGS…, check for non-zero status, and return output.
108If the exit status is non-zero, log the command output and re-throw."
108 (with-temp-buffer 109 (with-temp-buffer
109 (apply 'vc-git-command t 0 nil args) 110 (condition-case err
111 (apply 'vc-git-command t 0 nil args)
112 (t (message "Error running Git: %s" err)
113 (message "(buffer-string:\n%s\n)" (buffer-string))
114 (signal (car err) (cdr err))))
110 (buffer-string))) 115 (buffer-string)))
111 116
112(defun vc-git-test--start-branch () 117(defun vc-git-test--start-branch ()
@@ -120,31 +125,30 @@ agnostic of init.defaultbranch."
120 (string-trim (vc-git-test--run "branch" "--show-current"))) 125 (string-trim (vc-git-test--run "branch" "--show-current")))
121 126
122(defun vc-git-test--dir-headers (headers) 127(defun vc-git-test--dir-headers (headers)
123 "Return an alist of header values for the current `vc-dir' buffer. 128 "Return an alist of header values as they would appear in `vc-dir'.
124
125HEADERS should be a list of (NAME ...) strings. This function will 129HEADERS should be a list of (NAME ...) strings. This function will
126return a list of (NAME . VALUE) pairs, where VALUE is nil if the header 130return a list of (NAME . VALUE) pairs, where VALUE is nil if the header
127is absent." 131is absent."
128 ;; FIXME: to reproduce interactive sessions faithfully, we would need 132 (with-temp-buffer
129 ;; to wait for the dir-status-files process to terminate; have not 133 ;; We invoke the backend's dir-extra-headers function directly
130 ;; found a reliable way to do this. As a workaround, kill pending 134 ;; because (a) that covers the logic we mean to test (b) going
131 ;; processes and revert the `vc-dir' buffer. 135 ;; through vc-dir "like a user would" has proven fraught; see
132 (vc-dir-kill-dir-status-process) 136 ;; bug#76187 for hard-to-reproduce and hard-to-diagnose errors.
133 (revert-buffer) 137 (insert (vc-git-dir-extra-headers default-directory) "\n")
134 (mapcar 138 (mapcar
135 (lambda (header) 139 (lambda (header)
136 (let* ((pattern 140 (let* ((pattern
137 (rx bol 141 (rx bol
138 (literal header) (* space) ": " (group (+ nonl)) 142 (literal header) (* space) ": " (group (+ nonl))
139 eol)) 143 eol))
140 (value (and (goto-char (point-min)) 144 (value (and (goto-char (point-min))
141 (re-search-forward pattern nil t) 145 (re-search-forward pattern nil t)
142 (match-string 1)))) 146 (match-string 1))))
143 (cons header value))) 147 (cons header value)))
144 headers)) 148 headers)))
145 149
146(ert-deftest vc-git-test-dir-branch-headers () 150(ert-deftest vc-git-test-dir-branch-headers ()
147 "Check that `vc-dir' shows expected branch-related headers." 151 "Check that dir-extra-headers recognizes various branch arrangements."
148 (skip-unless (executable-find vc-git-program)) 152 (skip-unless (executable-find vc-git-program))
149 ;; Create a repository that will serve as the "remote". 153 ;; Create a repository that will serve as the "remote".
150 (vc-git-test--with-repo origin-repo 154 (vc-git-test--with-repo origin-repo
@@ -152,42 +156,42 @@ is absent."
152 ;; 'git clone' this repository and test things in this clone. 156 ;; 'git clone' this repository and test things in this clone.
153 (ert-with-temp-directory clone-repo 157 (ert-with-temp-directory clone-repo
154 (vc-git-test--run "clone" origin-repo clone-repo) 158 (vc-git-test--run "clone" origin-repo clone-repo)
155 (vc-dir clone-repo) 159 (let ((default-directory clone-repo))
156 (should 160 (should
157 (equal 161 (equal
158 (vc-git-test--dir-headers 162 (vc-git-test--dir-headers
159 '("Branch" "Tracking" "Remote")) 163 '("Branch" "Tracking" "Remote"))
160 `(("Branch" . ,main-branch) 164 `(("Branch" . ,main-branch)
161 ("Tracking" . ,(concat "origin/" main-branch)) 165 ("Tracking" . ,(concat "origin/" main-branch))
162 ("Remote" . ,origin-repo)))) 166 ("Remote" . ,origin-repo))))
163 ;; Checkout a new branch: no tracking information. 167 ;; Checkout a new branch: no tracking information.
164 (vc-git-test--run "checkout" "-b" "feature/foo" main-branch) 168 (vc-git-test--run "checkout" "-b" "feature/foo" main-branch)
165 (should 169 (should
166 (equal 170 (equal
167 (vc-git-test--dir-headers 171 (vc-git-test--dir-headers
168 '("Branch" "Tracking" "Remote")) 172 '("Branch" "Tracking" "Remote"))
169 '(("Branch" . "feature/foo") 173 '(("Branch" . "feature/foo")
170 ("Tracking" . nil) 174 ("Tracking" . nil)
171 ("Remote" . nil)))) 175 ("Remote" . nil))))
172 ;; Push with '--set-upstream origin': tracking information 176 ;; Push with '--set-upstream origin': tracking information
173 ;; should be updated. 177 ;; should be updated.
174 (vc-git-test--run "push" "--set-upstream" "origin" "feature/foo") 178 (vc-git-test--run "push" "--set-upstream" "origin" "feature/foo")
175 (should 179 (should
176 (equal 180 (equal
177 (vc-git-test--dir-headers 181 (vc-git-test--dir-headers
178 '("Branch" "Tracking" "Remote")) 182 '("Branch" "Tracking" "Remote"))
179 `(("Branch" . "feature/foo") 183 `(("Branch" . "feature/foo")
180 ("Tracking" . "origin/feature/foo") 184 ("Tracking" . "origin/feature/foo")
181 ("Remote" . ,origin-repo)))) 185 ("Remote" . ,origin-repo))))
182 ;; Checkout a new branch tracking the _local_ main branch. 186 ;; Checkout a new branch tracking the _local_ main branch.
183 ;; Bug#68183. 187 ;; Bug#68183.
184 (vc-git-test--run "checkout" "-b" "feature/bar" "--track" main-branch) 188 (vc-git-test--run "checkout" "-b" "feature/bar" "--track" main-branch)
185 (should 189 (should
186 (equal 190 (equal
187 (vc-git-test--dir-headers 191 (vc-git-test--dir-headers
188 '("Branch" "Tracking" "Remote")) 192 '("Branch" "Tracking" "Remote"))
189 `(("Branch" . "feature/bar") 193 `(("Branch" . "feature/bar")
190 ("Tracking" . ,main-branch) 194 ("Tracking" . ,main-branch)
191 ("Remote" . "none (tracking local branch)")))))))) 195 ("Remote" . "none (tracking local branch)")))))))))
192 196
193;;; vc-git-tests.el ends here 197;;; vc-git-tests.el ends here