From 6987c864dd2ec2673546e51ad51761e4241270f8 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Mon, 20 May 2024 18:17:27 +0200 Subject: [PATCH 1/3] Rename test-cockpit-infix to test-cockpit--infix --- test-cockpit.el | 4 ++-- test/test-cargo.el-test.el | 2 +- test/test-cask.el-test.el | 2 +- test/test-mix.el-test.el | 2 +- test/test-python.el-test.el | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test-cockpit.el b/test-cockpit.el index 4aa3e34..9502f04 100644 --- a/test-cockpit.el +++ b/test-cockpit.el @@ -228,7 +228,7 @@ FUNC-STRING is the string determining the function to test." (test-cockpit--make-test-command 'test-cockpit--test-function-command func-string args)) -(defun test-cockpit-infix () +(defun test-cockpit--infix () "Call the infix function of the current project type and return the infix array." (test-cockpit--transient-infix (funcall (alist-get (projectile-project-type) test-cockpit--project-types)))) @@ -238,7 +238,7 @@ FUNC-STRING is the string determining the function to test." (unless (equal (aref (transient-get-suffix 'test-cockpit-prefix '(0)) 2) '(:description "Run test")) (transient-remove-suffix 'test-cockpit-prefix '(0))) - (if-let (infix (test-cockpit-infix)) + (if-let (infix (test-cockpit--infix)) (transient-insert-suffix 'test-cockpit-prefix '(0) infix))) (defun test-cockpit--run-test (command) diff --git a/test/test-cargo.el-test.el b/test/test-cargo.el-test.el index 64f0200..1f3c526 100644 --- a/test/test-cargo.el-test.el +++ b/test/test-cargo.el-test.el @@ -239,7 +239,7 @@ mod bar { (ert-deftest test-cargo-infix () (mocker-let ((projectile-project-type () ((:output 'rust-cargo)))) - (let ((infix (test-cockpit-infix))) + (let ((infix (test-cockpit--infix))) (should (and (equal (aref (aref infix 0) 0) "Targets") (equal (aref (aref infix 0) 1) '("-t" "tests" "--tests")) (equal (aref (aref infix 0) 2) '("-b" "with benchmarks" "--benches")) diff --git a/test/test-cask.el-test.el b/test/test-cask.el-test.el index 7d93a78..3be1f57 100644 --- a/test/test-cask.el-test.el +++ b/test/test-cask.el-test.el @@ -70,7 +70,7 @@ (setq test-cockpit--project-engines nil) (mocker-let ((projectile-project-type () ((:output 'emacs-cask)))) - (let ((infix (test-cockpit-infix))) + (let ((infix (test-cockpit--infix))) (should (and (equal (aref infix 0) "Cask specific switches") (equal (aref infix 1) '("-i" "Run `cask install` before test" "install"))))))) diff --git a/test/test-mix.el-test.el b/test/test-mix.el-test.el index 52728d4..6a96d9d 100644 --- a/test/test-mix.el-test.el +++ b/test/test-mix.el-test.el @@ -120,7 +120,7 @@ (setq test-cockpit--project-engines nil) (mocker-let ((projectile-project-type () ((:output 'elixir)))) - (let ((infix (test-cockpit-infix))) + (let ((infix (test-cockpit--infix))) (should (and (equal (aref infix 0) "Mix specific switches") (equal (aref infix 1) '("-r" "Reset Ecto before test" "reset")) diff --git a/test/test-python.el-test.el b/test/test-python.el-test.el index f1cf219..1cafc67 100644 --- a/test/test-python.el-test.el +++ b/test/test-python.el-test.el @@ -389,7 +389,7 @@ async def test_first_outer(): (ert-deftest test-python-python-infix () (mocker-let ((projectile-project-type () ((:output 'python-pip)))) - (let ((infix (test-cockpit-infix))) + (let ((infix (test-cockpit--infix))) (should (equal (aref (aref infix 0) 0) "Switches")) (should (equal (car (aref (aref infix 0) 1)) "-k")) (should (equal (aref (aref infix 0) 2) '("-f" "only lastly failed tests" "--last-failed"))) From af0192326ec91c19a0f99228d7f14c76d75c42f3 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Mon, 20 May 2024 21:07:14 +0200 Subject: [PATCH 2/3] Honor modified switches when doing interactive repeat Fixes #24 --- test-cockpit.el | 20 ++++++++++- test/test-cockpit.el-test.el | 69 ++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/test-cockpit.el b/test-cockpit.el index 9502f04..2b0af5f 100644 --- a/test-cockpit.el +++ b/test-cockpit.el @@ -95,6 +95,8 @@ a derived class of `test-cockpit--engine'.") :initform nil) (last-args :initarg :last-args :initform nil) + (last-interactive-cmd :initarg :last-interactive-cmd + :initform nil) (is-dummy-engine :initarg :is-dummy-engine :initform nil)) "The base class for a test-cockpit engine. @@ -208,6 +210,10 @@ The additional arguments are shipped as ARGS." (oset engine last-function-string last-function)) (oset engine last-args args))) +(defun test-cockpit--update-last-interactive-command (function) + (let ((engine (test-cockpit--retrieve-engine))) + (oset engine last-interactive-cmd function))) + (defun test-cockpit--make-test-project-command (project-string args) "Call the test-project-command function with ARGS of the current project type. PROJECT-STRING is usually nil. The argument is here to make the function @@ -268,6 +274,7 @@ ARGS is the UI state for language specific settings." (list (transient-args 'test-cockpit-prefix))) (test-cockpit--run-test (test-cockpit--command 'test-cockpit--make-test-project-command nil args)) + (test-cockpit--update-last-interactive-command 'test-cockpit-test-project) (test-cockpit--update-last-commands args)) ;;;###autoload @@ -286,6 +293,7 @@ is tested." (test-cockpit--command 'test-cockpit--make-test-module-command module-string args)) + (test-cockpit--update-last-interactive-command 'test-cockpit-test-module) (test-cockpit--update-last-commands args)) (message "Not in a unit test module file"))) @@ -306,6 +314,7 @@ were in is tested." (test-cockpit--command 'test-cockpit--make-test-function-command function-string args)) + (test-cockpit--update-last-interactive-command 'test-cockpit-test-function) (test-cockpit--update-last-commands args)) (message "Not in a unit test module file"))) @@ -435,6 +444,12 @@ prompt to type a test command is shown." (test-cockpit--repeat-projectile-test) (test-cockpit-repeat-test))) + +(defun test-cockpit--repeat-interactive-test (args) + (when-let ((last-cmd (test-cockpit--last-interactive-test-command))) + (funcall last-cmd args))) + + (defun test-cockpit--projectile-build (&optional last-cmd) "Launch a projectile driven build process. If last executed command LAST-CMD is given the command is @@ -497,6 +512,9 @@ repetition." "Get the last switches stored in the current engine." (oref (test-cockpit--retrieve-engine) last-switches)) +(defun test-cockpit--last-interactive-test-command () + (oref (test-cockpit--retrieve-engine) last-interactive-cmd)) + (transient-define-prefix test-cockpit-prefix () "Test the project." :value 'test-cockpit--last-switches @@ -506,7 +524,7 @@ repetition." "Setup the main menu common for all projects for testing." (let ((module-string (or (test-cockpit--current-module-string) (test-cockpit--last-module-string))) (function-string (or (test-cockpit--current-function-string) (test-cockpit--last-function-string))) - (last-cmd (oref (test-cockpit--real-engine-or-error) last-command))) + (last-cmd (oref (test-cockpit--real-engine-or-error) last-interactive-cmd))) (vconcat (remove nil (append `("Run tests" ("p" "project" test-cockpit-test-project) ,(if module-string diff --git a/test/test-cockpit.el-test.el b/test/test-cockpit.el-test.el index 560b1b4..d2548a0 100644 --- a/test/test-cockpit.el-test.el +++ b/test/test-cockpit.el-test.el @@ -234,6 +234,37 @@ (test-cockpit-test-function '("foo" "bar")) (should (equal (test-cockpit--last-switches) '("foo" "bar"))))) + +(ert-deftest test-transient-repeat-command-no-last-command () + (tc--register-foo-project "foo") + (mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project")))) + (should (eq (test-cockpit--last-interactive-test-command) nil)))) + + +(ert-deftest test-transient-repeat-command-last-cmd-project () + (tc--register-foo-project "foo") + (mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project"))) + (compile (command) ((:input '("test project") :output 'success)))) + (test-cockpit-test-project) + (should (equal (test-cockpit--last-interactive-test-command) 'test-cockpit-test-project)))) + + +(ert-deftest test-transient-repeat-command-last-cmd-module () + (tc--register-foo-project "foo") + (mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project"))) + (compile (command) ((:input '("test module foo-module-string") :output 'success)))) + (test-cockpit-test-module) + (should (equal (test-cockpit--last-interactive-test-command) 'test-cockpit-test-module)))) + + +(ert-deftest test-transient-repeat-command-last-cmd-function () + (tc--register-foo-project "foo") + (mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project"))) + (compile (command) ((:input '("test function foo-function-string") :output 'success)))) + (test-cockpit-test-function) + (should (equal (test-cockpit--last-interactive-test-command) 'test-cockpit-test-function)))) + + (ert-deftest test-repeat-test-foo-engine () (tc--register-foo-project "foo") (mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project"))) @@ -581,6 +612,44 @@ (test-cockpit-repeat-test) (should (equal (test-cockpit--last-custom-command) "some custom command")))))) +(ert-deftest test-interactive-repeat-test-no-last-cmd () + (tc--register-foo-project "foo") + (mocker-let ((projectile-project-type () ((:output 'foo-project-type))) + (compile (command) ((:input '(_) :output nil :occur 0)))) + (test-cockpit--repeat-interactive-test '()))) + +(ert-deftest test-interactive-repeat-test-project () + (tc--register-foo-project "foo") + (mocker-let ((projectile-project-type () ((:output 'foo-project-type))) + (compile (command) ((:input '("test project foo bar") :output 'success :occur 1) + (:input '("test project other args") :output 'success :occur 1) + (:input '("test project even other args") :output 'success :occur 1)))) + (test-cockpit-test-project '("foo" "bar")) + (test-cockpit--repeat-interactive-test '("other" "args")) + (test-cockpit--repeat-interactive-test '("even" "other" "args")))) + +(ert-deftest test-interactive-repeat-test-module () + (tc--register-foo-project "foo") + (mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project"))) + (compile (command) ((:input '("test module foo-module-string foo bar") :output 'success :occur 1) + (:input '("test module foo-module-string other args") :output 'success :occur 1) + (:input '("test module foo-module-string even other args") :output 'success :occur 1)))) + (test-cockpit-test-module '("foo" "bar")) + (test-cockpit--repeat-interactive-test '("other" "args")) + (test-cockpit--repeat-interactive-test '("even" "other" "args")) + )) + +(ert-deftest test-interactive-repeat-test-function () + (tc--register-foo-project "foo") + (mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project"))) + (compile (command) ((:input '("test function foo-function-string foo bar") :output 'success :occur 1) + (:input '("test function foo-function-string other args") :output 'success :occur 1) + (:input '("test function foo-function-string even other args") :output 'success :occur 1)))) + (test-cockpit-test-function '("foo" "bar")) + (test-cockpit--repeat-interactive-test '("other" "args")) + (test-cockpit--repeat-interactive-test '("even" "other" "args")) + )) + (ert-deftest test-custom-test-command-default-directory () (tc--register-foo-project "foo") (mocker-let ((projectile-project-root (&optional _dir) ((:input-matcher (lambda (_) t) :output "foo-project")))) From 0214ea1e605d826d75cf39ded21eff528aac1008 Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Fri, 31 May 2024 22:34:50 +0200 Subject: [PATCH 3/3] Fix calling last interactive test command and add some docs --- test-cockpit.el | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test-cockpit.el b/test-cockpit.el index 2b0af5f..2c34ade 100644 --- a/test-cockpit.el +++ b/test-cockpit.el @@ -445,7 +445,13 @@ prompt to type a test command is shown." (test-cockpit-repeat-test))) -(defun test-cockpit--repeat-interactive-test (args) +;;;###autoload +(defun test-cockpit--repeat-interactive-test (&optional args) + "Repeat the last interactive test command. +This is not meant to be called directly but as a result the transient dispatch +in order to call the last test action with modified ARGS." + (interactive + (list (transient-args 'test-cockpit-prefix))) (when-let ((last-cmd (test-cockpit--last-interactive-test-command))) (funcall last-cmd args))) @@ -513,6 +519,7 @@ repetition." (oref (test-cockpit--retrieve-engine) last-switches)) (defun test-cockpit--last-interactive-test-command () + "Get the last interactive test command." (oref (test-cockpit--retrieve-engine) last-interactive-cmd)) (transient-define-prefix test-cockpit-prefix () @@ -537,7 +544,7 @@ repetition." test-cockpit-test-function)) ("c" "custom" test-cockpit-custom-test-command) ,(if last-cmd - `("r" "repeat" test-cockpit-repeat-test)))))))) + `("r" "repeat" test-cockpit--repeat-interactive-test)))))))) (defun test-cockpit--strip-project-root (path) "Strip the project root path from a given PATH."