Coverage report: /home/ellis/comp/core/lib/cli/tests/pkg.lisp

KindCoveredAll%
expression09 0.0
branch00nil
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; cli/tests.lisp --- CLI Tests
2
 
3
 ;;
4
 
5
 ;;; Code:
6
 (defpackage :cli/tests
7
   (:use :cl :std :rt :cli :cli/shell :cli/progress :cli/spark :cli/repl :cli/ansi :cli/clap :cli/tools/sbcl :dat/sxp :obj/ast))
8
 
9
 (in-package :cli/tests)
10
 (defsuite :cli)
11
 (in-suite :cli)
12
 
13
 (deftest progress ()
14
   (flet ((%step () (cli/progress::update 1)))
15
     (let ((*progress-bar-enabled* t)
16
           (n 100))
17
       (with-progress-bar (n "TEST: # of steps = ~a" n)
18
         (dotimes (i n) (%step))))))
19
 
20
 (deftest spark ()
21
   (is (string= 
22
        (spark '(1 5 22 13 5))
23
        "▁▂█▅▂"))
24
   (is (string= 
25
        (spark '(5.5 20))
26
        "▁█"))
27
   (is (string=
28
        (spark '(1 2 3 4 100 5 10 20 50 300))
29
        "▁▁▁▁▃▁▁▁▂█"))
30
   (is (string=
31
        (spark '(1 50 100))
32
        "▁▄█"))
33
   (is (string=
34
        (spark '(2 4 8))
35
        "▁▃█"))
36
   (is (string=
37
        (spark '(1 2 3 4 5))
38
        "▁▂▄▆█"))
39
   (is (string=
40
        (spark '(0 30 55 80 33 150))
41
        "▁▂▃▄▂█"))
42
   ;; null
43
   (is (string=
44
        (spark '())
45
        ""))
46
   ;; singleton
47
   (is (string=
48
        (spark '(42))
49
        "▁"))
50
   ;; constant
51
   (is (string=
52
        (spark '(42 42))
53
        "▁▁"))
54
   ;; min/max
55
   (is (string=
56
        (spark '(0 30 55 80 33 150) :min -100)
57
        "▃▄▅▆▄█"))
58
   (is (string=
59
        (spark '(0 30 55 80 33 150) :max 50)
60
        "▁▅██▅█"))
61
   (is (string=
62
        (spark '(0 30 55 80 33 150) :min 30 :max 80)
63
        "▁▁▄█▁█"))
64
   ;; double-float, minus
65
   (is (string=
66
        (spark '(1.000000000005d0 0.000000000005d0 1.0d0))
67
        "█▁▇"))
68
   (is (string=
69
        (spark '(-1 0 -1))
70
        "▁█▁"))
71
   (is (string=
72
        (spark '(-1.000000000005d0 0.000000000005d0 -1.0d0))
73
        "▁█▁"))
74
   ;; *ticks*
75
   (let ((ternary '(-1 0 1 -1 1 0 0 -1 1 1 0)))
76
     (is (string=
77
          (spark ternary)
78
          "▁▄█▁█▄▄▁██▄"))
79
     (is (string=
80
          (let ((*ticks* #(#\_ #\- #\¯)))
81
            (spark ternary))
82
          "_-¯_¯--_¯¯-"))
83
     (is (string=
84
          (let ((*ticks* #(#\▄ #\⎯ #\▀)))
85
            (spark ternary))
86
          "▄⎯▀▄▀⎯⎯▄▀▀⎯"))
87
     (is (string=
88
          (let ((*ticks* #(#\E #\O)))
89
            (spark '(4 8 15 22 42) :key (lambda (n) (mod n 2))))
90
          "EEOEE")))
91
   ;; key
92
   (flet ((range (start end) (loop for i from start below end collect i))
93
          (fib (n) (loop for x = 0 then y
94
                         and y = 1 then (+ x y)
95
                         repeat n
96
                         finally (return x)))
97
          (fac (n) (labels ((rec (n acc) (if (<= n 1) acc (rec (1- n) (* n acc)))))
98
                     (rec n 1))))
99
     (is (string=
100
          (spark (range 0 51)
101
                 :key (lambda (x) (sin (* x pi 1/4))))
102
          "▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█"))
103
     (is (string=
104
          (spark (range 0 51)
105
                 :key (lambda (x) (cos (* x pi 1/4))))
106
          "█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄▂▁▂▄▆█▆▄"))
107
 
108
     (is (string=
109
          (spark (range 0 51)
110
                 :key (lambda (x) (abs (cis (* x pi 1/4)))))
111
          "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁"))
112
     
113
     (is (string=
114
          (spark (range 0 51)
115
                 :key (lambda (x) (float (phase (cis (* x pi 1/4))) 1.0)))
116
          "▄▅▆▇█▁▁▂▄▅▆▇█▁▁▂▄▅▆▇█▁▁▂▄▅▆▇█▁▁▂▄▅▆▇█▁▁▂▄▅▆▇█▁▁▂▄▅▆"))
117
 
118
     (is (string=
119
          (spark (range 1 7) :key #'log)   
120
          "▁▃▅▆▇█"))
121
 
122
     (is (string=
123
          (spark (range 1 7) :key #'sqrt)  
124
          "▁▃▄▅▆█"))
125
     (is (string=
126
          (spark (range 1 7))              
127
          "▁▂▃▅▆█"))
128
     (is (string=
129
          (spark (range 1 7) :key #'fib)   
130
          "▁▁▂▃▅█"))
131
     (is (string=
132
          (spark (range 1 7) :key #'exp)   
133
          "▁▁▁▁▃█"))
134
     (is (string=
135
          (spark (range 1 7) :key #'fac)   
136
          "▁▁▁▁▂█"))
137
     (is (string=
138
          (spark (range 1 7) :key #'isqrt) 
139
          "▁▁▁███"))
140
     ;; misc
141
     (flet ((lbits (n) (spark (map 'list #'digit-char-p (write-to-string n :base 2)))))
142
       (is (string=
143
            (lbits 42) 
144
            "█▁█▁█▁"))
145
       (is (string=
146
            (lbits 43) 
147
            "█▁█▁██"))
148
       (is (string=
149
            (lbits 44) 
150
            "█▁██▁▁"))
151
       (is (string= 
152
            (lbits 45) 
153
            "█▁██▁█")))
154
 
155
     ;; VSPARK
156
     (is (string=
157
          (vspark '())
158
          ""))
159
     ;; singleton
160
     (is (string= 
161
          (vspark '(1))
162
          "
163
 1                      1.5                       2
164
 ˫-----------------------+------------------------˧
165
 
166
 "))
167
 
168
     ;; constant
169
     (is (string= 
170
          (vspark '(1 1))
171
          "
172
 1                      1.5                       2
173
 ˫-----------------------+------------------------˧
174
 
175
 
176
 "))
177
 
178
 
179
     (is (string=
180
          (vspark '(0 30 55 80 33 150))
181
          "
182
 0                      75                      150
183
 ˫-----------------------+------------------------˧
184
 
185
 ██████████▏
186
 ██████████████████▍
187
 ██████████████████████████▋
188
 ███████████▏
189
 ██████████████████████████████████████████████████
190
 "))
191
 
192
 
193
     ;; min, max
194
 
195
     (is (string=
196
          (vspark '(0 30 55 80 33 150) :min -100)
197
          "
198
 -100                    25                     150
199
 ˫-----------------------+------------------------˧
200
 ████████████████████▏
201
 ██████████████████████████▏
202
 ███████████████████████████████▏
203
 ████████████████████████████████████▏
204
 ██████████████████████████▋
205
 ██████████████████████████████████████████████████
206
 "))
207
 
208
     (is (string=
209
          (vspark '(0 30 55 80 33 150) :max 50)
210
          "
211
 0                      25                       50
212
 ˫-----------------------+------------------------˧
213
 
214
 ██████████████████████████████▏
215
 ██████████████████████████████████████████████████
216
 ██████████████████████████████████████████████████
217
 █████████████████████████████████▏
218
 ██████████████████████████████████████████████████
219
 "))
220
 
221
 
222
     (is (string=
223
          (vspark '(0 30 55 80 33 150) :min 30 :max 80)
224
          "
225
 30                      55                      80
226
 ˫-----------------------+------------------------˧
227
 
228
 
229
 █████████████████████████▏
230
 ██████████████████████████████████████████████████
231
 ███▏
232
 ██████████████████████████████████████████████████
233
 "))
234
 
235
     ;; labels
236
     (is (string=
237
          (vspark '(1 0 .5) :labels '("on" "off" "unknown")
238
                            :size 1
239
                            :scale? nil)
240
          "
241
      on █
242
     off ▏
243
 unknown ▌
244
 "))
245
 
246
     (is (string=
247
          (vspark '(1 0 .5) :labels '("on" "off")
248
                            :size 1
249
                            :scale? nil)
250
          "
251
  on █
252
 off ▏
253
     ▌
254
 "))
255
 
256
     (is (string=
257
          (vspark '(1 0) :labels '("on" "off" "unknown")
258
                         :size 1
259
                         :scale? nil)
260
          "
261
  on █
262
 off ▏
263
 "))
264
 
265
     ;; key
266
     (is (string=
267
          (vspark '(0 1 2 3 4 5 6 7 8) :key (lambda (x) (sin (* x pi 1/4))))
268
          "
269
 -1.0                    0.0                    1.0
270
 ˫-----------------------+------------------------˧
271
 █████████████████████████▏
272
 ██████████████████████████████████████████▋
273
 ██████████████████████████████████████████████████
274
 ██████████████████████████████████████████▋
275
 █████████████████████████▏
276
 ███████▍
277
 
278
 ███████▍
279
 ████████████████████████▉
280
 "))
281
 
282
     ;; size
283
     (is (string=
284
          (vspark '(0 1 2 3 4 5 6 7 8) :key (lambda (x) (sin (* x pi 1/4)))
285
                                       :size 10)
286
          "
287
 -1.0   1.0
288
 ˫--------˧
289
 █████▏
290
 ████████▌
291
 ██████████
292
 ████████▌
293
 █████▏
294
 █▌
295
 
296
 █▌
297
 ████▉
298
 "))
299
 
300
     ;; scale (mid-point)
301
     (is (string=
302
          (vspark '(0 1 2 3 4 5 6 7 8) :key (lambda (x) (sin (* x pi 1/4)))
303
                                       :size 20)
304
          "
305
 -1.0     0.0     1.0
306
 ˫--------+---------˧
307
 ██████████▏
308
 █████████████████▏
309
 ████████████████████
310
 █████████████████▏
311
 ██████████▏
312
 ██▉
313
 
314
 ██▉
315
 █████████▉
316
 "))
317
 
318
     (let ((life-expectancies '(("Africa" 56)
319
                                ("Americans" 76)
320
                                ("South-East Asia" 67)
321
                                ("Europe" 76)
322
                                ("Eastern Mediterranean" 68)
323
                                ("Western Pacific" 76)
324
                                ("Global" 70))))
325
 
326
       (is (string=
327
            (vspark life-expectancies :key #'second)
328
            "
329
 56                      66                      76
330
 ˫-----------------------+------------------------˧
331
 
332
 ██████████████████████████████████████████████████
333
 ███████████████████████████▌
334
 ██████████████████████████████████████████████████
335
 ██████████████████████████████▏
336
 ██████████████████████████████████████████████████
337
 ███████████████████████████████████▏
338
 "))
339
 
340
       ;; newline?
341
       (is (string=
342
            (vspark life-expectancies :key #'second :scale? nil :newline? nil)
343
            "▏
344
 ██████████████████████████████████████████████████
345
 ███████████████████████████▌
346
 ██████████████████████████████████████████████████
347
 ██████████████████████████████▏
348
 ██████████████████████████████████████████████████
349
 ███████████████████████████████████▏"))
350
 
351
       ;; scale?
352
       (is (string=
353
            (vspark life-expectancies :key #'second :scale? nil)
354
            "
355
 
356
 ██████████████████████████████████████████████████
357
 ███████████████████████████▌
358
 ██████████████████████████████████████████████████
359
 ██████████████████████████████▏
360
 ██████████████████████████████████████████████████
361
 ███████████████████████████████████▏
362
 "))
363
 
364
       ;; labels
365
       (is (string=
366
            (vspark life-expectancies
367
                    :key   #'second
368
                    :labels (mapcar #'first life-expectancies))
369
            "
370
                       56           66           76
371
                       ˫------------+-------------˧
372
                Africa ▏
373
             Americans ████████████████████████████
374
       South-East Asia ███████████████▍
375
                Europe ████████████████████████████
376
 Eastern Mediterranean ████████████████▊
377
       Western Pacific ████████████████████████████
378
                Global ███████████████████▋
379
 "))
380
 
381
       ;; title
382
       (is (string=
383
            (vspark life-expectancies
384
                    :min 50 :max 80
385
                    :key    #'second
386
                    :labels (mapcar #'first life-expectancies)
387
                    :title "Life Expectancy")
388
            "
389
                  Life Expectancy                  
390
                       50           65           80
391
                       ˫------------+-------------˧
392
                Africa █████▋
393
             Americans ████████████████████████▎
394
       South-East Asia ███████████████▉
395
                Europe ████████████████████████▎
396
 Eastern Mediterranean ████████████████▊
397
       Western Pacific ████████████████████████▎
398
                Global ██████████████████▋
399
 "))
400
 
401
       (is (string=
402
            (spark (range 0 15) :key #'fib)
403
            "▁▁▁▁▁▁▁▁▁▁▂▂▃▅█"))
404
 
405
       (is (string=
406
            (vspark (range 0 15) :key #'fib)
407
            "
408
 0                    188.5                     377
409
 ˫-----------------------+------------------------˧
410
 
411
 
412
 
413
 
414
 
415
 
416
 █▏
417
 █▊
418
 ██▊
419
 ████▌
420
 ███████▍
421
 ███████████▊
422
 ███████████████████▏
423
 ██████████████████████████████▉
424
 ██████████████████████████████████████████████████
425
 ")))))
426
 
427
 (deftest repl (:skip t))
428
 
429
 (deftest env ()
430
   (is (exec-path-list))
431
   (is (find-exe "sbcl")))
432
 
433
 (deftest sbcl-tools ()
434
   (when (find-exe "sbcl")
435
     (iseql 
436
      :ok
437
      (read-from-string
438
       (with-output-to-string (s)
439
         (let ((cli/tools/sbcl::*sbcl-input* nil)
440
               (cli/tools/sbcl::*sbcl-output* s))
441
           (with-sbcl (:noinform t :quit t)
442
             (print :ok))))))))
443
 �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������