Skip to content

Commit 2d600e1

Browse files
committed
Add tests for el-get-compute-new-status
1 parent 5259c31 commit 2d600e1

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

test/el-get-tests.el

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
(defmacro* ert-deftest (name () &body docstring-keys-and-body)
88
(message "Skipping tests, ERT is not available"))))
99

10+
(defun el-get-plist-equal (plist1 plist2)
11+
(let ((keys (el-get-plist-keys plist1)))
12+
(and (equal (sort keys #'string<)
13+
(sort (el-get-plist-keys plist2) #'string<))
14+
(loop for key in keys
15+
unless (equal (plist-get plist1 key)
16+
(plist-get plist2 key))
17+
return nil
18+
finally return t))))
19+
1020
(defvar el-get-test-output-buffer nil)
1121
(when noninteractive
1222
(defadvice message (around el-get-test-catch-output activate)
@@ -215,3 +225,105 @@ John.Doe-123_@example.com"))
215225
(lambda (package url)
216226
(error "Leave 'el-get-insecure-check to git"))))
217227
(should (el-get-do-update "dummy")))))
228+
229+
(defun el-get-test-compute-new-status-equal (status1 status2)
230+
"Check equality for `el-get-compute-new-status' results."
231+
(and (el-get-plist-equal (nth 0 status1) (nth 0 status2))
232+
(equal (nth 1 status1) (nth 1 status2))
233+
(el-get-plist-equal (nth 2 status1) (nth 2 status2))
234+
(el-get-plist-equal (nth 3 status1) (nth 3 status2))))
235+
236+
(ert-deftest el-get-test-compute-new-status ()
237+
"Test `el-get-compute-new-status'."
238+
(let* ((old '(:name a
239+
:type git
240+
:load-path "load-old"
241+
:depends (depends old)
242+
:build (("build" "old"))
243+
:build/gnu-linux (("build/gnu-linux" "old"))
244+
:url "http://example.com/url/old"))
245+
(new '(:name a
246+
:type git
247+
:load-path "load-new"
248+
:depends (depends new)
249+
:build (("build" "new"))
250+
:build/gnu-linux (("build/gnu-linux" "new"))
251+
:url "http://example.com/url/new"))
252+
(expected '((:name a
253+
:type git
254+
:load-path "load-new"
255+
:depends (depends old)
256+
:build (("build" "old"))
257+
:build/gnu-linux (("build/gnu-linux" "old"))
258+
:url "http://example.com/url/old")
259+
(reinstall)
260+
(:depends (depends new)
261+
:build (("build new"))
262+
:build/gnu-linux (("build/gnu-linux" "new"))
263+
:url "http://example.com/url/new")
264+
(:depends (depends old)
265+
:build (("build old"))
266+
:build/gnu-linux (("build/gnu-linux" "old"))
267+
:url "http://example.com/url/old")))
268+
(update-expected '((:name a
269+
:type git
270+
:load-path "load-new"
271+
:depends (depends new)
272+
:build (("build" "new"))
273+
:build/gnu-linux (("build/gnu-linux" "new"))
274+
:url "http://example.com/url/old")
275+
(reinstall)
276+
(:url "http://example.com/url/new")
277+
(:url "http://example.com/url/old"))))
278+
(should (el-get-test-compute-new-status-equal
279+
(el-get-compute-new-status 'init old new)
280+
expected))
281+
(should (el-get-test-compute-new-status-equal
282+
(el-get-compute-new-status 'update old new)
283+
update-expected))
284+
(should (el-get-test-compute-new-status-equal
285+
(el-get-compute-new-status 'reinstall old new)
286+
(list new nil nil nil)))))
287+
288+
(ert-deftest el-get-test-compute-new-status-2 ()
289+
"Test `el-get-compute-new-status'."
290+
(let* ((old '(:name a
291+
:type git
292+
:load-path "load-old"
293+
:depends (depends old)
294+
:build (("build" "old"))
295+
:build/gnu-linux (("build/gnu-linux" "old"))
296+
:url "http://example.com/url/old"))
297+
(new '(:name a
298+
:type git
299+
:load-path "load-new"
300+
:depends (depends new)
301+
:build (("build" "new"))
302+
:build/gnu-linux (("build/gnu-linux" "new"))
303+
:url "http://example.com/url/old"))
304+
(init-result (el-get-compute-new-status 'init old new))
305+
(init-expected '((:name a
306+
:type git
307+
:load-path "load-new"
308+
:depends (depends old)
309+
:build (("build" "old"))
310+
:build/gnu-linux (("build/gnu-linux" "old"))
311+
:url "http://example.com/url/old")
312+
(update reinstall)
313+
(:depends (depends new)
314+
:build (("build new"))
315+
:build/gnu-linux (("build/gnu-linux" "new")))
316+
(:depends (depends old)
317+
:build (("build old"))
318+
:build/gnu-linux (("build/gnu-linux" "old")))))
319+
(update-result (el-get-compute-new-status 'update old new))
320+
(update-expected '((:name a
321+
:type git
322+
:load-path "load-new"
323+
:depends (depends new)
324+
:build (("build" "new"))
325+
:build/gnu-linux (("build/gnu-linux" "new"))
326+
:url "http://example.com/url/old")
327+
nil nil nil)))
328+
(should (el-get-test-compute-new-status-equal init-result init-expected))
329+
(should (el-get-test-compute-new-status-equal update-result update-expected))))

0 commit comments

Comments
 (0)