Skip to content

Instantly share code, notes, and snippets.

@MidLifeXis
Last active December 11, 2015 15:29
Show Gist options
  • Select an option

  • Save MidLifeXis/4621348 to your computer and use it in GitHub Desktop.

Select an option

Save MidLifeXis/4621348 to your computer and use it in GitHub Desktop.
Activating unittest.el in .emacs
(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