This file is indexed.

/usr/share/emacs/site-lisp/elpa-src/slime-2.20/contrib/test/slime-macrostep-tests.el is in slime 2:2.20+dfsg-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
;; Tests for slime-macrostep.  The following are expected failures:

;; - Under CLISP, highlighting of macro sub-forms fails because our
;;   pretty-printer dispatch table hacking causes infinite recursion:
;;   see comment in swank-macrostep.lisp

;; - COLLECT-MACRO-FORMS does not catch compiler macros under CLISP
;;   and ABCL

;; - Under CCL and ECL, compiler macro calls returned by
;;   COLLECT-MACRO-FORMS are not EQ to the original form, and so are
;;   not detected by the tracking pretty-printer mechanism.  This
;;   could be fixed by adding :TEST #'EQUAL to the POSITION call
;;   within MAKE-TRACKING-PPRINT-DISPATCH, at the cost of introducing
;;   false positives.

;; ECL has two other issues:

;;   - it currently lacks a working SLIME defimplementation for
;;     MACROEXPAND-ALL (Github issue #157), without which none of the
;;     expand-in-context stuff works.

;;   - the environments consed up by its WALKER:MACROEXPAND-ALL
;;     function are slightly broken, and do not work when passed to
;;     MACROEXPAND-1 unless fixed up via

;;         (subst 'si::macro 'walker::macro env)

(require 'slime-macrostep)
(require 'slime-tests)
(require 'cl-lib)

(defun slime-macrostep-eval-definitions (definitions)
  (slime-check-top-level)
  (slime-compile-string definitions 0)
  (slime-sync-to-top-level 5))

(defmacro slime-macrostep-with-text (buffer-text &rest body)
  (declare (indent 1))
  `(with-temp-buffer
     (lisp-mode)
     (save-excursion
       (insert ,buffer-text))
     ,@body))

(defun slime-macrostep-search (form)
  "Search forward for FORM, leaving point at its first character."
  (let ((case-fold-search t)
        (search-spaces-regexp "\\s-+"))
    (re-search-forward (regexp-quote form)))
  (goto-char (match-beginning 0)))



(def-slime-test (slime-macrostep-expand-defmacro)
    (definition buffer-text original expansion)
  "Test that simple macrostep expansion works."
  '(("(defmacro macrostep-dummy-macro (&rest args)
        `(expansion of ,@args))"

     "(progn
        (first body form)
        (second body form)
        (macrostep-dummy-macro (first (argument)) second (third argument))
        (remaining body forms))"

     "(macrostep-dummy-macro (first (argument)) second (third argument))"

     "(expansion of (first (argument)) second (third argument))"))
  (slime-macrostep-eval-definitions definition)
  (slime-macrostep-with-text buffer-text
    (slime-macrostep-search original)
    (macrostep-expand)
    (slime-test-expect "Macroexpansion is correct"
                       expansion
                       (downcase (slime-sexp-at-point))
                       #'slime-test-macroexpansion=)))

(def-slime-test (slime-macrostep-fontify-macros
                 (:fails-for "clisp" "ECL"))
    (definition buffer-text original subform)
  "Test that macro forms in expansions are font-locked"
  '(("(defmacro macrostep-dummy-1 (&rest args)
        `(expansion including (macrostep-dummy-2 ,@args)))
      (defmacro macrostep-dummy-2 (&rest args)
        `(final expansion of ,@args))"

     "(progn
        (first body form)
        (second body form)
        (macrostep-dummy-1 (first (argument)) second (third argument))
        (remaining body forms))"

     "(macrostep-dummy-1 (first (argument)) second (third argument))"

     "(macrostep-dummy-2 (first (argument)) second (third argument))"))
  (slime-macrostep-eval-definitions definition)
  (slime-macrostep-with-text buffer-text
    (slime-macrostep-search original)
    (macrostep-expand)
    (slime-macrostep-search subform)
    (forward-char)                      ; move over open paren
    (slime-check "Head of macro form in expansion is fontified correctly"
        (eq (get-char-property (point) 'font-lock-face)
         'macrostep-macro-face))))

(def-slime-test (slime-macrostep-fontify-compiler-macros
                 (:fails-for "armedbear" "clisp" "ccl" "ECL"))
    (definition buffer-text original subform)
  "Test that compiler-macro forms in expansions are font-locked"
  '(("(defmacro macrostep-dummy-3 (&rest args)
        `(expansion including (macrostep-dummy-4 ,@args)))
      (defun macrostep-dummy-4 (&rest args)
        args)
      (define-compiler-macro macrostep-dummy-4 (&rest args)
        `(compile-time expansion of ,@args))"

     "(progn
        (first body form)
        (second body form)
        (macrostep-dummy-3 first second third)
        (remaining body forms))"

     "(macrostep-dummy-3 first second third)"

     "(macrostep-dummy-4 first second third)"))
  (slime-macrostep-eval-definitions definition)
  (slime-macrostep-with-text buffer-text
    (slime-macrostep-search original)
    (let ((macrostep-expand-compiler-macros t))
      (macrostep-expand))
    (slime-macrostep-search subform)
    (forward-char)                      ; move over open paren
    (slime-check "Head of compiler-macro in expansion is fontified correctly"
        (eq (get-char-property (point) 'font-lock-face)
         'macrostep-compiler-macro-face))))

(def-slime-test (slime-macrostep-expand-macrolet
                 (:fails-for "ECL"))
    (definitions buffer-text expansions)
    "Test that calls to macrolet-defined macros are expanded."
    '((nil
       "(macrolet
            ((test (&rest args) `(expansion of ,@args)))
          (first body form)
          (second body form)
          (test (strawberry pie) and (apple pie))
          (final body form))"
       (("(test (strawberry pie) and (apple pie))"
         "(EXPANSION OF (STRAWBERRY PIE) AND (APPLE PIE))")))

      ;; From swank.lisp:
      (nil
       "(macrolet ((define-xref-action (xref-type handler)
                     `(defmethod xref-doit ((type (eql ,xref-type)) thing)
                        (declare (ignorable type))
                        (funcall ,handler thing))))
          (define-xref-action :calls        #'who-calls)
          (define-xref-action :calls-who    #'calls-who)
          (define-xref-action :references   #'who-references)
          (define-xref-action :binds        #'who-binds)
          (define-xref-action :macroexpands #'who-macroexpands)
          (define-xref-action :specializes  #'who-specializes)
          (define-xref-action :callers      #'list-callers)
          (define-xref-action :callees      #'list-callees))"
       (("(define-xref-action :calls        #'who-calls)"
         "(DEFMETHOD XREF-DOIT ((TYPE (EQL :CALLS)) THING)
            (DECLARE (IGNORABLE TYPE))
            (FUNCALL #'WHO-CALLS THING))")
        ("(define-xref-action :macroexpands #'who-macroexpands)"
         "(DEFMETHOD XREF-DOIT ((TYPE (EQL :MACROEXPANDS)) THING)
            (DECLARE (IGNORABLE TYPE))
            (FUNCALL #'WHO-MACROEXPANDS THING))")
        ("(define-xref-action :callees      #'list-callees)"
         "(DEFMETHOD XREF-DOIT ((TYPE (EQL :CALLEES)) THING)
            (DECLARE (IGNORABLE TYPE))
            (FUNCALL #'LIST-CALLEES THING))")))

      ;; Test expansion of shadowed definitions
      (nil
       "(macrolet
            ((test-macro (&rest forms) (cons 'outer-definition forms)))
          (test-macro first (call))
          (macrolet
              ((test-macro (&rest forms) (cons 'inner-definition forms)))
            (test-macro (second (call)))))"
       (("(test-macro first (call))"
         "(OUTER-DEFINITION FIRST (CALL))")
        ("(test-macro (second (call)))"
         "(INNER-DEFINITION (SECOND (CALL)))")))

      ;; Expansion of macro-defined local macros
      ("(defmacro with-local-dummy-macro (&rest body)
          `(macrolet ((dummy (&rest args) `(expansion (of) ,@args)))
             ,@body))"
       "(with-local-dummy-macro
           (dummy form (one))
           (dummy (form two)))"
       (("(dummy form (one))"
         "(EXPANSION (OF) FORM (ONE))")
        ("(dummy (form two))"
         "(EXPANSION (OF) (FORM TWO))"))))

  (when definitions
    (slime-macrostep-eval-definitions definitions))
  (slime-macrostep-with-text buffer-text
    ;; slime-test-macroexpansion= does not expect tab characters,
    ;; so make sure that Emacs does not insert them
    (let ((indent-tabs-mode nil))
      (cl-loop
       for (original expansion) in expansions
       do
       (goto-char (point-min))
       (slime-macrostep-search original)
       (macrostep-expand)
       (slime-test-expect "Macroexpansion is correct"
                          expansion
                          (slime-sexp-at-point)
                          #'slime-test-macroexpansion=)))))

(def-slime-test (slime-macrostep-fontify-local-macros
                 (:fails-for "clisp" "ECL"))
    ()
    "Test that locally-bound macros are highlighted in expansions."
    '(())
    (slime-macrostep-with-text
        "(macrolet ((frob (&rest args)
                      (if (zerop (length args))
                          nil
                          `(cons ,(car args) (frob ,@(cdr args))))))
           (frob 1 2 3 4 5))"
      (let ((expansions
             '(("(frob 1 2 3 4 5)"
                "(CONS 1 (FROB 2 3 4 5))"
                "(FROB 2 3 4 5)")
               ("(FROB 2 3 4 5)"
                "(CONS 2 (FROB 3 4 5))"
                "(FROB 3 4 5)")
               ("(FROB 3 4 5)"
                "(CONS 3 (FROB 4 5))"
                "(FROB 4 5)")
               ("(FROB 4 5)"
                "(CONS 4 (FROB 5))"
                "(FROB 5)")
               ("(FROB 5)"
                "(CONS 5 (FROB))"
                "(FROB)")
               ;; ("(FROB)"
               ;;  "NIL"
               ;;  nil)
               )))
        (cl-loop for (original expansion subform) in expansions
                 do
                 (goto-char (point-min))
                 (slime-macrostep-search original)
                 (macrostep-expand)
                 (slime-test-expect "Macroexpansion is correct"
                                    expansion
                                    (slime-sexp-at-point)
                                    #'slime-test-macroexpansion=)
                 (when subform
                   (slime-macrostep-search subform)
                   (forward-char)
                   (slime-check "Head of macro form in expansion is fontified correctly"
                       (eq (get-char-property (point) 'font-lock-face)
                        'macrostep-macro-face)))))))

(def-slime-test (slime-macrostep-handle-unreadable-objects)
    (definitions buffer-text subform expansion)
    "Check that macroexpansion succeeds in a context containing unreadable objects."
    '(("(defmacro macrostep-dummy-5 (&rest args)
          `(expansion of ,@args))"
       "(progn
          #<unreadable object>
          (macrostep-dummy-5 quux frob))"
       "(macrostep-dummy-5 quux frob)"
       "(EXPANSION OF QUUX FROB)"))
    (slime-macrostep-eval-definitions definitions)
    (slime-macrostep-with-text buffer-text
      (slime-macrostep-search subform)
      (macrostep-expand)
      (slime-test-expect "Macroexpansion is correct"
                         expansion
                         (slime-sexp-at-point)
                         #'slime-test-macroexpansion=)))

(provide 'slime-macrostep-tests)