Skip to content

Commit 87bd037

Browse files
committed
Implement quiet mode for tctest
Add `:quiet` option to tctest-play and enable it when `quiet` keyword is specified for tctest-env.
1 parent 8bec74b commit 87bd037

File tree

2 files changed

+51
-23
lines changed

2 files changed

+51
-23
lines changed

test/tctest-env.el

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
;; notctest : tctest.el をロードしない。
3535
;; uim : tcode-use-input-method を t に設定する。
3636
;; nodefim : tcode-use-as-default-input-method を nil に設定する。
37+
;; quiet : バッチテストでの表示量を減らす。具体的には、ERT を
38+
;; quiet モード(summary だけを表示するモード。emacs-27 以
39+
;; 降のみ)にした上で、ERT 以外のメッセージを極力表示しな
40+
;; いようにする。
3741
;;
3842
;; FIXME: バッチモードで、単体テストを実行できるようにしたい。
3943
;; --batch で起動した emacs は、対話モードと動作が異なる場合がある
@@ -47,6 +51,10 @@
4751
(defvar tcode-use-isearch)
4852
(defvar tcode-use-input-method)
4953
(defvar tcode-use-as-default-input-method)
54+
(defvar tcode-verbose-message)
55+
(defvar tctest-play-default-params)
56+
(defvar ert-quiet)
57+
(declare-function tctest-load-tc "tctest-play")
5058

5159
(defconst tctest-env-mandatory-keywords
5260
'("isim" "isadvice" "isoverwrite" "ist" "isnil" "notc")
@@ -69,6 +77,9 @@
6977
(message msg) ; to stderr
7078
(insert msg "\n"))))
7179

80+
(defun tctest-env-quiet-p (keywords)
81+
(member "quiet" keywords))
82+
7283
(defun tctest-env-load-tc (keywords)
7384
"変数設定をした上で、tc-setup をロードする。"
7485
;; tctest-env-chk-mandatory によるチェックにより、キーワード isim,
@@ -90,6 +101,12 @@
90101
(setq tcode-use-as-default-input-method nil)))
91102
(when (member "uim" keywords)
92103
(setq tcode-use-input-method t))
104+
(when (tctest-env-quiet-p keywords)
105+
;; .tc-record の読み込みメッセージを非表示に。
106+
(setq tcode-verbose-message nil)
107+
;; この値が非 nil だと、文字入力のたびに tcode-input-method 内で
108+
;; tcode-verbose-message が t にセットされてしまう。
109+
(setq input-method-verbose-flag nil))
93110
(unless (member "notc" keywords)
94111
(require 'tc-setup))
95112
(when (member "nodefim" keywords)
@@ -110,12 +127,13 @@
110127
"ert のバッチテストを実行する。"
111128
(when (and noninteractive
112129
(not (member "nobatch" keywords)))
113-
;; FIXME: quiet オプションは、実験的に付けてはみたものの、isearch
114-
;; の echo area 表示が標準エラーに大量に出力されるので、あまり意味
115-
;; はなかった。個々のテスト中で、inhibit-message t を設定する機能
116-
;; を追加する必要がある。
117-
(let ((ert-quiet (member "quiet" keywords)))
118-
(ert-run-tests-batch-and-exit))))
130+
(when (tctest-env-quiet-p keywords)
131+
(setq ert-quiet t) ; ERT を quiet モードに (emacs-27 以降で有効)
132+
(puthash :quiet t tctest-play-default-params) ; テスト中の表示オフ
133+
(let ((inhibit-message t))
134+
;; tc-tbl.el のロードを、表示オフの状態で済ませおく。
135+
(tctest-load-tc)))
136+
(ert-run-tests-batch-and-exit)))
119137

