aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2025-08-01 22:02:50 -0700
committerGravatar Tom Willemse2025-08-01 22:02:50 -0700
commitaa111d30260684d0655b4eb1fb5b1ffaeb35ec03 (patch)
tree7b9725e653bc226f09852c3a83c5949926c72c0f
parent066a07b091167f378f640c10a1693be8d37f8afe (diff)
downloadnew-dotfiles-aa111d30260684d0655b4eb1fb5b1ffaeb35ec03.tar.gz
new-dotfiles-aa111d30260684d0655b4eb1fb5b1ffaeb35ec03.zip
pop-os/emacs: Redo test run commands
Instead of using a Transient, just use several interactive commands. The problem with the transient setup was that it makes you pretend like you're working with a command-line. Which is great when you actually are, but doesn't fit well for just Emacs commands for me so far. With these simplified commands it's all a bit easier to manage.
-rw-r--r--oni/home/config/pop-os/emacs.el160
1 files changed, 110 insertions, 50 deletions
diff --git a/oni/home/config/pop-os/emacs.el b/oni/home/config/pop-os/emacs.el
index 7ce9959..089e650 100644
--- a/oni/home/config/pop-os/emacs.el
+++ b/oni/home/config/pop-os/emacs.el
@@ -27,6 +27,9 @@
(project-root project))
""))
(local-set-key (kbd "C-c c") #'artisan-transient)
+ (local-set-key (kbd "C-c t t") '("Run tests" . artisan-run-test))
+ (local-set-key (kbd "C-c t f") '("Run tests in current file" . artisan-run-current-file-test))
+ (local-set-key (kbd "C-c t p") '("Run Test at point" . artisan-run-test-at-point))
(when (equal major-mode 'php-mode)
(add-hook 'before-save-hook 'snowball-reformat-chanced-file nil t)))))
@@ -48,7 +51,7 @@
("cam" "Migrate" artisan-chanced-migrate)]]
["Commands"
- ("t" "Test" artisan-test-transient)
+ ;; ("t" "Test" artisan-test-transient)
("mm" "Make Migration" artisan-make-migration-transient)])
(defun artisan-punt-composer-install ()
@@ -85,30 +88,31 @@
(let ((default-directory (expand-file-name "chanced" (project-root (project-current)))))
(async-shell-command "docker exec -it chanced-backend php artisan migrate")))
-(transient-define-prefix artisan-test-transient ()
- "Artisan Test."
-
- ["Arguments & Switches"
- ("-b" "Brand" "--brand=" :choices ("chanced" "punt"))
- ("-f" "Stop on failure" "--stop-on-failure")
- ("-p" "Pick test" "--pick")
- ("-P" "Test at point" "--at-point")]
-
- ["Commands"
- ("t" "Test" artisan-chanced-test)])
-
-(defun artisan-chanced-test (&optional args)
- (interactive (list (transient-args transient-current-command)))
- (let ((pick (transient-arg-value "--pick" args))
- (fail (transient-arg-value "--stop-on-failure" args))
- (brand (transient-arg-value "--brand=" args))
- (at-point (transient-arg-value "--at-point" args)))
- (artisan--test-internal pick (or brand "chanced")
- (if (string= brand "punt")
- "chanced"
- "punt")
- fail
- at-point)))
+;; (transient-define-prefix artisan-test-transient ()
+;; "Artisan Test."
+
+;; ["Arguments & Switches"
+;; ("-b" "Brand" "--brand=" :choices ("chanced" "punt"))
+;; ("-f" "Stop on failure" "--stop-on-failure")
+;; ("-p" "Pick test" "--pick")
+;; ("-P" "Test at point" "--at-point")]
+
+;; ;; ["Commands"
+;; ;; ("t" "Test" artisan-chanced-test)]
+;; )
+
+;; (defun artisan-chanced-test (&optional args)
+;; (interactive (list (transient-args transient-current-command)))
+;; (let ((pick (transient-arg-value "--pick" args))
+;; (fail (transient-arg-value "--stop-on-failure" args))
+;; (brand (transient-arg-value "--brand=" args))
+;; (at-point (transient-arg-value "--at-point" args)))
+;; (artisan--test-internal pick (or brand "chanced")
+;; (if (string= brand "punt")
+;; "chanced"
+;; "punt")
+;; fail
+;; at-point)))
(defvar artisan--test-last-state nil
"The last testing commnand that was run in the test buffer.
@@ -116,44 +120,34 @@ This variable should always be buffer local and only set in test
buffers.")
(make-variable-buffer-local 'artisan--test-last-state)
-(defun artisan--test-internal (pick name ignore fail test-at-point-p)
+(defun artisan-run-test (name &optional file filter)
+ (interactive
+ (let* ((refresh current-prefix-arg)
+ (project (nth 1 (read-multiple-choice "Project:" '((?c "chanced" "Chanced")
+ (?p "punt" "Punt")))))
+ (buffer-name (format "*%s Tests*" (capitalize project)))
+ (buffer (get-buffer-create buffer-name)))
+ (append (list project)
+ (unless refresh
+ (with-current-buffer buffer
+ artisan--test-last-state)))))
(let* ((default-directory (expand-file-name name (project-root (project-current))))
(buffer-name (format "*%s Tests*" (capitalize name)))
(buffer (get-buffer-create buffer-name))
- (state (with-current-buffer buffer
- artisan--test-last-state))
- (filter (or (map-elt state 'filter)
- (when test-at-point-p (which-function))))
- (files (unless (map-elt state 'file)
- (cons '("all" . "")
- (mapcar (lambda (dir) (cons (file-name-nondirectory dir) dir))
- (directory-files-recursively "../" (rx "Test.php") nil (lambda (subdir) (not (or (string-suffix-p "vendor" subdir)
- (string-suffix-p "data" subdir)
- (string-suffix-p "cdk.out" subdir)
- (string-suffix-p ignore subdir)))))))))
- (file (or (and (not pick)
- (map-elt state 'file))
- (and test-at-point-p
- (concat "../" (file-relative-name (buffer-file-name) (project-root (project-current)))))
- (map-elt files (completing-read "File: " files nil t))))
(command (with-current-buffer buffer
- (format "../../chanced-scripts/test %s %s %s %s"
+ (format "../../chanced-scripts/test %s %s %s"
name
- (if fail "--stop-on-failure" "")
(if filter (format "--filter=%s" filter) "")
- file)))
- (compilation-scroll-output t))
+ (or file "")))))
(cl-letf (((symbol-function 'compilation-buffer-name)
(lambda (&rest _) buffer-name)))
(compile command))
(with-current-buffer buffer
- (setq artisan--test-last-state
- `((file . ,file)
- (filter . ,filter)))
+ (setq artisan--test-last-state (list file filter))
(local-set-key (kbd "g")
(lambda ()
(interactive)
- (artisan--test-internal nil name ignore fail)))
+ (artisan-run-test name file filter)))
(local-set-key (kbd "q") #'bury-buffer)
(local-set-key (kbd "s") (lambda () (interactive) (interrupt-process)))
(local-set-key (kbd "M-p") (lambda ()
@@ -165,6 +159,72 @@ buffers.")
(forward-line)
(search-forward " •"))))))
+(defun artisan-run-current-file-test (name)
+ (interactive
+ (list (nth 1 (read-multiple-choice "Chanced or Punt? " '((?c "chanced" "Chanced")
+ (?p "punt" "Punt"))))))
+ (let* ((project-root (project-root (project-current)))
+ (file (concat "../" (file-relative-name (buffer-file-name) project-root))))
+ (artisan-run-test name file nil)))
+
+(defun artisan-run-test-at-point (name)
+ (interactive
+ (list (nth 1 (read-multiple-choice "Chanced or Punt? " '((?c "chanced" "Chanced")
+ (?p "punt" "Punt"))))))
+ (let* ((project-root (project-root (project-current)))
+ (file (concat "../" (file-relative-name (buffer-file-name) project-root)))
+ (test (which-function)))
+ (artisan-run-test name file test)))
+
+;; (defun artisan--test-internal (pick name ignore fail test-at-point-p)
+;; (let* ((default-directory (expand-file-name name (project-root (project-current))))
+;; (buffer-name (format "*%s Tests*" (capitalize name)))
+;; (buffer (get-buffer-create buffer-name))
+;; (state ((with-current-buffer buffer
+;; artisan--test-last-state)))
+;; (filter (or (map-elt state 'filter)
+;; (when test-at-point-p (which-function))))
+;; (files (unless (map-elt state 'file)
+;; (cons '("all" . "")
+;; (mapcar (lambda (dir) (cons (file-name-nondirectory dir) dir))
+;; (directory-files-recursively "../" (rx "Test.php") nil (lambda (subdir) (not (or (string-suffix-p "vendor" subdir)
+;; (string-suffix-p "data" subdir)
+;; (string-suffix-p "cdk.out" subdir)
+;; (string-suffix-p ignore subdir)))))))))
+;; (file (or (and (not pick)
+;; (map-elt state 'file))
+;; (and test-at-point-p
+;; (concat "../" (file-relative-name (buffer-file-name) (project-root (project-current)))))
+;; (map-elt files (completing-read "File: " files nil t))))
+;; (command (with-current-buffer buffer
+;; (format "../../chanced-scripts/test %s %s %s %s"
+;; name
+;; (if fail "--stop-on-failure" "")
+;; (if filter (format "--filter=%s" filter) "")
+;; file)))
+;; (compilation-scroll-output t))
+;; (cl-letf (((symbol-function 'compilation-buffer-name)
+;; (lambda (&rest _) buffer-name)))
+;; (compile command))
+;; (with-current-buffer buffer
+;; (setq artisan--test-last-state
+;; `((file . ,file)
+;; (filter . ,filter)))
+;; (local-set-key (kbd "g")
+;; (lambda ()
+;; (interactive)
+;; (artisan--test-internal nil name ignore fail)))
+;; (local-set-key (kbd "q") #'bury-buffer)
+;; (local-set-key (kbd "s") (lambda () (interactive) (interrupt-process)))
+;; (local-set-key (kbd "M-p") (lambda ()
+;; (interactive)
+;; (forward-line -1)
+;; (search-backward " •")))
+;; (local-set-key (kbd "M-n") (lambda ()
+;; (interactive)
+;; (forward-line)
+;; (search-forward " •"))))))
+
(transient-define-prefix artisan-make-migration-transient ()
"Make migration."