From 2b836e5f954059210b6efaecebfe5fd7c72e726c Mon Sep 17 00:00:00 2001 From: Johannes Mueller Date: Sun, 19 May 2024 19:47:42 +0200 Subject: [PATCH] Memorize the last custom command per project (#22) Fix #14 --- test-cockpit.el | 9 ++++++ test/test-cockpit.el-test.el | 56 +++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/test-cockpit.el b/test-cockpit.el index 9ee41e6..4aa3e34 100644 --- a/test-cockpit.el +++ b/test-cockpit.el @@ -86,6 +86,8 @@ a derived class of `test-cockpit--engine'.") (last-build-command :initarg :last-build-command :initform nil) (last-test-command :initarg :last-test-command + :initform nil) + (last-custom-command :initarg :last-custom-command :initform nil) (last-module-string :initarg :last-module-string :initform nil) @@ -365,7 +367,10 @@ The command run is then stored in as last command of the project and thus can be repeated using `test-cockpit-repeat-test'." (interactive) (projectile-with-default-dir (projectile-project-root) + (when-let ((last-cmd (test-cockpit--last-custom-command))) + (setq compile-command last-cmd)) (call-interactively #'compile)) + (oset (test-cockpit--retrieve-engine) last-custom-command compile-command) (oset (test-cockpit--retrieve-engine) last-command compile-command)) ;;;###autoload @@ -484,6 +489,10 @@ repetition." "Get the last test command stored in the current engine." (oref (test-cockpit--retrieve-engine) last-test-command)) +(defun test-cockpit--last-custom-command () + "Get the last custom command stored in the current engine." + (oref (test-cockpit--retrieve-engine) last-custom-command)) + (defun test-cockpit--last-switches () "Get the last switches stored in the current engine." (oref (test-cockpit--retrieve-engine) last-switches)) diff --git a/test/test-cockpit.el-test.el b/test/test-cockpit.el-test.el index 228ac7c..560b1b4 100644 --- a/test/test-cockpit.el-test.el +++ b/test/test-cockpit.el-test.el @@ -517,7 +517,7 @@ (test-cockpit-test-or-projectile-test) (test-cockpit-repeat-test-or-projectile-test)))) -(ert-deftest test-custom-test-command () +(ert-deftest test-custom-test-command-compile-command () (tc--register-foo-project "foo") (mocker-let ((projectile-project-type () ((:output 'foo-project-type))) (call-interactively (func) ((:input `(compile) :output 'success :occur 1))) @@ -527,6 +527,60 @@ (test-cockpit-custom-test-command) (test-cockpit-repeat-test)))) +(ert-deftest test-custom-test-memorized-command-called () + (tc--register-foo-project "foo") + (mocker-let ((projectile-project-type () ((:output 'foo-project-type))) + (call-interactively (func) ((:input `(compile) :output 'success :occur 1))) + (compile (command) + ((:input '("memorized command") :output 'success :occur 1))) + (test-cockpit--last-custom-command () ((:output "memorized command")))) + (let ((compile-command "some custom command")) + (test-cockpit-custom-test-command) + (test-cockpit-repeat-test) + (should (equal compile-command "memorized command"))))) + +(ert-deftest test-custom-test-memorized () + (tc--register-foo-project "foo") + (mocker-let ((projectile-project-type () ((:output 'foo-project-type))) + (call-interactively (func) ((:input `(compile) :output 'success :occur 1))) + (compile (command) + ((:input '("some custom command") :output 'success :occur 1)))) + (let ((compile-command "some custom command")) + (test-cockpit-custom-test-command) + (test-cockpit-repeat-test) + (should (equal (test-cockpit--last-custom-command) "some custom command"))))) + +(ert-deftest test-custom-test-memorized-different-projects () + (cl-letf (((symbol-function 'current-project-func) (lambda (_cmd) current-project-root))) + (tc--register-foo-project "foo") + (mocker-let ((projectile-project-type () ((:output 'foo-project-type))) + (projectile-project-root (&optional _dir) + ((:input-matcher (lambda (_) t) :output-generator 'current-project-func))) + (call-interactively (func) ((:input `(compile) :output 'success :occur 4))) + (compile (command) + ((:input '("some custom command") :output 'success :occur 1) + (:input '("other custom command") :output 'success :occur 1) + (:input '("other custom command") :output 'success :occur 1) + (:input '("some custom command") :output 'success :occur 1)))) + (let ((compile-command "some custom command") + (current-project-root "foo-project-1")) + (test-cockpit-custom-test-command) + (test-cockpit-repeat-test) + (should (equal (test-cockpit--last-custom-command) "some custom command"))) + (let ((compile-command "other custom command") + (current-project-root "foo-project-2")) + (test-cockpit-custom-test-command) + (test-cockpit-repeat-test) + (should (equal (test-cockpit--last-custom-command) "other custom command"))) + (let ((current-project-root "foo-project-2")) + (test-cockpit-custom-test-command) + (test-cockpit-repeat-test) + (should (equal (test-cockpit--last-custom-command) "other custom command"))) + (let ((current-project-root "foo-project-1")) + (test-cockpit-custom-test-command) + (test-cockpit-repeat-test) + (should (equal (test-cockpit--last-custom-command) "some custom command")))))) + (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"))))