Skip to content

Commit

Permalink
Add tests for el-get-compute-new-status
Browse files Browse the repository at this point in the history
  • Loading branch information
npostavs committed Aug 7, 2016
1 parent e8c6cbb commit c43737f
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions test/el-get-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@
(defmacro* ert-deftest (name () &body docstring-keys-and-body)
(message "Skipping tests, ERT is not available"))))

(defun el-get-plist-equal (plist1 plist2)
(let ((keys (el-get-plist-keys plist1)))
(and (equal (sort keys #'string<)
(sort (el-get-plist-keys plist2) #'string<))
(loop for key in keys
unless (equal (plist-get plist1 key)
(plist-get plist2 key))
return nil
finally return t))))

(defvar el-get-test-output-buffer nil)
(when noninteractive
(defadvice message (around el-get-test-catch-output activate)
Expand Down Expand Up @@ -125,3 +135,105 @@ Following variables are bound to temporal values:
(should-not (featurep pkg))
(el-get 'sync (mapcar 'el-get-source-name el-get-sources))
(should (featurep pkg)))))

(defun el-get-test-compute-new-status-equal (status1 status2)
"Check equality for `el-get-compute-new-status' results."
(and (el-get-plist-equal (nth 0 status1) (nth 0 status2))
(equal (nth 1 status1) (nth 1 status2))
(el-get-plist-equal (nth 2 status1) (nth 2 status2))
(el-get-plist-equal (nth 3 status1) (nth 3 status2))))

(ert-deftest el-get-test-compute-new-status ()
"Test `el-get-compute-new-status'."
(let* ((old '(:name a
:type git
:load-path "load-old"
:depends (depends old)
:build (("build" "old"))
:build/gnu-linux (("build/gnu-linux" "old"))
:url "http://example.com/url/old"))
(new '(:name a
:type git
:load-path "load-new"
:depends (depends new)
:build (("build" "new"))
:build/gnu-linux (("build/gnu-linux" "new"))
:url "http://example.com/url/new"))
(expected '((:name a
:type git
:load-path "load-new"
:depends (depends old)
:build (("build" "old"))
:build/gnu-linux (("build/gnu-linux" "old"))
:url "http://example.com/url/old")
(reinstall)
(:depends (depends new)
:build (("build new"))
:build/gnu-linux (("build/gnu-linux" "new"))
:url "http://example.com/url/new")
(:depends (depends old)
:build (("build old"))
:build/gnu-linux (("build/gnu-linux" "old"))
:url "http://example.com/url/old")))
(update-expected '((:name a
:type git
:load-path "load-new"
:depends (depends new)
:build (("build" "new"))
:build/gnu-linux (("build/gnu-linux" "new"))
:url "http://example.com/url/old")
(reinstall)
(:url "http://example.com/url/new")
(:url "http://example.com/url/old"))))
(should (el-get-test-compute-new-status-equal
(el-get-compute-new-status 'init old new)
expected))
(should (el-get-test-compute-new-status-equal
(el-get-compute-new-status 'update old new)
update-expected))
(should (el-get-test-compute-new-status-equal
(el-get-compute-new-status 'reinstall old new)
(list new nil nil nil)))))

(ert-deftest el-get-test-compute-new-status-2 ()
"Test `el-get-compute-new-status'."
(let* ((old '(:name a
:type git
:load-path "load-old"
:depends (depends old)
:build (("build" "old"))
:build/gnu-linux (("build/gnu-linux" "old"))
:url "http://example.com/url/old"))
(new '(:name a
:type git
:load-path "load-new"
:depends (depends new)
:build (("build" "new"))
:build/gnu-linux (("build/gnu-linux" "new"))
:url "http://example.com/url/old"))
(init-result (el-get-compute-new-status 'init old new))
(init-expected '((:name a
:type git
:load-path "load-new"
:depends (depends old)
:build (("build" "old"))
:build/gnu-linux (("build/gnu-linux" "old"))
:url "http://example.com/url/old")
(update reinstall)
(:depends (depends new)
:build (("build new"))
:build/gnu-linux (("build/gnu-linux" "new")))
(:depends (depends old)
:build (("build old"))
:build/gnu-linux (("build/gnu-linux" "old")))))
(update-result (el-get-compute-new-status 'update old new))
(update-expected '((:name a
:type git
:load-path "load-new"
:depends (depends new)
:build (("build" "new"))
:build/gnu-linux (("build/gnu-linux" "new"))
:url "http://example.com/url/old")
nil nil nil)))
(should (el-get-test-compute-new-status-equal init-result init-expected))
(should (el-get-test-compute-new-status-equal update-result update-expected))))

0 comments on commit c43737f

Please sign in to comment.