120138
(defun tctest-env-main ()
121139
(let* ((keywords-packed (or (getenv "TCTEST_ENV")
@@ -124,20 +142,21 @@
124142
(tctest-env-chk-mandatory keywords)
125143
(when (member "debug" keywords)
126144
(setq debug-on-error t))
127-
(tctest-env-msg "dir: %s" default-directory)
128-
(tctest-env-msg "emacs-version: %s" emacs-version)
129-
(tctest-env-msg "keywords: %S" keywords)
130-
(tctest-env-load-tc keywords)
131-
(unless (or (member "notc" keywords)
132-
(member "notctest" keywords))
133-
(require 'tctest))
134-
(tctest-env-show-exprs '(tcode-data-directory
135-
tcode-use-isearch
136-
tcode-use-input-method
137-
tcode-use-as-default-input-method
138-
(locate-library "tc-setup")
139-
(featurep 'tc-is22)
140-
(featurep 'tc-ishelper)))
145+
(let ((inhibit-message (tctest-env-quiet-p keywords)))
146+
(tctest-env-msg "dir: %s" default-directory)
147+
(tctest-env-msg "emacs-version: %s" emacs-version)
148+
(tctest-env-msg "keywords: %S" keywords)
149+
(tctest-env-load-tc keywords)
150+
(unless (or (member "notc" keywords)
151+
(member "notctest" keywords))
152+
(require 'tctest))
153+
(tctest-env-show-exprs '(tcode-data-directory
154+
tcode-use-isearch
155+
tcode-use-input-method
156+
tcode-use-as-default-input-method
157+
(locate-library "tc-setup")
158+
(featurep 'tc-is22)
159+
(featurep 'tc-ishelper))))
141160
(tctest-env-run-test keywords)))
142161

143162
(tctest-env-main)

test/tctest-play.el

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Keyword arguments:
2525
:timeout SECONDS Stop the macro after the specified duration.
2626
:buf BUFFER Use BUFFER instead of creating a new one.
2727
:no-ding t Do not insert `<DING>'.
28+
:quiet t Stop showing messages to echo area and stderr.
2829
:setup-fun FUN Call FUN before running the macro.
2930
:cleanup-fun FUN Call FUN after running the macro.
3031
:no-kbd t Pass KEYS directly to `execute-kbd-macro'
@@ -40,11 +41,13 @@ sole argument to both :setup-fun and :cleanup-fun."
4041
(initial (gethash :initial params))
4142
(timeout (gethash :timeout params))
4243
(buf (gethash :buf params))
44+
(quiet (gethash :quiet params))
4345
(no-kbd (gethash :no-kbd params))
4446
(no-ding (gethash :no-ding params))
4547
(setup-fun (gethash :setup-fun params))
4648
(cleanup-fun (gethash :cleanup-fun params))
47-
(error-filter (gethash :error-filter params)))
49+
(error-filter (gethash :error-filter params))
50+
(inhibit-message quiet))
4851
(puthash :keys keys params)
4952
(when (null buf)
5053
(setq buf (generate-new-buffer "*play*"))
@@ -225,15 +228,21 @@ hash-table DEFAULT-PARAMS."
225228
#s(hash-table data (:show-buf nil))
226229
"Default values used by `tctest-cmp'.")
227230

231+
(defun tctest-load-tc ()
232+
"tc.el がロード済みの状態にする。"
233+
;; (require 'tc) でも十分だが、テストなので念のため、ユーザーの使用
234+
;; 方法に準じた操作のみで実現する。
235+
(toggle-input-method) ; 初回の有効化で、tc.el がロードされる。
236+
(toggle-input-method))
237+
228238
(defun tctest-cmp (keys &rest args)
229239
"T-Code テスト用の設定を行なった上で、`tctest-check'を呼ぶ。
230240
tctest-check および tctest-play の受け取る引数に加えて、以下の
231241
キーワード引数を指定できる。
232242
:vars ((VAR VAL)...) : テストの間だけ、変数 VAR に 値 VAL をセットする。
233243
:requires (PKG...) : (require PKG) を実行する。
234244
:input-method NAME : テストの間だけ input method を NAME に変更する。"
235-
(toggle-input-method) ; load tc
236-
(toggle-input-method)
245+
(tctest-load-tc) ; T-Code 表の逆引きのために必要。
237246
(let* ((params (tctest-fill-params tctest-cmp-default-params args))
238247
(setup-user-fun (gethash :setup-fun params))
239248
(cleanup-user-fun (gethash :cleanup-fun params)))

0 commit comments

Comments
 (0)