forked from slime/slime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slime-tests.el
1488 lines (1376 loc) · 55.6 KB
/
slime-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
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; slime-tests.el --- Automated tests for slime.el -*- lexical-binding: t -*-
;;
;;;; License
;; Copyright (C) 2003 Eric Marsden, Luke Gorrie, Helmut Eller
;; Copyright (C) 2004,2005,2006 Luke Gorrie, Helmut Eller
;; Copyright (C) 2007,2008,2009 Helmut Eller, Tobias C. Rittweiler
;; Copyright (C) 2013
;;
;; For a detailed list of contributors, see the manual.
;;
;; 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 2 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, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.
;;;; Tests
(require 'slime)
(require 'ert nil t)
(require 'ert "lib/ert" t) ;; look for bundled version for Emacs 23
(require 'cl-lib)
(require 'bytecomp) ; byte-compile-current-file
(defun slime-shuffle-list (list)
(let* ((len (length list))
(taken (make-vector len nil))
(result (make-vector len nil)))
(dolist (e list)
(while (let ((i (random len)))
(cond ((aref taken i))
(t (aset taken i t)
(aset result i e)
nil)))))
(append result '())))
(defun slime-batch-test (&optional test-name randomize)
"Run the test suite in batch-mode.
Exits Emacs when finished. The exit code is the number of failed tests."
(interactive)
(let ((ert-debug-on-error nil)
(timeout 60)
(slime-background-message-function #'ignore))
(slime)
;; Block until we are up and running.
(let (timed-out)
(run-with-timer timeout nil
(lambda () (setq timed-out t)))
(while (not (slime-connected-p))
(sit-for 1)
(when timed-out
(when noninteractive
(kill-emacs 252)))))
(slime-sync-to-top-level 5)
(let* ((selector (if randomize
`(member ,@(slime-shuffle-list
(ert-select-tests (or test-name t) t)))
(or test-name t)))
(ert-fun (if noninteractive
'ert-run-tests-batch
'ert)))
(let ((stats (funcall ert-fun selector)))
(if noninteractive
(kill-emacs (ert-stats-completed-unexpected stats)))))))
(defun slime-skip-test (message)
;; ERT for Emacs 23 and earlier doesn't have `ert-skip'
(if (fboundp 'ert-skip)
(ert-skip message)
(message (concat "SKIPPING: " message))
(ert-pass)))
(defun slime-tests--undefine-all ()
(dolist (test (ert-select-tests t t))
(let* ((sym (ert-test-name test)))
(cl-assert (eq (get sym 'ert--test) test))
(cl-remprop sym 'ert--test))))
(slime-tests--undefine-all)
(eval-and-compile
(defun slime-tests-auto-tags ()
(append '(slime)
(let ((file-name (or load-file-name
byte-compile-current-file)))
(if (and file-name
(string-match "contrib/test/slime-\\(.*\\)\.elc?$"
file-name))
(list 'contrib (intern (match-string 1 file-name)))
'(core)))))
(defmacro define-slime-ert-test (name &rest args)
"Like `ert-deftest', but set tags automatically.
Also don't error if `ert.el' is missing."
(if (not (featurep 'ert))
(warn "No ert.el found: not defining test %s"
name)
(let* ((docstring (and (stringp (cl-second args))
(cl-second args)))
(args (if docstring
(cddr args)
(cdr args)))
(tags (slime-tests-auto-tags)))
`(ert-deftest ,name () ,(or docstring "No docstring for this test.")
:tags ',tags
,@args))))
(defun slime-test-ert-test-for (name input i doc _body fails-for style fname)
`(define-slime-ert-test
,(intern (format "%s-%d" name i)) ()
,(format "For input %s, %s" (truncate-string-to-width
(format "%s" input)
15 nil nil 'ellipsis)
(replace-regexp-in-string "^.??\\(\\w+\\)"
(lambda (s) (downcase s))
doc
t))
,@(if fails-for
`(:expected-result '(satisfies
(lambda (result)
(ert-test-result-type-p
result
(if (member
(slime-lisp-implementation-name)
',fails-for)
:failed
:passed))))))
,@(when style
`((let ((style (slime-communication-style)))
(when (not (member style ',style))
(slime-skip-test (format "test not applicable for style %s"
style))))))
(apply #',fname ',input))))
(defmacro def-slime-test (name args doc inputs &rest body)
"Define a test case.
NAME ::= SYMBOL | (SYMBOL OPTION*) is a symbol naming the test.
OPTION ::= (:fails-for IMPLEMENTATION*) | (:style COMMUNICATION-STYLE*)
ARGS is a lambda-list.
DOC is a docstring.
INPUTS is a list of argument lists, each tested separately.
BODY is the test case. The body can use `slime-check' to test
conditions (assertions)."
(declare (debug (&define name sexp sexp sexp &rest def-form)))
(if (not (featurep 'ert))
(warn "No ert.el found: not defining test %s"
name)
`(progn
,@(cl-destructuring-bind (name &rest options)
(if (listp name) name (list name))
(let ((fname (intern (format "slime-test-%s" name))))
(cons `(defun ,fname ,args
(slime-sync-to-top-level 0.3)
,@body
(slime-sync-to-top-level 0.3))
(cl-loop for input in (eval inputs)
for i from 1
with fails-for = (cdr (assoc :fails-for options))
with style = (cdr (assoc :style options))
collect (slime-test-ert-test-for name
input
i
doc
body
fails-for
style
fname))))))))
(put 'def-slime-test 'lisp-indent-function 4)
(defmacro slime-check (check &rest body)
(declare (indent defun))
`(unless (progn ,@body)
(ert-fail ,(cl-etypecase check
(cons `(concat "Ooops, " ,(cons 'format check)))
(string `(concat "Check failed: " ,check))
(symbol `(concat "Check failed: " ,(symbol-name check)))))))
;;;;; Test case definitions
(defun slime-check-top-level () ;(&optional _test-name)
(accept-process-output nil 0.001)
(slime-check "At the top level (no debugging or pending RPCs)"
(slime-at-top-level-p)))
(defun slime-at-top-level-p ()
(and (not (sldb-get-default-buffer))
(null (slime-rex-continuations))))
(defun slime-wait-condition (name predicate timeout)
(let ((end (time-add (current-time) (seconds-to-time timeout))))
(while (not (funcall predicate))
(message "waiting for condition: %s [%s]" name
(format-time-string "%H:%M:%S.%6N"))
(cond ((time-less-p end (current-time))
(error "Timeout waiting for condition: %S" name))
(t
;; XXX if a process-filter enters a recursive-edit, we
;; hang forever
(accept-process-output nil 0.1))))))
(defun slime-sync-to-top-level (timeout)
(slime-wait-condition "top-level" #'slime-at-top-level-p timeout))
;; XXX: unused function
(defun slime-check-sldb-level (expected)
(let ((sldb-level (let ((sldb (sldb-get-default-buffer)))
(if sldb
(with-current-buffer sldb
sldb-level)))))
(slime-check ("SLDB level (%S) is %S" expected sldb-level)
(equal expected sldb-level))))
(defun slime-test-expect (_name expected actual &optional test)
(when (stringp expected) (setq expected (substring-no-properties expected)))
(when (stringp actual) (setq actual (substring-no-properties actual)))
(if test
(should (funcall test expected actual))
(should (equal expected actual))))
(defun sldb-level ()
(let ((sldb (sldb-get-default-buffer)))
(if sldb
(with-current-buffer sldb
sldb-level))))
(defun slime-sldb-level= (level)
(equal level (sldb-level)))
(eval-when-compile
(defvar slime-test-symbols
'(("foobar") ("foo@bar") ("@foobar") ("foobar@") ("\\@foobar")
("|asdf||foo||bar|")
("\\#<Foo@Bar>")
("\\(setf\\ car\\)"))))
(defun slime-check-symbol-at-point (prefix symbol suffix)
;; We test that `slime-symbol-at-point' works at every
;; character of the symbol name.
(with-temp-buffer
(lisp-mode)
(insert prefix)
(let ((start (point)))
(insert symbol suffix)
(dotimes (i (length symbol))
(goto-char (+ start i))
(slime-test-expect (format "Check `%s' (at %d)..."
(buffer-string) (point))
symbol
(slime-symbol-at-point)
#'equal)))))
(def-slime-test symbol-at-point.2 (sym)
"fancy symbol-name _not_ at BOB/EOB"
slime-test-symbols
(slime-check-symbol-at-point "(foo " sym " bar)"))
(def-slime-test symbol-at-point.3 (sym)
"fancy symbol-name with leading ,"
(cl-remove-if (lambda (s) (eq (aref (car s) 0) ?@)) slime-test-symbols)
(slime-check-symbol-at-point "," sym ""))
(def-slime-test symbol-at-point.4 (sym)
"fancy symbol-name with leading ,@"
slime-test-symbols
(slime-check-symbol-at-point ",@" sym ""))
(def-slime-test symbol-at-point.5 (sym)
"fancy symbol-name with leading `"
slime-test-symbols
(slime-check-symbol-at-point "`" sym ""))
(def-slime-test symbol-at-point.6 (sym)
"fancy symbol-name wrapped in ()"
slime-test-symbols
(slime-check-symbol-at-point "(" sym ")"))
(def-slime-test symbol-at-point.7 (sym)
"fancy symbol-name wrapped in #< {DEADBEEF}>"
slime-test-symbols
(slime-check-symbol-at-point "#<" sym " {DEADBEEF}>"))
;;(def-slime-test symbol-at-point.8 (sym)
;; "fancy symbol-name wrapped in #<>"
;; slime-test-symbols
;; (slime-check-symbol-at-point "#<" sym ">"))
(def-slime-test symbol-at-point.9 (sym)
"fancy symbol-name wrapped in #| ... |#"
slime-test-symbols
(slime-check-symbol-at-point "#|\n" sym "\n|#"))
(def-slime-test symbol-at-point.10 (sym)
"fancy symbol-name after #| )))(( |# (1)"
slime-test-symbols
(slime-check-symbol-at-point "#| )))(( #|\n" sym ""))
(def-slime-test symbol-at-point.11 (sym)
"fancy symbol-name after #| )))(( |# (2)"
slime-test-symbols
(slime-check-symbol-at-point "#| )))(( #|" sym ""))
(def-slime-test symbol-at-point.12 (sym)
"fancy symbol-name wrapped in \"...\""
slime-test-symbols
(slime-check-symbol-at-point "\"\n" sym "\"\n"))
(def-slime-test symbol-at-point.13 (sym)
"fancy symbol-name wrapped in \" )))(( \" (1)"
slime-test-symbols
(slime-check-symbol-at-point "\" )))(( \"\n" sym ""))
(def-slime-test symbol-at-point.14 (sym)
"fancy symbol-name wrapped in \" )))(( \" (1)"
slime-test-symbols
(slime-check-symbol-at-point "\" )))(( \"" sym ""))
(def-slime-test symbol-at-point.15 (sym)
"symbol-at-point after #."
slime-test-symbols
(slime-check-symbol-at-point "#." sym ""))
(def-slime-test symbol-at-point.16 (sym)
"symbol-at-point after #+"
slime-test-symbols
(slime-check-symbol-at-point "#+" sym ""))
(def-slime-test sexp-at-point.1 (string)
"symbol-at-point after #'"
'(("foo")
("#:foo")
("#'foo")
("#'(lambda (x) x)")
("()"))
(with-temp-buffer
(lisp-mode)
(insert string)
(goto-char (point-min))
(slime-test-expect (format "Check sexp `%s' (at %d)..."
(buffer-string) (point))
string
(slime-sexp-at-point)
#'equal)))
(def-slime-test narrowing ()
"Check that narrowing is properly sustained."
'()
(slime-check-top-level)
(let ((random-buffer-name (symbol-name (cl-gensym)))
(defun-pos) (tmpbuffer))
(with-temp-buffer
(dotimes (i 100) (insert (format ";;; %d. line\n" i)))
(setq tmpbuffer (current-buffer))
(setq defun-pos (point))
(insert (concat "(defun __foo__ (x y)" "\n"
" 'nothing)" "\n"))
(dotimes (i 100) (insert (format ";;; %d. line\n" (+ 100 i))))
(slime-check "Checking that newly created buffer is not narrowed."
(not (slime-buffer-narrowed-p)))
(goto-char defun-pos)
(narrow-to-defun)
(slime-check "Checking that narrowing succeeded."
(slime-buffer-narrowed-p))
(slime-with-popup-buffer (random-buffer-name)
(slime-check ("Checking that we're in Slime's temp buffer `%s'"
random-buffer-name)
(equal (buffer-name (current-buffer)) random-buffer-name)))
(with-current-buffer random-buffer-name
;; Notice that we cannot quit the buffer within the extent
;; of slime-with-output-to-temp-buffer.
(quit-window t))
(slime-check ("Checking that we've got back from `%s'"
random-buffer-name)
(and (eq (current-buffer) tmpbuffer)
(= (point) defun-pos)))
(slime-check "Checking that narrowing sustained \
after quitting Slime's temp buffer."
(slime-buffer-narrowed-p))
(let ((slime-buffer-package "SWANK")
(symbol '*buffer-package*))
(slime-edit-definition (symbol-name symbol))
(slime-check ("Checking that we've got M-. into swank.lisp. %S" symbol)
(string= (file-name-nondirectory (buffer-file-name))
"swank.lisp"))
(slime-pop-find-definition-stack)
(slime-check ("Checking that we've got back.")
(and (eq (current-buffer) tmpbuffer)
(= (point) defun-pos)))
(slime-check "Checking that narrowing sustained after M-,"
(slime-buffer-narrowed-p)))
))
(slime-check-top-level))
(defun slime-test--display-region-eval-arg (line window-height)
(cl-etypecase line
(number line)
(cons (slime-dcase line
((+h line)
(+ (slime-test--display-region-eval-arg line window-height)
window-height))
((-h line)
(- (slime-test--display-region-eval-arg line window-height)
window-height))))))
(defun slime-test--display-region-line-to-position (line window-height)
(let ((line (slime-test--display-region-eval-arg line window-height)))
(save-excursion
(goto-char (point-min))
(forward-line (1- line))
(line-beginning-position))))
(def-slime-test display-region
(start end pos window-start expected-window-start expected-point)
"Test `slime-display-region'."
;; numbers are actually lines numbers
'(;; region visible, point in region
(2 4 3 1 1 3)
;; region visible, point visible but ouside region
(2 4 5 1 1 5)
;; end not visible, point at start
(2 (+h 2) 2 1 2 2)
;; start not visible, point at start
((+h 2) (+h 500) (+h 2) 1 (+h 2) (+h 2))
;; start not visible, point after end
((+h 2) (+h 500) (+h 6) 1 (+h 2) (+h 6))
;; end - start should be visible, point after end
((+h 2) (+h 7) (+h 10) 1 (-h (+h 7)) (+h 6))
;; region is window-height + 1 and ends with newline
((+h -2) (+h (+h -3)) (+h -2) 1 (+h -3) (+h -2))
(2 (+h 1) 3 1 1 3)
(2 (+h 0) 3 1 1 3)
(2 (+h -1) 3 1 1 3)
;; start and end are the beginning
(1 1 1 1 1 1)
;;
(1 (+h 1) (+h 22) (+h 20) 1 (+h 0))
)
(when noninteractive
(slime-skip-test "Can't test slime-display-region in batch mode"))
(with-temp-buffer
(dotimes (i 1000)
(insert (format "%09d\n" i)))
(let* ((win (display-buffer (current-buffer) t))
(wh (window-text-height win)))
(cl-macrolet ((l2p (l)
`(slime-test--display-region-line-to-position ,l wh)))
(select-window win)
(set-window-start win (l2p window-start))
(redisplay)
(goto-char (l2p pos))
(cl-assert (= (l2p window-start) (window-start win)))
(cl-assert (= (point) (l2p pos)))
(slime--display-region (l2p start) (l2p end))
(redisplay)
(cl-assert (= (l2p expected-window-start) (window-start)))
(cl-assert (= (l2p expected-point) (point)))
))))
(def-slime-test find-definition
(name buffer-package snippet)
"Find the definition of a function or macro in swank.lisp."
'(("start-server" "SWANK" "(defun start-server ")
("swank::start-server" "CL-USER" "(defun start-server ")
("swank:start-server" "CL-USER" "(defun start-server ")
("swank::connection" "CL-USER" "(defstruct (connection")
("swank::*emacs-connection*" "CL-USER" "(defvar \\*emacs-connection\\*")
)
(switch-to-buffer "*scratch*") ; not buffer of definition
(slime-check-top-level)
(let ((orig-buffer (current-buffer))
(orig-pos (point))
(enable-local-variables nil) ; don't get stuck on -*- eval: -*-
(slime-buffer-package buffer-package))
(slime-edit-definition name)
;; Postconditions
(slime-check ("Definition of `%S' is in swank.lisp." name)
(string= (file-name-nondirectory (buffer-file-name)) "swank.lisp"))
(slime-check ("Looking at '%s'." snippet) (looking-at snippet))
(slime-pop-find-definition-stack)
(slime-check "Returning from definition restores original buffer/position."
(and (eq orig-buffer (current-buffer))
(= orig-pos (point)))))
(slime-check-top-level))
(def-slime-test (find-definition.2 (:fails-for "allegro" "lispworks"))
(buffer-content buffer-package snippet)
"Check that we're able to find definitions even when
confronted with nasty #.-fu."
'(("#.(prog1 nil (defvar *foobar* 42))
(defun .foo. (x)
(+ x #.*foobar*))
#.(prog1 nil (makunbound '*foobar*))
"
"SWANK"
"[ \t]*(defun .foo. "
)
("#.(prog1 nil (defvar *foobar* 42))
;; some comment
(defun .foo. (x)
(+ x #.*foobar*))
#.(prog1 nil (makunbound '*foobar*))
"
"SWANK"
"[ \t]*(defun .foo. "
)
("(in-package swank)
(eval-when (:compile-toplevel) (defparameter *bar* 456))
(eval-when (:load-toplevel :execute) (makunbound '*bar*))
(defun bar () #.*bar*)
(defun .foo. () 123)"
"SWANK"
"[ \t]*(defun .foo. () 123)"))
(let ((slime-buffer-package buffer-package))
(with-temp-buffer
(insert buffer-content)
(slime-check-top-level)
(slime-eval
`(swank:compile-string-for-emacs
,buffer-content
,(buffer-name)
'((:position 0) (:line 1 1))
,nil
,nil))
(let ((bufname (buffer-name)))
(slime-edit-definition ".foo.")
(slime-check ("Definition of `.foo.' is in buffer `%s'." bufname)
(string= (buffer-name) bufname))
(slime-check "Definition now at point." (looking-at snippet))))))
(def-slime-test (find-definition.3
(:fails-for "abcl" "allegro" "clisp" "lispworks" "ecl"))
(name source regexp)
"Extra tests for defstruct."
'(("swank::foo-struct"
"(progn
(defun foo-fun ())
(defstruct (foo-struct (:constructor nil) (:predicate nil)))
)"
"(defstruct (foo-struct"))
(switch-to-buffer "*scratch*")
(with-temp-buffer
(insert source)
(let ((slime-buffer-package "SWANK"))
(slime-eval
`(swank:compile-string-for-emacs
,source
,(buffer-name)
'((:position 0) (:line 1 1))
,nil
,nil)))
(let ((temp-buffer (current-buffer)))
(with-current-buffer "*scratch*"
(slime-edit-definition name)
(slime-check ("Definition of %S is in buffer `%s'."
name temp-buffer)
(eq (current-buffer) temp-buffer))
(slime-check "Definition now at point." (looking-at regexp)))
)))
(def-slime-test complete-symbol
(prefix expected-completions)
"Find the completions of a symbol-name prefix."
'(("cl:compile" ("cl:compile" "cl:compile-file" "cl:compile-file-pathname"
"cl:compiled-function" "cl:compiled-function-p"
"cl:compiler-macro" "cl:compiler-macro-function"))
("cl:foobar" ())
("swank::compile-file" ("swank::compile-file"
"swank::compile-file-for-emacs"
"swank::compile-file-if-needed"
"swank::compile-file-output"
"swank::compile-file-pathname"))
("cl:m-v-l" ()))
(let ((completions (slime-simple-completions prefix)))
(slime-test-expect "Completion set" expected-completions completions)))
(def-slime-test read-from-minibuffer
(input-keys expected-result)
"Test `slime-read-from-minibuffer' with INPUT-KEYS as events."
'(("( r e v e TAB SPC ' ( 1 SPC 2 SPC 3 ) ) RET"
"(reverse '(1 2 3))")
("( c l : c o n TAB s t a n t l TAB SPC 4 2 ) RET"
"(cl:constantly 42)"))
(when noninteractive
(slime-skip-test "Can't use unread-command-events in batch mode"))
(let ((keys (eval `(kbd ,input-keys)))) ; kbd is a macro in Emacs 23
(setq unread-command-events (listify-key-sequence keys)))
(let ((actual-result (slime-read-from-minibuffer "Test: ")))
(accept-process-output) ; run idle timers
(slime-test-expect "Completed string" expected-result actual-result)))
(def-slime-test arglist
;; N.B. Allegro apparently doesn't return the default values of
;; optional parameters. Thus the regexp in the start-server
;; expected value. In a perfect world we'd find a way to smooth
;; over this difference between implementations--perhaps by
;; convincing Franz to provide a function that does what we want.
(function-name expected-arglist)
"Lookup the argument list for FUNCTION-NAME.
Confirm that EXPECTED-ARGLIST is displayed."
'(("swank::operator-arglist" "(swank::operator-arglist name package)")
("swank::compute-backtrace" "(swank::compute-backtrace start end)")
("swank::emacs-connected" "(swank::emacs-connected)")
("swank::compile-string-for-emacs"
"(swank::compile-string-for-emacs \
string buffer position filename policy)")
("swank::connection.socket-io"
"(swank::connection.socket-io \
\\(struct\\(ure\\)?\\|object\\|instance\\|x\\|connection\\))")
("cl:lisp-implementation-type" "(cl:lisp-implementation-type)")
("cl:class-name"
"(cl:class-name \\(class\\|object\\|instance\\|structure\\))"))
(let ((arglist (slime-eval `(swank:operator-arglist ,function-name
"swank"))))
(slime-test-expect "Argument list is as expected"
expected-arglist (and arglist (downcase arglist))
(lambda (pattern arglist)
(and arglist (string-match pattern arglist))))))
(defun slime-test--compile-defun (program subform)
(slime-check-top-level)
(with-temp-buffer
(lisp-mode)
(insert program)
(let ((font-lock-verbose nil))
(setq slime-buffer-package ":swank")
(slime-compile-string (buffer-string) 1)
(setq slime-buffer-package ":cl-user")
(slime-sync-to-top-level 5)
(goto-char (point-max))
(slime-previous-note)
(slime-check error-location-correct
(equal (read (current-buffer)) subform))))
(slime-check-top-level))
(def-slime-test (compile-defun (:fails-for "allegro" "lispworks" "clisp"))
(program subform)
"Compile PROGRAM containing errors.
Confirm that SUBFORM is correctly located."
'(("(defun cl-user::foo () (cl-user::bar))" (cl-user::bar))
("(defun cl-user::foo ()
#\\space
;;Sdf
(cl-user::bar))"
(cl-user::bar))
("(defun cl-user::foo ()
#+(or)skipped
#| #||#
#||# |#
(cl-user::bar))"
(cl-user::bar))
("(defun cl-user::foo ()
\"\\\" bla bla \\\"\"
(cl-user::bar))"
(cl-user::bar))
("(defun cl-user::foo ()
#.*log-events*
(cl-user::bar))"
(cl-user::bar))
("#.'(defun x () (/ 1 0))
(defun foo ()
(cl-user::bar))
"
(cl-user::bar)))
(slime-test--compile-defun program subform))
;; This test ideally would be collapsed into the previous
;; compile-defun test, but only 1 case fails for ccl--and that's here
(def-slime-test (compile-defun-with-reader-conditionals
(:fails-for "allegro" "lispworks" "clisp" "ccl"))
(program subform)
"Compile PROGRAM containing errors.
Confirm that SUBFORM is correctly located."
'(("(defun foo ()
#+#.'(:and) (/ 1 0))"
(/ 1 0)))
(slime-test--compile-defun program subform))
;; SBCL used to pass this one but since they changed the
;; backquote/unquote reader it fails.
(def-slime-test (compile-defun-with-backquote
(:fails-for "allegro" "lispworks" "clisp" "sbcl"))
(program subform)
"Compile PROGRAM containing errors.
Confirm that SUBFORM is correctly located."
'(("(defun cl-user::foo ()
(list `(1 ,(random 10) 2 ,@(make-list (random 10)) 3
,(cl-user::bar))))"
(cl-user::bar)))
(slime-test--compile-defun program subform))
(def-slime-test (compile-file (:fails-for "allegro" "clisp"))
(string)
"Insert STRING in a file, and compile it."
`((,(pp-to-string '(defun foo () nil))))
(let ((filename "/tmp/slime-tmp-file.lisp"))
(with-temp-file filename
(insert string))
(let ((cell (cons nil nil)))
(slime-eval-async
`(swank:compile-file-for-emacs ,filename nil)
(slime-rcurry (lambda (result cell)
(setcar cell t)
(setcdr cell result))
cell))
(slime-wait-condition "Compilation finished" (lambda () (car cell))
5)
(let ((result (cdr cell)))
(slime-check "Compilation successfull"
(eq (slime-compilation-result.successp result) t))))))
(def-slime-test utf-8-source
(input output)
"Source code containing utf-8 should work"
(list (let* ((bytes "\000\343\201\212\343\201\257\343\202\210\343\201\206")
;; (encode-coding-string
;; (string #x0000 #x304a #x306f #x3088 #x3046)
;; 'utf-8)
(string (decode-coding-string bytes 'utf-8-unix)))
(cl-assert (equal bytes (encode-coding-string string 'utf-8-unix)))
(list (concat "(defun cl-user::foo () \"" string "\")")
string)))
(slime-eval `(cl:eval (cl:read-from-string ,input)))
(slime-test-expect "Eval result correct"
output (slime-eval '(cl-user::foo)))
(let ((cell (cons nil nil)))
(let ((hook (slime-curry (lambda (cell &rest _) (setcar cell t)) cell)))
(add-hook 'slime-compilation-finished-hook hook)
(unwind-protect
(progn
(slime-compile-string input 0)
(slime-wait-condition "Compilation finished"
(lambda () (car cell))
5)
(slime-test-expect "Compile-string result correct"
output (slime-eval '(cl-user::foo))))
(remove-hook 'slime-compilation-finished-hook hook))
(let ((filename "/tmp/slime-tmp-file.lisp"))
(setcar cell nil)
(add-hook 'slime-compilation-finished-hook hook)
(unwind-protect
(with-temp-buffer
(when (fboundp 'set-buffer-multibyte)
(set-buffer-multibyte t))
(setq buffer-file-coding-system 'utf-8-unix)
(setq buffer-file-name filename)
(insert ";; -*- coding: utf-8-unix -*- \n")
(insert input)
(let ((coding-system-for-write 'utf-8-unix))
(write-region nil nil filename nil t))
(let ((slime-load-failed-fasl 'always))
(slime-compile-and-load-file)
(slime-wait-condition "Compilation finished"
(lambda () (car cell))
5))
(slime-test-expect "Compile-file result correct"
output (slime-eval '(cl-user::foo))))
(remove-hook 'slime-compilation-finished-hook hook)
(ignore-errors (delete-file filename)))))))
(def-slime-test async-eval-debugging (depth)
"Test recursive debugging of asynchronous evaluation requests."
'((1) (2) (3))
(let ((depth depth)
(debug-hook-max-depth 0))
(let ((debug-hook
(lambda ()
(with-current-buffer (sldb-get-default-buffer)
(when (> sldb-level debug-hook-max-depth)
(setq debug-hook-max-depth sldb-level)
(if (= sldb-level depth)
;; We're at maximum recursion - time to unwind
(sldb-quit)
;; Going down - enter another recursive debug
;; Recursively debug.
(slime-eval-async '(error))))))))
(let ((sldb-hook (cons debug-hook sldb-hook)))
(slime-eval-async '(error))
(slime-sync-to-top-level 5)
(slime-check ("Maximum depth reached (%S) is %S."
debug-hook-max-depth depth)
(= debug-hook-max-depth depth))))))
(def-slime-test unwind-to-previous-sldb-level (level2 level1)
"Test recursive debugging and returning to lower SLDB levels."
'((2 1) (4 2))
(slime-check-top-level)
(let ((level2 level2)
(level1 level1)
(state 'enter)
(max-depth 0))
(let ((debug-hook
(lambda ()
(with-current-buffer (sldb-get-default-buffer)
(setq max-depth (max sldb-level max-depth))
(cl-ecase state
(enter
(cond ((= sldb-level level2)
(setq state 'leave)
(sldb-invoke-restart (sldb-first-abort-restart)))
(t
(slime-eval-async `(cl:aref cl:nil ,sldb-level)))))
(leave
(cond ((= sldb-level level1)
(setq state 'ok)
(sldb-quit))
(t
(sldb-invoke-restart (sldb-first-abort-restart))
))))))))
(let ((sldb-hook (cons debug-hook sldb-hook)))
(slime-eval-async `(cl:aref cl:nil 0))
(slime-sync-to-top-level 15)
(slime-check-top-level)
(slime-check ("Maximum depth reached (%S) is %S." max-depth level2)
(= max-depth level2))
(slime-check ("Final state reached.")
(eq state 'ok))))))
(defun sldb-first-abort-restart ()
(let ((case-fold-search t))
(cl-position-if (lambda (x) (string-match "abort" (car x)))
sldb-restarts)))
(def-slime-test loop-interrupt-quit
()
"Test interrupting a loop."
'(())
(slime-check-top-level)
(slime-eval-async '(cl:loop) (lambda (_) ) "CL-USER")
(accept-process-output nil 1)
(slime-check "In eval state." (slime-busy-p))
(slime-interrupt)
(slime-wait-condition "First interrupt" (lambda () (slime-sldb-level= 1)) 5)
(with-current-buffer (sldb-get-default-buffer)
(sldb-quit))
(slime-sync-to-top-level 5)
(slime-check-top-level))
(def-slime-test loop-interrupt-continue-interrupt-quit
()
"Test interrupting a previously interrupted but continued loop."
'(())
(slime-check-top-level)
(slime-eval-async '(cl:loop) (lambda (_) ) "CL-USER")
(sleep-for 1)
(slime-wait-condition "running" #'slime-busy-p 5)
(slime-interrupt)
(slime-wait-condition "First interrupt" (lambda () (slime-sldb-level= 1)) 5)
(with-current-buffer (sldb-get-default-buffer)
(sldb-continue))
(slime-wait-condition "running" (lambda ()
(and (slime-busy-p)
(not (sldb-get-default-buffer)))) 5)
(slime-interrupt)
(slime-wait-condition "Second interrupt" (lambda () (slime-sldb-level= 1)) 5)
(with-current-buffer (sldb-get-default-buffer)
(sldb-quit))
(slime-sync-to-top-level 5)
(slime-check-top-level))
(def-slime-test interactive-eval
()
"Test interactive eval and continuing from the debugger."
'(())
(slime-check-top-level)
(let ((done nil))
(let ((sldb-hook (lambda () (sldb-continue) (setq done t))))
(slime-interactive-eval
"(progn\
(cerror \"foo\" \"restart\")\
(cerror \"bar\" \"restart\")\
(+ 1 2))")
(while (not done) (accept-process-output))
(slime-sync-to-top-level 5)
(slime-check-top-level)
(unless noninteractive
(let ((message (current-message)))
(slime-check "Minibuffer contains: \"3\""
(equal "=> 3 (2 bits, #x3, #o3, #b11)" message)))))))
(def-slime-test report-condition-with-circular-list
(format-control format-argument)
"Test conditions involving circular lists."
'(("~a" "(let ((x (cons nil nil))) (setf (cdr x) x))")
("~a" "(let ((x (cons nil nil))) (setf (car x) x))")
("~a" "(let ((x (cons (make-string 100000 :initial-element #\\X) nil)))\
(setf (cdr x) x))"))
(slime-check-top-level)
(let ((done nil))
(let ((sldb-hook (lambda () (sldb-continue) (setq done t))))
(slime-interactive-eval
(format "(with-standard-io-syntax (cerror \"foo\" \"%s\" %s) (+ 1 2))"
format-control format-argument))
(while (not done) (accept-process-output))
(slime-sync-to-top-level 5)
(slime-check-top-level)
(unless noninteractive
(let ((message (current-message)))
(slime-check "Minibuffer contains: \"3\""
(equal "=> 3 (2 bits, #x3, #o3, #b11)" message)))))))
(def-slime-test interrupt-bubbling-idiot
()
"Test interrupting a loop that sends a lot of output to Emacs."
'(())
(accept-process-output nil 1)
(slime-check-top-level)
(slime-eval-async '(cl:loop :for i :from 0 :do (cl:progn (cl:print i)
(cl:finish-output)))
(lambda (_) )
"CL-USER")
(sleep-for 1)
(slime-interrupt)
(slime-wait-condition "Debugger visible"
(lambda ()
(and (slime-sldb-level= 1)
(get-buffer-window (sldb-get-default-buffer))))
30)
(with-current-buffer (sldb-get-default-buffer)
(sldb-quit))
(slime-sync-to-top-level 5))
(def-slime-test (interrupt-encode-message (:style :sigio))
()
"Test interrupt processing during swank::encode-message"
'(())
(slime-eval-async '(cl:loop :for i :from 0
:do (swank::background-message "foo ~d" i)))
(sleep-for 1)
(slime-eval-async '(cl:/ 1 0))
(slime-wait-condition "Debugger visible"
(lambda ()
(and (slime-sldb-level= 1)
(get-buffer-window (sldb-get-default-buffer))))
30)
(with-current-buffer (sldb-get-default-buffer)
(sldb-quit))
(slime-sync-to-top-level 5))
(def-slime-test inspector
(exp)
"Test basic inspector workingness."
'(((let ((h (make-hash-table)))
(loop for i below 10 do (setf (gethash i h) i))
h))
((make-array 10))
((make-list 10))
('cons)
(#'cons))
(slime-inspect (prin1-to-string exp))
(cl-assert (not (slime-inspector-visible-p)))
(slime-wait-condition "Inspector visible" #'slime-inspector-visible-p 5)
(with-current-buffer (window-buffer (selected-window))
(slime-inspector-quit))
(slime-wait-condition "Inspector closed"
(lambda () (not (slime-inspector-visible-p)))
5)
(slime-sync-to-top-level 1))
(defun slime-buffer-visible-p (name)
(let ((buffer (window-buffer (selected-window))))
(string-match name (buffer-name buffer))))
(defun slime-inspector-visible-p ()
(slime-buffer-visible-p (slime-buffer-name :inspector)))
(defun slime-execute-as-command (name)
"Execute `name' as if it was done by the user through the
Command Loop. Similiar to `call-interactively' but also pushes on
the buffer's undo-list."
(undo-boundary)
(call-interactively name))
(def-slime-test macroexpand
(macro-defs bufcontent expansion1 search-str expansion2)
"foo"
'((("(defmacro qwertz (&body body) `(list :qwertz ',body))"
"(defmacro yxcv (&body body) `(list :yxcv (qwertz ,@body)))")