File: test-inferior-process.el

package info (click to toggle)
lua-mode 20210802-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 480 kB
  • sloc: lisp: 3,132; makefile: 40; sh: 21
file content (162 lines) | stat: -rw-r--r-- 6,220 bytes parent folder | download | duplicates (2)
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
;; -*- flycheck-disabled-checkers: (emacs-lisp-checkdoc) ; lexical-binding:t -*-
(load (concat (file-name-directory (or load-file-name (buffer-file-name)
                                       default-directory))
              "utils.el") nil 'nomessage 'nosuffix)
(require 'cl-lib)
(require 'comint)


(describe "Hiding process buffer does not switch current window"
  (it "when process is active"
    (with-lua-buffer
     (let ((cur-buf (current-buffer)))
       (expect (get-buffer-window cur-buf))
       (lua-start-process)
       (lua-hide-process-buffer)
       (expect (get-buffer-window cur-buf)))))

  (it "and does not signal when process is already killed"
    (with-lua-buffer
     (let ((cur-buf (current-buffer)))
       (lua-start-process)
       (lua-kill-process)
       (lua-hide-process-buffer)
       (expect (get-buffer-window cur-buf)))))

  (it "when process is not started"
    (with-lua-buffer
     (let ((cur-buf (current-buffer)))
       (expect lua-process-buffer :to-be nil)
       (lua-hide-process-buffer)
       (expect (get-buffer-window cur-buf))))))

(describe "Compilation minor mode"
  (it "sets comint-prompt-regexp in process buffer"
    (with-lua-buffer
     (lua-start-process)
     (with-current-buffer lua-process-buffer
       (expect "" :not :to-match comint-prompt-regexp)
       (expect "> " :to-match comint-prompt-regexp))
     (expect comint-prompt-regexp :to-equal "^"))
    (expect comint-prompt-regexp :to-equal "^")))


(require 'compile)
(if (fboundp 'compilation--loc->file-struct)
    (defun get-error-file (err-info)
      (caar (compilation--loc->file-struct
             (compilation--message->loc (compilation-next-error 0)))))
  (defun get-error-file (err-info)
    (caar (nth 2 (car err-info)))))


(describe "Fontification in compilation buffer"
  (xit "fontifies runtime error messages"
    (with-lua-buffer
     (insert "\
function bar()
   error(123)
end

function foo()
   bar()
end
")
     (rename-buffer "test-send-runtime-error.lua" 'unique)
     ;; By default non-nil compilation-message-face is appended to
     ;; compilation-error faces, let's simplify the checks.
     (let ((compilation-message-face nil))
       (lua-send-buffer)
       (lua-send-string "foo()")
       ;; Make sure to wait enough to get all the output from the subprocess.
       (while (accept-process-output lua-process 0 200))
       (with-current-buffer lua-process-buffer
         (expect
          (get-buffer-line-faces)
          :to-equal
          '(nil ;; motd line (not highlighted)
            nil ;; first prompt (also not highlighted)
            ("test-send-runtime-error.lua" compilation-error
             "2" compilation-line-number) ;; error message
            nil                           ;; stack traceback
            nil                           ;; in function error
            ("test-send-runtime-error.lua" compilation-error
             "2" compilation-line-number) ;; in 'bar'
            ("test-send-runtime-error.lua" compilation-error
             "6" compilation-line-number) ;; in 'foo'
            ("stdin" compilation-error "1" compilation-line-number)
            nil ;; in main chunk
            nil))))))

  (xit "fontifies syntax error messages"
    (with-lua-buffer
     (rename-buffer "test-send-syntax-error.lua")
     (insert "\
function () end
")
     ;; By default non-nil compilation-message-face is appended to
     ;; compilation-error faces, let's simplify the checks.
     (let ((compilation-message-face nil))
       (lua-send-buffer)
       (while (accept-process-output lua-process 0 200))
       (with-current-buffer lua-process-buffer
         (expect
          (get-buffer-line-faces)
          :to-equal
          '(nil ;; motd line, no highlight
            nil ;; first prompt, also no highlight
            (;; "stdin" is being highlighted here because compilation mode
             ;; thinks it is some sort of "make: ..." message.  This doesn't
             ;; happen in wildlife, because there's a default message face
             ;; (underline) that prevents this.  In tests this is turned off,
             ;; see `(compilation-message-face nil)' above, to simplify
             ;; font-lock face checks.
             "stdin" font-lock-function-name-face
             "test-send-syntax-error.lua" compilation-error
             "1" compilation-line-number)
            ;; stacktrace with misc info, no font-lock
            nil nil
            ("stdin" compilation-error "1" compilation-line-number)
            ("stdin" compilation-error "1" compilation-line-number)
            nil nil))))))


  ;; (it "does not ask for file on \"stdin:NN\" errors"
  ;;   (let ((fname (make-temp-file "lua_mode_test" nil ".lua"))
  ;;         buf)
  ;;     (unwind-protect
  ;;         (progn
  ;;           (save-current-buffer
  ;;             (setq buf (find-file fname))
  ;;             (insert "function () end")
  ;;             ;; Make sure the buffer can be killed cleanly
  ;;             (set-buffer-modified-p nil)
  ;;             (lua-send-buffer)
  ;;             (while (accept-process-output lua-process 0 200))
  ;;             (with-current-buffer lua-process-buffer
  ;;               (font-lock-fontify-buffer))
  ;;             (cl-letf
  ;;                 (((symbol-function 'read-file-name)
  ;;                   (lambda (&rest args)
  ;;                     (error "read-file-name must not be called"))))
  ;;               (expect (next-error) :to-be nil)
  ;;               (with-current-buffer lua-process-buffer
  ;;                 (expect fname :to-equal
  ;;                         (get-error-file (compilation-next-error 0))))

  ;;               (expect (next-error) :to-be nil)
  ;;               (with-current-buffer lua-process-buffer
  ;;                 (expect "stdin" :to-equal
  ;;                         (get-error-file (compilation-next-error 0)))))))
  ;;       (when buf
  ;;         (kill-buffer buf))
  ;;       (delete-file fname)
  ;;       (kill-buffer "*lua*"))))
  )

(describe "String escaping"
  (it "Escapes literal tabs"
    (expect (string=
	     (lua-make-lua-string "\
	-- comment indented with a tab")
	     "'\\t-- comment indented with a tab'"))))