-
Notifications
You must be signed in to change notification settings - Fork 2
/
keg-tests.el
196 lines (170 loc) · 6.69 KB
/
keg-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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
;;; keg-tests.el --- Test definitions for keg -*- lexical-binding: t; -*-
;; Copyright (C) 2019 Naoya Yamashita
;; Author: Naoya Yamashita <conao3@gmail.com>
;; URL: https://github.com/conao3/keg.el
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Test definitions for `keg'.
;;; Code:
(require 'cort)
(require 'keg)
(defsubst keg-tests--string-trim-right (string &optional regexp)
"Trim STRING of trailing string matching REGEXP.
REGEXP defaults to \"[ \\t\\n\\r]+\"."
(let ((i (string-match-p (concat "\\(?:" (or regexp "[ \t\n\r]+") "\\)\\'")
string)))
(if i (substring string 0 i) string)))
(defmacro cort-deftest-with-shell-command (name form)
"Return `cort-deftest' compare with `string=' for NAME, FORM.
(cort-deftest-with-shell-command keg/subcommand-help
'((\"keg version\"
\"Keg 0.0.1 running on Emacs 26.3\")
(\"keg files\"
\"keg-ansi.el\\nkeg-mode.el\\nkeg.el\")))
=> (cort-deftest keg/subcommand-help
'((:string= \"Keg 0.0.1 running on Emacs 26.3\"
(string-trim-right
(shell-command-to-string \"keg version\")))
(:string= \"keg-ansi.el\\nkeg-mode.el\\nkeg.el\"
(string-trim-right
(shell-command-to-string \"keg files\")))))"
(declare (indent 1))
`(cort-deftest ,name
',(apply #'nconc
(mapcar (lambda (elm)
(mapcar
(lambda (regexp)
`(:string-match-p
,regexp
(keg-tests--string-trim-right (shell-command-to-string ,(car elm)))))
(cdr elm)))
(cadr form)))))
(cort-deftest-with-shell-command keg/subcommand-simple
'(("./bin/keg version"
"Keg [0-9.]+ running on Emacs [0-9.]+")
("./bin/keg help"
"USAGE: keg \\[SUBCOMMAND\\] \\[OPTIONS\\.\\.\\.\\]$"
"^ build \\[PACKAGE\\]$"
"^ clean$"
"^ clean-elc \\[PACKAGE\\]$"
"^ debug$"
"^ files \\[PACKAGE\\]$"
"^ emacs \\[ARGS\\.\\.\\.\\]$"
"^ eval \\[SEXP\\]$"
"^ exec COMMAND \\[ARGS\\.\\.\\.\\]$"
"^ files \\[PACKAGE\\]$"
"^ help$"
"^ info \\[PACKAGE\\]$"
"^ init$"
"^ install \\[PACKAGES\\.\\.\\.\\]$"
"^ lint \\[PACKAGE\\]$"
"^ `?load-path'?$" ; Symbol is automatically quoted on Emacs 24.5>=.
"^ run \\[SCRIPT\\]$"
"^ version$")))
(cort-deftest-generate keg/ansi-cl-macrolet :macroexpand
'(
;; With 1 argument
((keg-ansi--cl-macrolet
((macro-1-arg (arg1) `(let ((x 1)) ,arg1)))
(macro-1-arg x))
(let ((x 1)) x))
((keg-ansi--cl-macrolet
((macro-1-arg (arg1) (message "Expand") `(let ((x 1)) ,arg1)))
(macro-1-arg x))
(let ((x 1)) x))
;;With &rest arguments
((keg-ansi--cl-macrolet
((macro-&rest-args (arg1 &rest args) `(let ((x 1)) ,arg1 ,@args)))
(macro-&rest-args x 1 (2 3) 4))
(let ((x 1)) x 1 (2 3) 4))
((keg-ansi--cl-macrolet
((macro-&rest-args (arg1 &rest args) (message "Expand") `(let ((x 1)) ,arg1 ,@args)))
(macro-&rest-args x 1 (2 3) 4))
(let ((x 1)) x 1 (2 3) 4))
((keg-ansi--cl-macrolet
((macro-&rest-args (arg1 &rest args) `(let ((x 1)) ,arg1 ,@args)))
(macro-&rest-args x [1] (2 3) 4))
(let ((x 1)) x [1] (2 3) 4))
((keg-ansi--cl-macrolet
((macro-&rest-args (arg1 &rest args) (message "Expand") `(let ((x 1)) ,arg1 ,@args)))
(macro-&rest-args x [1] (2 3) 4))
(let ((x 1)) x [1] (2 3) 4))
;; With 1 &optional argument
((keg-ansi--cl-macrolet
((macro-1-optional-arg (arg1 &optional arg2) `(let ((x 1)) ,arg1 ,arg2)))
(macro-1-optional-arg x))
(let ((x 1)) x nil))
((keg-ansi--cl-macrolet
((macro-1-optional-arg (arg1 &optional arg2) `(let ((x 1)) ,arg1 ,arg2)))
(macro-1-optional-arg x 1))
(let ((x 1)) x 1))
;; With 2 &optional arguments
((keg-ansi--cl-macrolet
((macro-2-optional-args (arg1 &optional arg2 arg3) `(let ((x 1)) ,arg1 ,arg2 ,arg3)))
(macro-2-optional-args x))
(let ((x 1)) x nil nil))
((keg-ansi--cl-macrolet
((macro-2-optional-args (arg1 &optional arg2 arg3) `(let ((x 1)) ,arg1 ,arg2 ,arg3)))
(macro-2-optional-args x 2))
(let ((x 1)) x 2 nil))
((keg-ansi--cl-macrolet
((macro-2-optional-args (arg1 &optional arg2 arg3) `(let ((x 1)) ,arg1 ,arg2 ,arg3)))
(macro-2-optional-args x 2 3))
(let ((x 1)) x 2 3))
;; With multiple bindings
((keg-ansi--cl-macrolet
((macro-1-arg (arg1) `(let ((x 1)) ,arg1))
(macro-&rest-args (arg1 &rest args) `(let ((x 1)) ,arg1 ,@args)))
(macro-1-arg x)
(macro-&rest-args x 1 2))
(progn
(let ((x 1)) x)
(let ((x 1)) x 1 2)))))
(cort-deftest-generate keg/with-keg-ansi :string=
'(((with-keg-ansi
(red "foo"))
(keg-ansi 'red "foo"))
((with-keg-ansi
(blue "foo"))
(keg-ansi 'blue "foo"))
((with-keg-ansi
(red "foo")
(blue "bar"))
(concat (keg-ansi 'red "foo")
(keg-ansi 'blue "bar")))
((with-keg-ansi
(red "foo")
(blue "bar")
(green "baz"))
(concat (keg-ansi 'red "foo")
(keg-ansi 'blue "bar")
(keg-ansi 'green "baz")))))
(cort-deftest-generate keg/build--package-archives :equal
'(((keg-build--package-archives
'(gnu))
'(("gnu" . "https://elpa.gnu.org/packages/")))
((keg-build--package-archives
'((gnu . "http://elpa.zilongshanren.com/gnu/")))
'(("gnu" . "http://elpa.zilongshanren.com/gnu/")))
((keg-build--package-archives
'("http://elpa.zilongshanren.com/gnu/"))
'(("http://elpa.zilongshanren.com/gnu/" . "http://elpa.zilongshanren.com/gnu/")))
((keg-build--package-archives
'((gnu . "http://elpa.zilongshanren.com/gnu/")
(melpa . "http://elpa.zilongshanren.com/melpa/")))
'(("gnu" . "http://elpa.zilongshanren.com/gnu/")
("melpa" . "http://elpa.zilongshanren.com/melpa/")))))
;; (provide 'keg-tests)
;; Local Variables:
;; indent-tabs-mode: nil
;; End:
;;; keg-tests.el ends here