forked from babashka/neil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
neil-tests.el
103 lines (92 loc) · 4.26 KB
/
neil-tests.el
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
;;; neil-tests.el --- tests for neil.el -*- lexical-binding: t; -*-
;;
;; Copyright (c) 2021 Michiel Borkent
;;
;; Author: Ag Ibragimov <[email protected]>
;; Maintainer: Ag Ibragimov <[email protected]>
;; Created: May, 2022
;; Modified: May, 2022
;; Version: 0.0.1
;; Keywords: convenience tools
;; Homepage: https://github.com/babashka/neil
;; Package-Requires: ((emacs "27.1"))
;;
;;; Commentary:
;;
;; Description
;;
;;; Code:
(require 'buttercup)
(require 'neil)
(describe "neil-find-clojure-package, no neil"
(it "throws error when neil cmd-line executable not found"
(spy-on #'executable-find :and-return-value nil)
(expect (funcall #'neil-find-clojure-package "foo") :to-throw 'error)))
(describe "neil-find-clojure-package, happy path"
:var (prompt-calls shell-cmd-calls)
(before-each
(setq prompt-calls 0
shell-cmd-calls 0
neil-inject-dep-to-project-p nil)
(spy-on #'executable-find :and-return-value "/bin/neil")
(spy-on #'shell-command-to-string
:and-call-fake
(lambda (command)
;; shell-command-to-string may get called multiple times, first to search
;; for packages, second time to get versions of a selected package,
;; arguments and the results differ every time
(setf shell-cmd-calls (1+ shell-cmd-calls))
(cond
((eq shell-cmd-calls 1)
(expect command :to-equal "/bin/neil dep search test-pkg")
(concat
":lib foo/test-pkg :version 1.0.0 :description \"good lib\"\n"
":lib bar/awesome-test-pkg :version 2.1.0 :description \"better lib\"\n"))
((eq shell-cmd-calls 2)
(expect command :to-equal "/bin/neil dep versions foo/test-pkg")
(concat
":lib foo/test-pkg :version 1.0.0\n"
":lib bar/awesome-test-pkg :version 2.1.0\n")))))
(spy-on #'neil-search-annotation-fn)
(spy-on #'completing-read
:and-call-fake
(lambda (prompt coll)
;; `neil-find-clojure-package' pops up completion prompt multiple times,
;; first to select from candidates matching the search term, second time, it
;; prompts for a version of the package - but only if
;; `neil-prompt-for-version-p' is not nil
(setf prompt-calls (1+ prompt-calls))
(cond
((eq prompt-calls 1)
(expect prompt :to-equal "Found 2 matches for 'test-pkg':")
(expect coll :to-equal
'(("foo/test-pkg" (version . "1.0.0") (description . "\"good lib\""))
("bar/awesome-test-pkg" (version . "2.1.0") (description . "\"better lib\""))))
"foo/test-pkg")
((eq prompt-calls 2)
;; TODO: figure out how to assert the sorted order of completion candidates
(expect prompt :to-equal "Choose version of foo/test-pkg:")
"1.0.0")))))
(it "shouldn't throw 'executable not found' error"
(expect (neil-find-clojure-package "test-pkg") :not :to-throw))
(it "for clojure-cli, without version prompt"
(spy-on #'neil--identify-project-build-tool :and-return-value '(clojure-cli))
(let ((neil-prompt-for-version-p nil))
(expect (neil-find-clojure-package "test-pkg") :to-equal
"foo/test-pkg {:mvn/version \"1.0.0\"}")))
(it "for clojure-cli, with version prompt"
(spy-on #'neil--identify-project-build-tool :and-return-value '(clojure-cli))
(let ((neil-prompt-for-version-p t))
(expect (neil-find-clojure-package "test-pkg") :to-equal
"foo/test-pkg {:mvn/version \"1.0.0\"}")))
(it "for lein, without version prompt"
(spy-on #'neil--identify-project-build-tool :and-return-value '(lein))
(let ((neil-prompt-for-version-p nil))
(expect (neil-find-clojure-package "test-pkg") :to-equal
"[foo/test-pkg \"1.0.0\"]")))
(it "for lein, with version prompt"
(spy-on #'neil--identify-project-build-tool :and-return-value '(lein))
(let ((neil-prompt-for-version-p t))
(expect (neil-find-clojure-package "test-pkg") :to-equal
"[foo/test-pkg \"1.0.0\"]"))))
;;; neil-tests.el ends here