|
34 | 34 | (require 'swift-mode) |
35 | 35 | (require 'swift-mode-indent) |
36 | 36 |
|
37 | | -(defvar swift-mode:test:basedir |
38 | | - (file-name-directory (or load-file-name buffer-file-name))) |
39 | | - |
40 | | -(defun swift-mode:setup-error-buffer () |
41 | | - "Initialize and switch to the error buffer. |
42 | | -
|
43 | | -Return the error-buffer" |
44 | | - (pop-to-buffer (get-buffer-create "*swift-mode-test-indent*")) |
45 | | - (fundamental-mode) |
46 | | - (setq buffer-read-only nil) |
47 | | - (erase-buffer) |
48 | | - (current-buffer)) |
49 | | - |
50 | | -(defun swift-mode:run-test:indent () |
51 | | - "Run indentation test for `swift-mode'." |
| 37 | +(defun swift-mode:run-test:indent |
| 38 | + (&optional error-buffer error-counts progress-reporter) |
| 39 | + "Run indentation test for `swift-mode'. |
| 40 | +
|
| 41 | +ERROR-BUFFER is the buffer to output errors. |
| 42 | +ERROR-COUNTS is a association list holding counts of errors. Updated |
| 43 | +destructively. |
| 44 | +PROGRESS-REPORTER is the progress-reporter." |
52 | 45 | (interactive) |
53 | | - (let ((error-buffer |
54 | | - (if noninteractive nil (swift-mode:setup-error-buffer))) |
55 | | - (current-line 0) |
56 | | - (error-counts (list |
57 | | - (cons 'error 0) |
58 | | - (cons 'warning 0) |
59 | | - (cons 'info 0) |
60 | | - (cons 'ok 0))) |
61 | | - (progress-reporter (unless noninteractive |
62 | | - (make-progress-reporter "Running tests...")))) |
63 | | - (setq default-directory |
64 | | - (concat (file-name-as-directory swift-mode:test:basedir) |
65 | | - "swift-files")) |
66 | | - |
67 | | - (dolist (swift-file (file-expand-wildcards "*.swift")) |
68 | | - (redisplay) |
69 | | - (with-temp-buffer |
70 | | - (switch-to-buffer (current-buffer)) |
71 | | - (insert-file-contents-literally swift-file) |
72 | | - (swift-mode) |
73 | | - (setq current-line 0) |
74 | | - (while (not (eobp)) |
75 | | - (when (not noninteractive) |
76 | | - (progress-reporter-update progress-reporter)) |
77 | | - (setq current-line (1+ current-line)) |
78 | | - (cond |
79 | | - ((looking-at ".*//.*swift-mode:test:keep-indent") |
80 | | - nil) |
81 | | - |
82 | | - ((= (line-beginning-position) (line-end-position)) |
83 | | - ;; Empty line |
84 | | - nil) |
85 | | - |
86 | | - (t |
87 | | - (when (looking-at ".*//.*swift-mode:test:eval\\(.*\\)") |
88 | | - (eval-region (match-beginning 1) (match-end 1))) |
89 | | - (let* |
90 | | - ((status (swift-mode:test-current-line-indent |
91 | | - swift-file current-line error-buffer)) |
92 | | - (count-assoc (assq status error-counts))) |
93 | | - (setcdr count-assoc (1+ (cdr count-assoc)))))) |
94 | | - (forward-line)))) |
95 | | - |
96 | | - (when (not noninteractive) |
97 | | - (progress-reporter-done progress-reporter)) |
98 | | - |
99 | | - (swift-mode:print-message |
100 | | - error-buffer |
101 | | - (concat |
102 | | - "Errors: " (prin1-to-string (assoc-default 'error error-counts)) "\n" |
103 | | - "Warning: " (prin1-to-string (assoc-default 'warning error-counts)) "\n" |
104 | | - "Info: " (prin1-to-string (assoc-default 'info error-counts)) "\n" |
105 | | - "OK: " (prin1-to-string (assoc-default 'ok error-counts)) "\n")) |
106 | | - |
107 | | - (if noninteractive |
108 | | - (kill-emacs (min 63 (assoc-default 'error error-counts))) |
109 | | - (compilation-mode)))) |
| 46 | + |
| 47 | + (if (not swift-mode:test:running) |
| 48 | + (swift-mode:run-test '(swift-mode:run-test:indent)) |
| 49 | + (let ((current-line 0)) |
| 50 | + (setq default-directory |
| 51 | + (concat (file-name-as-directory swift-mode:test:basedir) |
| 52 | + (file-name-as-directory "swift-files") |
| 53 | + "indent")) |
| 54 | + |
| 55 | + (dolist (swift-file (file-expand-wildcards "*.swift")) |
| 56 | + (redisplay) |
| 57 | + (with-temp-buffer |
| 58 | + (switch-to-buffer (current-buffer)) |
| 59 | + (insert-file-contents-literally swift-file) |
| 60 | + (swift-mode) |
| 61 | + (setq current-line 0) |
| 62 | + (while (not (eobp)) |
| 63 | + (when (not noninteractive) |
| 64 | + (progress-reporter-update progress-reporter)) |
| 65 | + (setq current-line (1+ current-line)) |
| 66 | + (cond |
| 67 | + ((looking-at ".*//.*swift-mode:test:keep-indent") |
| 68 | + nil) |
| 69 | + |
| 70 | + ((= (line-beginning-position) (line-end-position)) |
| 71 | + ;; Empty line |
| 72 | + nil) |
| 73 | + |
| 74 | + (t |
| 75 | + (when (looking-at ".*//.*swift-mode:test:eval\\(.*\\)") |
| 76 | + (eval-region (match-beginning 1) (match-end 1))) |
| 77 | + (let* |
| 78 | + ((status (swift-mode:test-current-line-indent |
| 79 | + swift-file current-line error-buffer)) |
| 80 | + (count-assoc (assq status error-counts))) |
| 81 | + (setcdr count-assoc (1+ (cdr count-assoc)))))) |
| 82 | + (forward-line))))))) |
110 | 83 |
|
111 | 84 | (defun swift-mode:test-current-line-indent |
112 | 85 | (swift-file current-line error-buffer) |
@@ -151,40 +124,6 @@ ERROR-BUFFER is the buffer to output errors." |
151 | 124 |
|
152 | 125 | status)) |
153 | 126 |
|
154 | | -(defun swift-mode:show-error (error-buffer file line level message) |
155 | | - "Show an error message to the ERROR-BUFFER or stdout. |
156 | | -
|
157 | | -If the Emacs is in the batch mode, the message is printed to the stdout. |
158 | | -Otherwise, the message is appended to the ERROR-BUFFER. |
159 | | -
|
160 | | -FILE is the filename of the test case. |
161 | | -LINE is the line number of the error. |
162 | | -LEVEL is the error level (e.g. error, warning). |
163 | | -MESSAGE is the error message." |
164 | | - (let ((formatted |
165 | | - (concat |
166 | | - "swift-mode-test:" |
167 | | - file |
168 | | - ":" |
169 | | - (prin1-to-string line) |
170 | | - ": " |
171 | | - level |
172 | | - ": " |
173 | | - message |
174 | | - "\n"))) |
175 | | - (swift-mode:print-message error-buffer formatted))) |
176 | | - |
177 | | -(defun swift-mode:print-message (error-buffer message) |
178 | | - "Print a message to the ERROR-BUFFER or stdout. |
179 | | -
|
180 | | -If the Emacs is in the batch mode, MESSAGE is printed to the stdout. |
181 | | -Otherwise, MESSAGE is appended to the ERROR-BUFFER." |
182 | | - (if noninteractive |
183 | | - (princ message) |
184 | | - (with-current-buffer error-buffer |
185 | | - (goto-char (point-max)) |
186 | | - (insert-and-inherit message)))) |
187 | | - |
188 | 127 | (provide 'swift-mode-test-indent) |
189 | 128 |
|
190 | 129 | ;;; swift-mode-test-indent.el ends here |
0 commit comments