Skip to content

Commit

Permalink
Memorize the last custom command per project (#22)
Browse files Browse the repository at this point in the history
Fix #14
  • Loading branch information
johannes-mueller authored May 19, 2024
1 parent ecc210e commit 2b836e5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
9 changes: 9 additions & 0 deletions test-cockpit.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
56 changes: 55 additions & 1 deletion test/test-cockpit.el-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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"))))
Expand Down

0 comments on commit 2b836e5

Please sign in to comment.