This repository has been archived by the owner on Sep 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlish-test.lisp
295 lines (270 loc) · 11.1 KB
/
lish-test.lisp
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
;;
;; lish-test.lisp - Tests for Lish
;;
;; @@@ These are so woefully incomplete.
(defpackage :lish-test
(:documentation "Tests for Lish")
(:use :cl :test :lish :dlib)
(:export
#:run
))
(in-package :lish-test)
(declaim (optimize (speed 0) (safety 3) (debug 3) (space 0)
(compilation-speed 0)))
(defun sort-of-equal (a b)
"Like equalp, but ignoring symbol package differences."
(typecase a
(list
(return-from sort-of-equal
(not
(loop :for aa :in a :for bb :in b
:unless (sort-of-equal aa bb)
:return t))))
(symbol
(and (symbolp b)
(equal (symbol-name a) (symbol-name b))))
(t
(equalp a b))))
(defun vuvu (str l-args)
(let ((aa (command-to-lisp-args (command-arglist (get-command str)))))
(format t "~w ~{~w ~}~%~w~%~%" str (command-arglist (get-command str)) aa)
(sort-of-equal aa l-args)))
;; You probably have to say: (with-package :lish (test-stla))
;; Unfortunately this may fail if not updated to reflect builtin changes.
#| I changed it so everything is keywords!!!
(deftests (shell-to-lisp-args-1 :doc "Test COMMAND-TO-LISP-ARGS.")
(vuvu "cd" '(&optional directory))
(vuvu "pwd" '())
(vuvu "pushd" '(&optional directory))
(vuvu "popd" '(&optional number))
(vuvu "dirs" '())
(vuvu "suspend" '())
(vuvu "history" '(&key clear write read append read-not-read filename
show-times delete))
;; (vuvu ":" '(&rest args))
(vuvu "echo" '(&key no-newline args))
(vuvu "help" '(&optional subject))
(vuvu "alias" '(&key global edit name expansion))
(vuvu "unalias" '(name))
(vuvu "exit" '(&rest values))
(vuvu "source" '(filename))
(vuvu "debug" '(&optional (state :toggle)))
(vuvu "export" '(&key remove name value))
(vuvu "jobs" '(&key long))
(vuvu "kill" '(&key list-signals (signal "term") pids))
;; (vuvu "format" '(format-string &rest args))
;; (vuvu "read" '(&key name prompt timeout editing))
(vuvu "time" '(&rest command))
(vuvu "times" '())
(vuvu "umask" '(&key print-command symbolic mask))
(vuvu "ulimit" '())
(vuvu "wait" '())
(vuvu "exec" '(&rest command-words))
(vuvu "bind" '(&key print-bindings print-readable-bindings query
remove-function-bindings remove-key-binding key-sequence
function-name))
(vuvu "hash" '(&key rehash packages commands))
(vuvu "type" '(&key type-only path-only all names))
;; (format t "SUCCEED!~%")
)
|#
(deftests (shell-to-lisp-args-1 :doc "Test COMMAND-TO-LISP-ARGS.")
(vuvu "cd" '(&key directory))
(vuvu "pwd" '())
(vuvu "pushd" '(&key directory))
(vuvu "popd" '(&key number))
(vuvu "dirs" '())
(vuvu "suspend" '())
(vuvu "history" '(&key clear write read append read-not-read filename
show-times delete))
;; (vuvu ":" '(&rest args))
(vuvu "echo" '(&key no-newline args))
(vuvu "help" '(&key subject))
(vuvu "alias" '(&key global edit name expansion))
(vuvu "unalias" '(&key name))
(vuvu "exit" '(&key values))
(vuvu "source" '(&key filename))
(vuvu "debug" '(&key (state :toggle state-supplied-p)))
(vuvu "export" '(&key remove edit name value))
(vuvu "jobs" '(&key long all))
(vuvu "kill" '(&key list-signals interactive (signal "term") pids))
;; (vuvu "format" '(format-string &rest args))
;; (vuvu "read" '(&key name prompt timeout editing))
(vuvu "time" '(&key command))
(vuvu "times" '())
(vuvu "umask" '(&key print-command symbolic mask))
(vuvu "ulimit" '())
(vuvu "wait" '())
(vuvu "exec" '(&key command-words))
(vuvu "bind" '(&key print-bindings print-readable-bindings query
remove-function-bindings remove-key-binding key-sequence
function-name))
(vuvu "hash" '(&key rehash packages commands))
(vuvu "type" '(&key type-only path-only all names))
;; (format t "SUCCEED!~%")
)
(defun o-vivi (str &rest args)
(format t "~w ~{~w ~}~%~w~%~%" str args
(posix-to-lisp-args (get-command str) args)))
(defun vivi (str p-args l-args)
(let ((aa (posix-to-lisp-args
(get-command str)
;; (lish::expr-to-words (lish:shell-read p-args)))))
(lish::shell-expr-words (lish:shell-read p-args)))))
;;(format t "~w ~{~w ~}~%~w~%~%" str p-args aa)
(format t "~w ~w~%~w~%~%" str p-args aa)
(equalp aa l-args)))
(defcommand tata
(("one" boolean :short-arg #\1)
("two" string :short-arg #\2))
"Test argument conversion."
(format t "one = ~s two = ~s~%" one two))
(defcommand gurp
(("pattern" string :optional nil)
("files" pathname :repeating t)
("invert" boolean :short-arg #\i))
"Test argument conversion."
(format t "pattern = ~s files = ~s invert = ~s~%" pattern files invert))
(defcommand zurp
(("section" string :short-arg #\s)
("entry" string :optional t))
"Test argument conversion."
(format t "entry = ~s section = ~s~%" entry section))
(defcommand clop
((from string :repeating t #| :optional nil |#)
(to string :optional nil))
"Test argument conversion."
(format t "from = ~s to = ~a~%" from to))
(defcommand snerp
((from string :repeating t :optional nil)
(to string :optional nil))
"Test argument conversion."
(format t "from = ~s to = ~a~%" from to))
(deftests (posix-to-lisp-args-1 :doc "Test POSIX-TO-LISP-ARGS.")
;; (vivi ":" '() '())
;; (vivi ":"
;; '("(format t \"egg~a~%\" (lisp-implementation-type))")
;; '("(format t \"egg~a~%\" (lisp-implementation-type))"))
;; (vivi ":"
;; '("blah" "blah" "blah" "etc" "...")
;; '("blah" "blah" "blah" "etc" "..."))
;; This was before adding the -g option:
;; (vivi "alias" '("name") '("name"))
;; (vivi "alias" '("name" "expansion") '("name" "expansion"))
;; (vivi "alias"
;; '("name" "expansion" "extra" "junk")
;; '("name" "expansion"))
(vivi "alias" "" '(:expansion nil))
(vivi "alias" "name" '(:name "name":expansion nil))
(vivi "alias" "name expansion" '(:name "name" :expansion ("expansion")))
(vivi "alias"
"name expansion extra junk"
'(:name "name" :expansion ("expansion" "extra" "junk")))
(vivi "bind" "" '())
(vivi "bind" "-p" '(:print-bindings t))
(vivi "bind" "-P" '(:print-readable-bindings t))
(vivi "bind" "-r foo" '(:remove-key-binding "foo"))
(vivi "cd" "" '())
(vivi "cd" "dir" '(:directory "dir"))
(vivi "debug" "" '(:state :toggle))
(vivi "debug" "on" '(:state t))
(vivi "debug" "off" '(:state nil))
;; This is supposed to fail, since pecan isn't a boolean
; (vivi "debug" '("pecan") '())
(vivi "gurp" "-i foo bar baz lemon"
'(:pattern "foo" :files ("bar" "baz" "lemon") :invert t))
(vivi "zurp" "-s 3 chflags" '(:entry "chflags" :section "3"))
(vivi "clop" "foo the bar mmkay" '(:from ("foo" "the" "bar") :to "mmkay"))
(vivi "clop" "foo bar" '(:from ("foo") :to "bar"))
(vivi "clop" "zurpy" '(:to "zurpy"))
(vivi "snerp" "foo the bar mmkay" '(:from ("foo" "the" "bar") :to "mmkay"))
(vivi "snerp" "foo bar" '(:from ("foo") :to "bar"))
;; This should get a: "Missing mandatory agrument: to" error
;; (vivi "snerp" "zurpy"
;; '(:to "zurpy"))
)
;(with-dbug (lish::posix-to-lisp-args (lish::get-command "bind") '("-r" "foo")))
;(with-dbug (lish::posix-to-lisp-args (lish::get-command "find") '("--name" "txt$")))
;; @@@ This is an internal-ish way to test. Once we finish, we should test it
;; through a more external interface. Or perhaps this suggests that an external
;; interface to these would be useful.
(deftests (expand-variables-1 :doc "Test variable expansion")
:setup
(progn
(setf (nos:environment-variable "bar") nil
(nos:environment-variable "foo") "Yow$a!"))
:takedown
(setf (nos:environment-variable "foo") nil)
(equal (lish::expand-variables "") "")
(equal (lish::expand-variables "foo") "foo")
(equal (lish::expand-variables "foo\\$bar") "foo\\$bar")
(equal (lish::expand-variables "foobar\\") "foobar\\")
(equal (lish::expand-variables "\\foo\\bar\\") "\\foo\\bar\\")
(equal (lish::expand-variables "\\foo\\$bar\\") "\\foo\\$bar\\")
(equal (lish::expand-variables "\\$foobar\\$") "\\$foobar\\$")
(equal (lish::expand-variables "foo$bar") "foo")
(equal (lish::expand-variables "$bar") "")
(equal (lish::expand-variables "foo$bar.baz") "foo.baz")
(equal (lish::expand-variables "foo$bar_baz") "foo")
(equal (lish::expand-variables "foo$bar_baz.zeep") "foo.zeep")
(equal (lish::expand-variables "$foo") "Yow$a!")
(equal (lish::expand-variables "-$foo-") "-Yow$a!-")
(equal (lish::expand-variables "\\$foo") "\\$foo")
(equal (lish::expand-variables "-$foo$bar-") "-Yow$a!-")
(equal (lish::expand-variables "$}") "$}")
)
(deftests (expand-braces-1 :doc "Test brace expansion")
(equal (lish::expand-braces "hi") '("hi"))
(equal (lish::expand-braces "hi there") '("hi there"))
(equal (lish::expand-braces "fooba{r,z}") '("foobar" "foobaz"))
(equal (lish::expand-braces "foo{bar,baz}") '("foobar" "foobaz"))
(equal (lish::expand-braces "{f,g,l}oobar{1,2,3}")
'("foobar1" "foobar2" "foobar3" "goobar1" "goobar2" "goobar3" "loobar1"
"loobar2" "loobar3"))
(equal (lish::expand-braces "foo{b,f}a{r,z}")
'("foobar" "foobaz" "foofar" "foofaz"))
(equal (lish::expand-braces "foo{ba{r,t},ga}") '("foobar" "foobat" "fooga"))
(equal (lish::expand-braces "{foo,bar}") '("foo" "bar"))
(equal (lish::expand-braces "{a,b,c}") '("a" "b" "c"))
"Malformed expressions"
(equal (lish::expand-braces "}") '("}"))
(equal (lish::expand-braces "{") '("{"))
(equal (lish::expand-braces "{}") '("{}"))
(equal (lish::expand-braces "{ }") '("{ }"))
(equal (lish::expand-braces "{foo}") '("{foo}"))
(equal (lish::expand-braces "fooba{r,z") '("fooba{r,z"))
(equal (lish::expand-braces "foobar,z") '("foobar,z"))
"Escaping"
(equal (lish::expand-braces "fooba{r\\,z}") '("fooba{r\\,z}"))
(equal (lish::expand-braces "_\\{a,b,c}_") '("_\\{a,b,c}_"))
(equal (lish::expand-braces "\\_{a,b,c}_") '("\\_a_" "\\_b_" "\\_c_"))
(equal (lish::expand-braces "\\{a,b,c,d,e}") '("\\{a,b,c,d,e}"))
(equal (lish::expand-braces "{foo,bar,\\{it's,the,blimp}}")
'("foo}" "bar}" "\\{it's}" "the}" "blimp}"))
(equal (lish::expand-braces "{foo\\,bar,\\{zerp\\},quux}")
'("foo\\,bar" "\\{zerp\\}" "quux"))
)
(deftests (expand-brace-sequences-1 :doc "Test brace sequence expansion")
(equal (lish::expand-braces "{1..5}") '("1" "2" "3" "4" "5"))
(equal (lish::expand-braces "{1..10}")
'("1" "2" "3" "4" "5" "6" "7" "8" "9" "10"))
(equal (lish::expand-braces "{01..10}")
'("01" "02" "03" "04" "05" "06" "07" "08" "09"
"10"))
(equal (lish::expand-braces "{1..10..2}") '("1" "3" "5" "7" "9"))
(equal (lish::expand-braces "{1..010..2}") '("001" "003" "005" "007" "009"))
(equal (lish::expand-braces "{01..110..10}")
'("001" "011" "021" "031" "041" "051" "061" "071" "081" "091" "101"))
(equal (lish::expand-braces "{-5..5}")
'("-5" "-4" "-3" "-2" "-1" "0" "1" "2" "3" "4" "5"))
(equal (lish::expand-braces "{-20..20..5}")
'("-20" "-15" "-10" "-5" "0" "5" "10" "15" "20"))
)
(deftests (lish-all :doc "Test all the things!.")
shell-to-lisp-args-1 posix-to-lisp-args-1 expand-variables-1 expand-braces-1
expand-brace-sequences-1
;; expand-brace-sequences-2 expand-brace-sequences-3
)
(defun run ()
(run-group-name 'lish-all :verbose t))
;; EOF