Skip to content

Commit 16dfe06

Browse files
committed
Add tests for el-get-compute-new-status
1 parent df6e6ce commit 16dfe06

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)
@@ -232,3 +242,105 @@ John.Doe-123_@example.com"))
232242
(lambda (package url)
233243
(error "Leave 'el-get-insecure-check to git"))))
234244
(should (el-get-do-update "dummy")))))
245+
246+
(defun el-get-test-compute-new-status-equal (status1 status2)
247+
"Check equality for `el-get-compute-new-status' results."
248+
(and (el-get-plist-equal (nth 0 status1) (nth 0 status2))
249+
(equal (nth 1 status1) (nth 1 status2))
250+
(el-get-plist-equal (nth 2 status1) (nth 2 status2))
251+
(el-get-plist-equal (nth 3 status1) (nth 3 status2))))
252+
253+
(ert-deftest el-get-test-compute-new-status ()
254+
"Test `el-get-compute-new-status'."
255+
(let* ((old '(:name a
256+
:type git
257+
:load-path "load-old"
258+
:depends (depends old)
259+
:build (("build" "old"))
260+
:build/gnu-linux (("build/gnu-linux" "old"))
261+
:url "http://example.com/url/old"))
262+
(new '(:name a
263+
:type git
264+
:load-path "load-new"
265+
:depends (depends new)
266+
:build (("build" "new"))
267+
:build/gnu-linux (("build/gnu-linux" "new"))
268+
:url "http://example.com/url/new"))
269+
(expected '((:name a
270+
:type git
271+
:load-path "load-new"
272+
:depends (depends old)
273+
:build (("build" "old"))
274+
:build/gnu-linux (("build/gnu-linux" "old"))
275+
:url "http://example.com/url/old")
276+
(reinstall)
277+
(:depends (depends new)
278+
:build (("build new"))
279+
:build/gnu-linux (("build/gnu-linux" "new"))
280+
:url "http://example.com/url/new")
281+
(:depends (depends old)
282+
:build (("build old"))
283+
:build/gnu-linux (("build/gnu-linux" "old"))
284+
:url "http://example.com/url/old")))
285+
(update-expected '((:name a
286+
:type git
287+
:load-path "load-new"
288+
:depends (depends new)
289+
:build (("build" "new"))
290+
:build/gnu-linux (("build/gnu-linux" "new"))
291+
:url "http://example.com/url/old")
292+
(reinstall)
293+
(:url "http://example.com/url/new")
294+
(:url "http://example.com/url/old"))))
295+
(should (el-get-test-compute-new-status-equal
296+
(el-get-compute-new-status 'init old new)
297+
expected))
298+
(should (el-get-test-compute-new-status-equal
299+
(el-get-compute-new-status 'update old new)
300+
update-expected))
301+
(should (el-get-test-compute-new-status-equal
302+
(el-get-compute-new-status 'reinstall old new)
303+
(list new nil nil nil)))))
304+
305+
(ert-deftest el-get-test-compute-new-status-2 ()
306+
"Test `el-get-compute-new-status'."
307+
(let* ((old '(:name a
308+
:type git
309+
:load-path "load-old"
310+
:depends (depends old)
311+
:build (("build" "old"))
312+
:build/gnu-linux (("build/gnu-linux" "old"))
313+
:url "http://example.com/url/old"))
314+
(new '(:name a
315+
:type git
316+
:load-path "load-new"
317+
:depends (depends new)
318+
:build (("build" "new"))
319+
:build/gnu-linux (("build/gnu-linux" "new"))
320+
:url "http://example.com/url/old"))
321+
(init-result (el-get-compute-new-status 'init old new))
322+
(init-expected '((:name a
323+
:type git
324+
:load-path "load-new"
325+
:depends (depends old)
326+
:build (("build" "old"))
327+
:build/gnu-linux (("build/gnu-linux" "old"))
328+
:url "http://example.com/url/old")
329+
(update reinstall)
330+
(:depends (depends new)
331+
:build (("build new"))
332+
:build/gnu-linux (("build/gnu-linux" "new")))
333+
(:depends (depends old)
334+
:build (("build old"))
335+
:build/gnu-linux (("build/gnu-linux" "old")))))
336+
(update-result (el-get-compute-new-status 'update old new))
337+
(update-expected '((:name a
338+
:type git
339+
:load-path "load-new"
340+
:depends (depends new)
341+
:build (("build" "new"))
342+
:build/gnu-linux (("build/gnu-linux" "new"))
343+
:url "http://example.com/url/old")
344+
nil nil nil)))
345+
(should (el-get-test-compute-new-status-equal init-result init-expected))
346+
(should (el-get-test-compute-new-status-equal update-result update-expected))))

0 commit comments

Comments
 (0)