Last active
December 11, 2015 15:29
-
-
Save MidLifeXis/4621348 to your computer and use it in GitHub Desktop.
Activating unittest.el in .emacs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (require 'unit-test) | |
| (define-key global-map (kbd "C-c t") 'run-unit-tests) | |
| (define-key global-map (kbd "C-c s") 'set-unit-test-command) | |
| (define-key global-map (kbd "C-c o") 'open-unit-test-file) | |
| ;;; (define-key global-map [(control shift mouse-2)] 'btw/perl-open-class-file) | |
| (defun btw/unit-test-completion-function (buf status) | |
| "Function to run when a unit-test compilation has completed." | |
| (cond ((string-match "finished" status) | |
| (show-test-status 'passed)) | |
| (t (show-test-status 'failed) | |
| )) | |
| ) | |
| (defun btw/perl-unit-test-command () | |
| "Function to run a unit test for perl" | |
| (let | |
| ((process-environment initial-environment) | |
| (compilation-buffer-name-function | |
| (lambda (mymode) (concat "*UnitTest-" | |
| (replace-regexp-in-string | |
| "^UnitTests::" "" | |
| (btw/perl-get-current-package-name)) "*"))) | |
| (compilation-auto-jump-to-first-error t) | |
| ) | |
| (add-to-list 'compilation-finish-functions 'btw/unit-test-completion-function) | |
| (cd default-directory) | |
| (setenv "TEST_CLASS" | |
| (replace-regexp-in-string | |
| "^UnitTests::" "" | |
| (btw/perl-get-current-package-name))) | |
| (setenv "AUTOMATED_TESTING" "1") | |
| (compile | |
| (format "%s %s --timer --merge --lib -It/lib --verbose \"t/200-unittests.t\"" btw/perl-cmd btw/perl-prove-cmd)) | |
| 'handled)) | |
| (defun btw/unit-test-completion-function (buf status) | |
| "Function to run when a unit-test compilation has completed." | |
| (cond ((string-match "finished" status) | |
| (show-test-status 'passed)) | |
| (t (show-test-status 'failed) | |
| )) | |
| ) | |
| (defun btw/perl-unit-test-command () | |
| "Function to run a unit test for perl" | |
| (let | |
| ((process-environment initial-environment) | |
| (compilation-buffer-name-function | |
| (lambda (mymode) (concat "*UnitTest-" | |
| (replace-regexp-in-string | |
| "^UnitTests::" "" | |
| (btw/perl-get-current-package-name)) "*"))) | |
| (compilation-auto-jump-to-first-error t) | |
| ) | |
| (add-to-list 'compilation-finish-functions 'btw/unit-test-completion-function) | |
| (cd default-directory) | |
| (setenv "TEST_CLASS" | |
| (replace-regexp-in-string | |
| "^UnitTests::" "" | |
| (btw/perl-get-current-package-name))) | |
| (setenv "AUTOMATED_TESTING" "1") | |
| (compile | |
| (format "%s %s --timer --merge --lib -It/lib --verbose \"t/200-unittests.t\"" btw/perl-cmd btw/perl-prove-cmd)) | |
| 'handled)) | |
| ;; Run unit tests on Perl files after save | |
| (add-hook 'after-save-hook | |
| #'(lambda () | |
| (and (string-equal mode-name "Perl") (run-unit-tests)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment