Skip to content

Commit 22466aa

Browse files
Merge pull request #25 from johannes-mueller/correct-transient-repeat-cmd
Fixes #24
2 parents 878ef83 + 0214ea1 commit 22466aa

6 files changed

+102
-8
lines changed

test-cockpit.el

+29-4
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ a derived class of `test-cockpit--engine'.")
9595
:initform nil)
9696
(last-args :initarg :last-args
9797
:initform nil)
98+
(last-interactive-cmd :initarg :last-interactive-cmd
99+
:initform nil)
98100
(is-dummy-engine :initarg :is-dummy-engine
99101
:initform nil))
100102
"The base class for a test-cockpit engine.
@@ -208,6 +210,10 @@ The additional arguments are shipped as ARGS."
208210
(oset engine last-function-string last-function))
209211
(oset engine last-args args)))
210212

213+
(defun test-cockpit--update-last-interactive-command (function)
214+
(let ((engine (test-cockpit--retrieve-engine)))
215+
(oset engine last-interactive-cmd function)))
216+
211217
(defun test-cockpit--make-test-project-command (project-string args)
212218
"Call the test-project-command function with ARGS of the current project type.
213219
PROJECT-STRING is usually nil. The argument is here to make the function
@@ -228,7 +234,7 @@ FUNC-STRING is the string determining the function to test."
228234
(test-cockpit--make-test-command
229235
'test-cockpit--test-function-command func-string args))
230236

231-
(defun test-cockpit-infix ()
237+
(defun test-cockpit--infix ()
232238
"Call the infix function of the current project type and return the infix array."
233239
(test-cockpit--transient-infix
234240
(funcall (alist-get (projectile-project-type) test-cockpit--project-types))))
@@ -238,7 +244,7 @@ FUNC-STRING is the string determining the function to test."
238244
(unless (equal (aref (transient-get-suffix 'test-cockpit-prefix '(0)) 2)
239245
'(:description "Run test"))
240246
(transient-remove-suffix 'test-cockpit-prefix '(0)))
241-
(if-let (infix (test-cockpit-infix))
247+
(if-let (infix (test-cockpit--infix))
242248
(transient-insert-suffix 'test-cockpit-prefix '(0) infix)))
243249

244250
(defun test-cockpit--run-test (command)
@@ -268,6 +274,7 @@ ARGS is the UI state for language specific settings."
268274
(list (transient-args 'test-cockpit-prefix)))
269275
(test-cockpit--run-test
270276
(test-cockpit--command 'test-cockpit--make-test-project-command nil args))
277+
(test-cockpit--update-last-interactive-command 'test-cockpit-test-project)
271278
(test-cockpit--update-last-commands args))
272279

273280
;;;###autoload
@@ -286,6 +293,7 @@ is tested."
286293
(test-cockpit--command 'test-cockpit--make-test-module-command
287294
module-string
288295
args))
296+
(test-cockpit--update-last-interactive-command 'test-cockpit-test-module)
289297
(test-cockpit--update-last-commands args))
290298
(message "Not in a unit test module file")))
291299

@@ -306,6 +314,7 @@ were in is tested."
306314
(test-cockpit--command 'test-cockpit--make-test-function-command
307315
function-string
308316
args))
317+
(test-cockpit--update-last-interactive-command 'test-cockpit-test-function)
309318
(test-cockpit--update-last-commands args))
310319
(message "Not in a unit test module file")))
311320

@@ -435,6 +444,18 @@ prompt to type a test command is shown."
435444
(test-cockpit--repeat-projectile-test)
436445
(test-cockpit-repeat-test)))
437446

447+
448+
;;;###autoload
449+
(defun test-cockpit--repeat-interactive-test (&optional args)
450+
"Repeat the last interactive test command.
451+
This is not meant to be called directly but as a result the transient dispatch
452+
in order to call the last test action with modified ARGS."
453+
(interactive
454+
(list (transient-args 'test-cockpit-prefix)))
455+
(when-let ((last-cmd (test-cockpit--last-interactive-test-command)))
456+
(funcall last-cmd args)))
457+
458+
438459
(defun test-cockpit--projectile-build (&optional last-cmd)
439460
"Launch a projectile driven build process.
440461
If last executed command LAST-CMD is given the command is
@@ -497,6 +518,10 @@ repetition."
497518
"Get the last switches stored in the current engine."
498519
(oref (test-cockpit--retrieve-engine) last-switches))
499520

521+
(defun test-cockpit--last-interactive-test-command ()
522+
"Get the last interactive test command."
523+
(oref (test-cockpit--retrieve-engine) last-interactive-cmd))
524+
500525
(transient-define-prefix test-cockpit-prefix ()
501526
"Test the project."
502527
:value 'test-cockpit--last-switches
@@ -506,7 +531,7 @@ repetition."
506531
"Setup the main menu common for all projects for testing."
507532
(let ((module-string (or (test-cockpit--current-module-string) (test-cockpit--last-module-string)))
508533
(function-string (or (test-cockpit--current-function-string) (test-cockpit--last-function-string)))
509-
(last-cmd (oref (test-cockpit--real-engine-or-error) last-command)))
534+
(last-cmd (oref (test-cockpit--real-engine-or-error) last-interactive-cmd)))
510535
(vconcat (remove nil (append `("Run tests"
511536
("p" "project" test-cockpit-test-project)
512537
,(if module-string
@@ -519,7 +544,7 @@ repetition."
519544
test-cockpit-test-function))
520545
("c" "custom" test-cockpit-custom-test-command)
521546
,(if last-cmd
522-
`("r" "repeat" test-cockpit-repeat-test))))))))
547+
`("r" "repeat" test-cockpit--repeat-interactive-test))))))))
523548

524549
(defun test-cockpit--strip-project-root (path)
525550
"Strip the project root path from a given PATH."

test/test-cargo.el-test.el

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ mod bar {
239239
(ert-deftest test-cargo-infix ()
240240
(mocker-let
241241
((projectile-project-type () ((:output 'rust-cargo))))
242-
(let ((infix (test-cockpit-infix)))
242+
(let ((infix (test-cockpit--infix)))
243243
(should (and (equal (aref (aref infix 0) 0) "Targets")
244244
(equal (aref (aref infix 0) 1) '("-t" "tests" "--tests"))
245245
(equal (aref (aref infix 0) 2) '("-b" "with benchmarks" "--benches"))

test/test-cask.el-test.el

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
(setq test-cockpit--project-engines nil)
7171
(mocker-let
7272
((projectile-project-type () ((:output 'emacs-cask))))
73-
(let ((infix (test-cockpit-infix)))
73+
(let ((infix (test-cockpit--infix)))
7474
(should
7575
(and (equal (aref infix 0) "Cask specific switches")
7676
(equal (aref infix 1) '("-i" "Run `cask install` before test" "install")))))))

test/test-cockpit.el-test.el

+69
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,37 @@
234234
(test-cockpit-test-function '("foo" "bar"))
235235
(should (equal (test-cockpit--last-switches) '("foo" "bar")))))
236236

237+
238+
(ert-deftest test-transient-repeat-command-no-last-command ()
239+
(tc--register-foo-project "foo")
240+
(mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project"))))
241+
(should (eq (test-cockpit--last-interactive-test-command) nil))))
242+
243+
244+
(ert-deftest test-transient-repeat-command-last-cmd-project ()
245+
(tc--register-foo-project "foo")
246+
(mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project")))
247+
(compile (command) ((:input '("test project") :output 'success))))
248+
(test-cockpit-test-project)
249+
(should (equal (test-cockpit--last-interactive-test-command) 'test-cockpit-test-project))))
250+
251+
252+
(ert-deftest test-transient-repeat-command-last-cmd-module ()
253+
(tc--register-foo-project "foo")
254+
(mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project")))
255+
(compile (command) ((:input '("test module foo-module-string") :output 'success))))
256+
(test-cockpit-test-module)
257+
(should (equal (test-cockpit--last-interactive-test-command) 'test-cockpit-test-module))))
258+
259+
260+
(ert-deftest test-transient-repeat-command-last-cmd-function ()
261+
(tc--register-foo-project "foo")
262+
(mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project")))
263+
(compile (command) ((:input '("test function foo-function-string") :output 'success))))
264+
(test-cockpit-test-function)
265+
(should (equal (test-cockpit--last-interactive-test-command) 'test-cockpit-test-function))))
266+
267+
237268
(ert-deftest test-repeat-test-foo-engine ()
238269
(tc--register-foo-project "foo")
239270
(mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project")))
@@ -581,6 +612,44 @@
581612
(test-cockpit-repeat-test)
582613
(should (equal (test-cockpit--last-custom-command) "some custom command"))))))
583614

615+
(ert-deftest test-interactive-repeat-test-no-last-cmd ()
616+
(tc--register-foo-project "foo")
617+
(mocker-let ((projectile-project-type () ((:output 'foo-project-type)))
618+
(compile (command) ((:input '(_) :output nil :occur 0))))
619+
(test-cockpit--repeat-interactive-test '())))
620+
621+
(ert-deftest test-interactive-repeat-test-project ()
622+
(tc--register-foo-project "foo")
623+
(mocker-let ((projectile-project-type () ((:output 'foo-project-type)))
624+
(compile (command) ((:input '("test project foo bar") :output 'success :occur 1)
625+
(:input '("test project other args") :output 'success :occur 1)
626+
(:input '("test project even other args") :output 'success :occur 1))))
627+
(test-cockpit-test-project '("foo" "bar"))
628+
(test-cockpit--repeat-interactive-test '("other" "args"))
629+
(test-cockpit--repeat-interactive-test '("even" "other" "args"))))
630+
631+
(ert-deftest test-interactive-repeat-test-module ()
632+
(tc--register-foo-project "foo")
633+
(mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project")))
634+
(compile (command) ((:input '("test module foo-module-string foo bar") :output 'success :occur 1)
635+
(:input '("test module foo-module-string other args") :output 'success :occur 1)
636+
(:input '("test module foo-module-string even other args") :output 'success :occur 1))))
637+
(test-cockpit-test-module '("foo" "bar"))
638+
(test-cockpit--repeat-interactive-test '("other" "args"))
639+
(test-cockpit--repeat-interactive-test '("even" "other" "args"))
640+
))
641+
642+
(ert-deftest test-interactive-repeat-test-function ()
643+
(tc--register-foo-project "foo")
644+
(mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project")))
645+
(compile (command) ((:input '("test function foo-function-string foo bar") :output 'success :occur 1)
646+
(:input '("test function foo-function-string other args") :output 'success :occur 1)
647+
(:input '("test function foo-function-string even other args") :output 'success :occur 1))))
648+
(test-cockpit-test-function '("foo" "bar"))
649+
(test-cockpit--repeat-interactive-test '("other" "args"))
650+
(test-cockpit--repeat-interactive-test '("even" "other" "args"))
651+
))
652+
584653
(ert-deftest test-custom-test-command-default-directory ()
585654
(tc--register-foo-project "foo")
586655
(mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project"))))

test/test-mix.el-test.el

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
(setq test-cockpit--project-engines nil)
121121
(mocker-let
122122
((projectile-project-type () ((:output 'elixir))))
123-
(let ((infix (test-cockpit-infix)))
123+
(let ((infix (test-cockpit--infix)))
124124
(should
125125
(and (equal (aref infix 0) "Mix specific switches")
126126
(equal (aref infix 1) '("-r" "Reset Ecto before test" "reset"))

test/test-python.el-test.el

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ async def test_first_outer():
389389

390390
(ert-deftest test-python-python-infix ()
391391
(mocker-let ((projectile-project-type () ((:output 'python-pip))))
392-
(let ((infix (test-cockpit-infix)))
392+
(let ((infix (test-cockpit--infix)))
393393
(should (equal (aref (aref infix 0) 0) "Switches"))
394394
(should (equal (car (aref (aref infix 0) 1)) "-k"))
395395
(should (equal (aref (aref infix 0) 2) '("-f" "only lastly failed tests" "--last-failed")))

0 commit comments

Comments
 (0)