[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/swift-mode ed03fde 377/496: Refactor tests
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/swift-mode ed03fde 377/496: Refactor tests |
Date: |
Sun, 29 Aug 2021 11:34:10 -0400 (EDT) |
branch: elpa/swift-mode
commit ed03fde38fe7b78fb4bb548b9188ec3b7d316e38
Author: taku0 <mxxouy6x3m_github@tatapa.org>
Commit: taku0 <mxxouy6x3m_github@tatapa.org>
Refactor tests
---
Makefile | 5 +-
test/swift-files/{ => indent}/comment.swift | 0
test/swift-files/{ => indent}/declarations.swift | 0
test/swift-files/{ => indent}/expressions.swift | 0
test/swift-files/{ => indent}/identifiers.swift | 0
test/swift-files/{ => indent}/operators.swift | 0
test/swift-files/{ => indent}/statements.swift | 0
test/swift-files/{ => indent}/strings.swift | 0
test/swift-files/{ => indent}/types.swift | 0
test/swift-mode-test-indent.el | 151 ++++++---------------
...wift-mode-test-indent.el => swift-mode-test.el} | 109 ++++-----------
11 files changed, 71 insertions(+), 194 deletions(-)
diff --git a/Makefile b/Makefile
index 303f864..b7039d4 100644
--- a/Makefile
+++ b/Makefile
@@ -49,5 +49,6 @@ test:
## Tests the package.
$(CASK) exec $(EMACS) --batch -q \
--eval "(add-to-list 'load-path \""$(shell readlink -f .)"\")" \
- -l test/swift-mode-test-indent.el \
- -f swift-mode:run-test:indent
+ --eval "(add-to-list 'load-path \""$(shell readlink -f .)"/test\")" \
+ -l test/swift-mode-test.el \
+ -f swift-mode:run-test
diff --git a/test/swift-files/comment.swift
b/test/swift-files/indent/comment.swift
similarity index 100%
rename from test/swift-files/comment.swift
rename to test/swift-files/indent/comment.swift
diff --git a/test/swift-files/declarations.swift
b/test/swift-files/indent/declarations.swift
similarity index 100%
rename from test/swift-files/declarations.swift
rename to test/swift-files/indent/declarations.swift
diff --git a/test/swift-files/expressions.swift
b/test/swift-files/indent/expressions.swift
similarity index 100%
rename from test/swift-files/expressions.swift
rename to test/swift-files/indent/expressions.swift
diff --git a/test/swift-files/identifiers.swift
b/test/swift-files/indent/identifiers.swift
similarity index 100%
rename from test/swift-files/identifiers.swift
rename to test/swift-files/indent/identifiers.swift
diff --git a/test/swift-files/operators.swift
b/test/swift-files/indent/operators.swift
similarity index 100%
rename from test/swift-files/operators.swift
rename to test/swift-files/indent/operators.swift
diff --git a/test/swift-files/statements.swift
b/test/swift-files/indent/statements.swift
similarity index 100%
rename from test/swift-files/statements.swift
rename to test/swift-files/indent/statements.swift
diff --git a/test/swift-files/strings.swift
b/test/swift-files/indent/strings.swift
similarity index 100%
rename from test/swift-files/strings.swift
rename to test/swift-files/indent/strings.swift
diff --git a/test/swift-files/types.swift b/test/swift-files/indent/types.swift
similarity index 100%
rename from test/swift-files/types.swift
rename to test/swift-files/indent/types.swift
diff --git a/test/swift-mode-test-indent.el b/test/swift-mode-test-indent.el
index 52a78e4..a48236c 100644
--- a/test/swift-mode-test-indent.el
+++ b/test/swift-mode-test-indent.el
@@ -34,79 +34,52 @@
(require 'swift-mode)
(require 'swift-mode-indent)
-(defvar swift-mode:test:basedir
- (file-name-directory (or load-file-name buffer-file-name)))
-
-(defun swift-mode:setup-error-buffer ()
- "Initialize and switch to the error buffer.
-
-Return the error-buffer"
- (pop-to-buffer (get-buffer-create "*swift-mode-test-indent*"))
- (fundamental-mode)
- (setq buffer-read-only nil)
- (erase-buffer)
- (current-buffer))
-
-(defun swift-mode:run-test:indent ()
- "Run indentation test for `swift-mode'."
+(defun swift-mode:run-test:indent
+ (&optional error-buffer error-counts progress-reporter)
+ "Run indentation test for `swift-mode'.
+
+ERROR-BUFFER is the buffer to output errors.
+ERROR-COUNTS is a association list holding counts of errors. Updated
+destructively.
+PROGRESS-REPORTER is the progress-reporter."
(interactive)
- (let ((error-buffer
- (if noninteractive nil (swift-mode:setup-error-buffer)))
- (current-line 0)
- (error-counts (list
- (cons 'error 0)
- (cons 'warning 0)
- (cons 'info 0)
- (cons 'ok 0)))
- (progress-reporter (unless noninteractive
- (make-progress-reporter "Running tests..."))))
- (setq default-directory
- (concat (file-name-as-directory swift-mode:test:basedir)
- "swift-files"))
-
- (dolist (swift-file (file-expand-wildcards "*.swift"))
- (redisplay)
- (with-temp-buffer
- (switch-to-buffer (current-buffer))
- (insert-file-contents-literally swift-file)
- (swift-mode)
- (setq current-line 0)
- (while (not (eobp))
- (when (not noninteractive)
- (progress-reporter-update progress-reporter))
- (setq current-line (1+ current-line))
- (cond
- ((looking-at ".*//.*swift-mode:test:keep-indent")
- nil)
-
- ((= (line-beginning-position) (line-end-position))
- ;; Empty line
- nil)
-
- (t
- (when (looking-at ".*//.*swift-mode:test:eval\\(.*\\)")
- (eval-region (match-beginning 1) (match-end 1)))
- (let*
- ((status (swift-mode:test-current-line-indent
- swift-file current-line error-buffer))
- (count-assoc (assq status error-counts)))
- (setcdr count-assoc (1+ (cdr count-assoc))))))
- (forward-line))))
-
- (when (not noninteractive)
- (progress-reporter-done progress-reporter))
-
- (swift-mode:print-message
- error-buffer
- (concat
- "Errors: " (prin1-to-string (assoc-default 'error error-counts)) "\n"
- "Warning: " (prin1-to-string (assoc-default 'warning error-counts)) "\n"
- "Info: " (prin1-to-string (assoc-default 'info error-counts)) "\n"
- "OK: " (prin1-to-string (assoc-default 'ok error-counts)) "\n"))
-
- (if noninteractive
- (kill-emacs (min 63 (assoc-default 'error error-counts)))
- (compilation-mode))))
+
+ (if (not swift-mode:test:running)
+ (swift-mode:run-test '(swift-mode:run-test:indent))
+ (let ((current-line 0))
+ (setq default-directory
+ (concat (file-name-as-directory swift-mode:test:basedir)
+ (file-name-as-directory "swift-files")
+ "indent"))
+
+ (dolist (swift-file (file-expand-wildcards "*.swift"))
+ (redisplay)
+ (with-temp-buffer
+ (switch-to-buffer (current-buffer))
+ (insert-file-contents-literally swift-file)
+ (swift-mode)
+ (setq current-line 0)
+ (while (not (eobp))
+ (when (not noninteractive)
+ (progress-reporter-update progress-reporter))
+ (setq current-line (1+ current-line))
+ (cond
+ ((looking-at ".*//.*swift-mode:test:keep-indent")
+ nil)
+
+ ((= (line-beginning-position) (line-end-position))
+ ;; Empty line
+ nil)
+
+ (t
+ (when (looking-at ".*//.*swift-mode:test:eval\\(.*\\)")
+ (eval-region (match-beginning 1) (match-end 1)))
+ (let*
+ ((status (swift-mode:test-current-line-indent
+ swift-file current-line error-buffer))
+ (count-assoc (assq status error-counts)))
+ (setcdr count-assoc (1+ (cdr count-assoc))))))
+ (forward-line)))))))
(defun swift-mode:test-current-line-indent
(swift-file current-line error-buffer)
@@ -151,40 +124,6 @@ ERROR-BUFFER is the buffer to output errors."
status))
-(defun swift-mode:show-error (error-buffer file line level message)
- "Show an error message to the ERROR-BUFFER or stdout.
-
-If the Emacs is in the batch mode, the message is printed to the stdout.
-Otherwise, the message is appended to the ERROR-BUFFER.
-
-FILE is the filename of the test case.
-LINE is the line number of the error.
-LEVEL is the error level (e.g. error, warning).
-MESSAGE is the error message."
- (let ((formatted
- (concat
- "swift-mode-test:"
- file
- ":"
- (prin1-to-string line)
- ": "
- level
- ": "
- message
- "\n")))
- (swift-mode:print-message error-buffer formatted)))
-
-(defun swift-mode:print-message (error-buffer message)
- "Print a message to the ERROR-BUFFER or stdout.
-
-If the Emacs is in the batch mode, MESSAGE is printed to the stdout.
-Otherwise, MESSAGE is appended to the ERROR-BUFFER."
- (if noninteractive
- (princ message)
- (with-current-buffer error-buffer
- (goto-char (point-max))
- (insert-and-inherit message))))
-
(provide 'swift-mode-test-indent)
;;; swift-mode-test-indent.el ends here
diff --git a/test/swift-mode-test-indent.el b/test/swift-mode-test.el
similarity index 52%
copy from test/swift-mode-test-indent.el
copy to test/swift-mode-test.el
index 52a78e4..99410ba 100644
--- a/test/swift-mode-test-indent.el
+++ b/test/swift-mode-test.el
@@ -1,4 +1,4 @@
-;;; swift-mode-test-indent.el --- Test for swift-mode: indentation -*-
lexical-binding: t -*-
+;;; swift-mode-test.el --- Test for swift-mode -*- lexical-binding: t -*-
;; Copyright (C) 2016-2017 taku0
@@ -26,33 +26,38 @@
;;; Commentary:
-;; Test for swift-mode: indentation.
-;; Execute swift-mode:run-test:indent interactively or in batch mode.
+;; Tests for swift-mode.
+;; Execute swift-mode:run-test interactively or in batch mode.
;;; Code:
-(require 'swift-mode)
-(require 'swift-mode-indent)
+(require 'swift-mode-test-indent)
(defvar swift-mode:test:basedir
(file-name-directory (or load-file-name buffer-file-name)))
+(defvar swift-mode:test:running nil)
+
(defun swift-mode:setup-error-buffer ()
"Initialize and switch to the error buffer.
Return the error-buffer"
- (pop-to-buffer (get-buffer-create "*swift-mode-test-indent*"))
+ (pop-to-buffer (get-buffer-create "*swift-mode-test*"))
(fundamental-mode)
(setq buffer-read-only nil)
(erase-buffer)
(current-buffer))
-(defun swift-mode:run-test:indent ()
- "Run indentation test for `swift-mode'."
+(defvar swift-mode:tests '(swift-mode:run-test:indent))
+
+(defun swift-mode:run-test (&optional tests)
+ "Run TESTS for `swift-mode'."
(interactive)
+
+ (setq tests (or tests swift-mode:tests))
+
(let ((error-buffer
(if noninteractive nil (swift-mode:setup-error-buffer)))
- (current-line 0)
(error-counts (list
(cons 'error 0)
(cons 'warning 0)
@@ -60,38 +65,13 @@ Return the error-buffer"
(cons 'ok 0)))
(progress-reporter (unless noninteractive
(make-progress-reporter "Running tests..."))))
- (setq default-directory
- (concat (file-name-as-directory swift-mode:test:basedir)
- "swift-files"))
-
- (dolist (swift-file (file-expand-wildcards "*.swift"))
- (redisplay)
- (with-temp-buffer
- (switch-to-buffer (current-buffer))
- (insert-file-contents-literally swift-file)
- (swift-mode)
- (setq current-line 0)
- (while (not (eobp))
- (when (not noninteractive)
- (progress-reporter-update progress-reporter))
- (setq current-line (1+ current-line))
- (cond
- ((looking-at ".*//.*swift-mode:test:keep-indent")
- nil)
-
- ((= (line-beginning-position) (line-end-position))
- ;; Empty line
- nil)
-
- (t
- (when (looking-at ".*//.*swift-mode:test:eval\\(.*\\)")
- (eval-region (match-beginning 1) (match-end 1)))
- (let*
- ((status (swift-mode:test-current-line-indent
- swift-file current-line error-buffer))
- (count-assoc (assq status error-counts)))
- (setcdr count-assoc (1+ (cdr count-assoc))))))
- (forward-line))))
+
+ (setq swift-mode:test:running t)
+
+ (unwind-protect
+ (dolist (test tests)
+ (funcall test error-buffer error-counts progress-reporter))
+ (setq swift-mode:test:running nil))
(when (not noninteractive)
(progress-reporter-done progress-reporter))
@@ -108,49 +88,6 @@ Return the error-buffer"
(kill-emacs (min 63 (assoc-default 'error error-counts)))
(compilation-mode))))
-(defun swift-mode:test-current-line-indent
- (swift-file current-line error-buffer)
- "Run indentation test for swift-mode on current line.
-
-SWIFT-FILE is the filename of the current test case.
-CURRENT-LINE is the current line number.
-ERROR-BUFFER is the buffer to output errors."
- (back-to-indentation)
- (let ((original-indent (current-column))
- computed-indent
- (known-bug (looking-at ".*//.*swift-mode:test:known-bug"))
- (status 'ok))
- (delete-horizontal-space)
- (when (= original-indent 0)
- (indent-line-to 1))
-
- (swift-mode:indent-line)
- (back-to-indentation)
- (setq computed-indent (current-column))
- (indent-line-to original-indent)
-
- (when (/= original-indent computed-indent)
- (setq status (if known-bug 'warning 'error))
-
- (swift-mode:show-error
- error-buffer swift-file current-line
- (if known-bug "warning" "error")
- (concat
- (if known-bug "(knwon bug) " "")
- "expected "
- (prin1-to-string original-indent)
- " but "
- (prin1-to-string computed-indent))))
-
- (when (and (= original-indent computed-indent) known-bug)
- (setq status 'info)
- (swift-mode:show-error
- error-buffer swift-file current-line
- "info"
- "known-bug is fixed somehow"))
-
- status))
-
(defun swift-mode:show-error (error-buffer file line level message)
"Show an error message to the ERROR-BUFFER or stdout.
@@ -185,6 +122,6 @@ Otherwise, MESSAGE is appended to the ERROR-BUFFER."
(goto-char (point-max))
(insert-and-inherit message))))
-(provide 'swift-mode-test-indent)
+(provide 'swift-mode-test)
-;;; swift-mode-test-indent.el ends here
+;;; swift-mode-test.el ends here
- [nongnu] elpa/swift-mode 50394e4 357/496: Bump version to 2.4.0, (continued)
- [nongnu] elpa/swift-mode 50394e4 357/496: Bump version to 2.4.0, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 82ee822 361/496: Fix code styles, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 5df00bc 367/496: Fix typo, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 1167fec 369/496: Fix comment, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode e58e4e0 368/496: Tweak test, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 089853c 384/496: Fix typo "identifer" to "identifier", ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode e81ab53 381/496: Fix comments, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 8d4a5a5 373/496: Add kill/mark/narrow-to-sentence, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode a042764 374/496: Fix indentation of comments, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 8c45f69 383/496: Bump version to 4.0.1, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode ed03fde 377/496: Refactor tests,
ELPA Syncer <=
- [nongnu] elpa/swift-mode 1970f1d 380/496: Fix `beginning-of-defun' inside class methods, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 4b2c628 372/496: Add forward/backward sentence, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode c67b950 388/496: Fixes which-function-mode hang when running swift-mode:current-defun-name in a non swift-mode buffer., ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 9809fb6 391/496: Add more comprehensive support for highlighting built-ins, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 544c265 397/496: Move macro before its use, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 3751335 398/496: Tweak and checkdoc compliance, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 4c5a1d9 401/496: Add support for running on device via ios-deploy, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode 7ea1d4e 404/496: Bump version to 5.0.0, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode e229d69 405/496: Fix typo, ELPA Syncer, 2021/08/29
- [nongnu] elpa/swift-mode cfbec0a 406/496: Update copyrights, ELPA Syncer, 2021/08/29