-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from nlamirault/develop
Release 0.16.0
- Loading branch information
Showing
5 changed files
with
91 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
;; Eric Hansen <[email protected]> | ||
;; | ||
;; URL: https://github.com/nlamirault/phpunit.el | ||
;; Version: 0.15.0 | ||
;; Keywords: php, tests, phpunit | ||
;; Version: 0.16.0 | ||
;; Keywords: tools, php, tests, phpunit | ||
|
||
;; Package-Requires: ((s "1.9.0") (f "0.16.0") (pkg-info "0.5") (cl-lib "0.5") (emacs "24.3")) | ||
|
||
|
@@ -84,7 +84,25 @@ | |
|
||
(defcustom phpunit-configuration-file nil | ||
"The PHPUnit configuration file." | ||
:type '(choice string nil)) | ||
:type '(choice (file :tag "Path to phpunit.xml[.dist]") | ||
(const :tag "Automatically detect the path of phpunit.xml" nil))) | ||
|
||
(defcustom phpunit-bootstrap-file nil | ||
"The PHPUnit bootstrap file." | ||
:type '(choice (file :tag "Path to PHPUnit bootstrap script") | ||
(const :tag "Not specify boostrap script" nil))) | ||
|
||
(defcustom phpunit-colorize nil | ||
"Colorize PHPUnit compilation output buffer." | ||
:type '(choice (const :tag "Do not specific --color argument" nil) | ||
(const :tag "--color=auto" "auto") | ||
(const :tag "--color=never" "never") | ||
(const :tag "--color=always" "always"))) | ||
|
||
(defcustom phpunit-hide-compilation-buffer-if-all-tests-pass nil | ||
"Hide the compilation buffer if all tests pass." | ||
:type 'boolean | ||
:group 'phpunit) | ||
|
||
(defconst php-beginning-of-defun-regexp | ||
(eval-when-compile | ||
|
@@ -115,11 +133,8 @@ | |
"[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]" | ||
"Valid syntax for a character in a PHP label.") | ||
|
||
;; Allow for error navigation after a failed test | ||
(add-hook 'compilation-mode-hook | ||
(lambda () | ||
(interactive) | ||
(add-to-list 'compilation-error-regexp-alist '("^\\(.+\\.php\\):\\([0-9]+\\)$" 1 2)))) | ||
(when phpunit-hide-compilation-buffer-if-all-tests-pass | ||
(add-hook 'compilation-finish-functions 'phpunit--hide-compilation-buffer-if-all-tests-pass)) | ||
|
||
(defvar phpunit-last-group-cache nil) | ||
|
||
|
@@ -147,8 +162,13 @@ | |
(s-concat " " (if (stringp phpunit-arg) phpunit-arg | ||
(s-join " " (mapcar 'shell-quote-argument phpunit-arg))))) | ||
(if phpunit-configuration-file | ||
(s-concat " -c " (shell-quote-argument phpunit-configuration-file)) | ||
(s-concat " -c " (shell-quote-argument (expand-file-name phpunit-configuration-file))) | ||
"") | ||
(if phpunit-bootstrap-file | ||
(s-concat " --bootstrap " (shell-quote-argument (expand-file-name phpunit-bootstrap-file))) | ||
"") | ||
(when phpunit-colorize | ||
(format " --colors=%s" phpunit-colorize)) | ||
" " | ||
args))) | ||
|
||
|
@@ -224,10 +244,28 @@ https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.anno | |
|
||
(defun phpunit-get-compile-command (args) | ||
"Return command string to execute PHPUnit from `ARGS'." | ||
(let ((column-setting-command (format "stty cols %d" (frame-width))) | ||
(command-separator "; ") | ||
(phpunit-command (phpunit-get-program (phpunit-arguments args)))) | ||
(concat column-setting-command command-separator phpunit-command))) | ||
(if (memq system-type '(windows-nt ms-dos)) | ||
(phpunit-get-program (phpunit-arguments args)) | ||
(let ((column-setting-command (format "stty cols %d" (frame-width))) | ||
(command-separator "; ") | ||
(phpunit-command (phpunit-get-program (phpunit-arguments args)))) | ||
(concat column-setting-command command-separator phpunit-command)))) | ||
|
||
(defun phpunit--colorize-compilation-buffer () | ||
"Colorize PHPUnit compilation buffer." | ||
(let ((inhibit-read-only t)) | ||
(ansi-color-apply-on-region compilation-filter-start (point)))) | ||
|
||
(defun phpunit--setup-compilation-buffer () | ||
"Setup hooks for PHPUnit compilation buffer." | ||
(add-hook 'compilation-finish-functions #'phpunit--finish-compilation-buffer) | ||
(add-hook 'compilation-filter-hook #'phpunit--colorize-compilation-buffer)) | ||
|
||
(defun phpunit--finish-compilation-buffer (&optional cur-buffer msg) | ||
"Setup hooks for PHPUnit compilation buffer. | ||
`CUR-BUFFER' and `MSG' are ignore." | ||
(remove-hook 'compilation-finish-functions #'phpunit--finish-compilation-buffer) | ||
(remove-hook 'compilation-filter-hook #'phpunit--colorize-compilation-buffer)) | ||
|
||
(defun phpunit--execute (args) | ||
"Execute phpunit command with `ARGS'." | ||
|
@@ -236,9 +274,32 @@ https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.anno | |
|
||
(defun phpunit-run (args) | ||
"Execute phpunit command with `ARGS'." | ||
(let ((default-directory (phpunit-get-root-directory))) | ||
(add-to-list 'compilation-error-regexp-alist '("^\\(.+\\.php\\):\\([0-9]+\\)$" 1 2)) | ||
(let ((default-directory (phpunit-get-root-directory)) | ||
(compilation-process-setup-function #'phpunit--setup-compilation-buffer)) | ||
(compile (phpunit-get-compile-command args)))) | ||
|
||
(defun phpunit--hide-compilation-buffer-if-all-tests-pass (buffer status) | ||
"Hide the compilation BUFFER if all tests pass. | ||
The STATUS describes how the compilation process finished." | ||
(with-current-buffer buffer | ||
(let* ((buffer-string (buffer-substring-no-properties | ||
(point-min) (point-max))) | ||
(buffer-lines (s-lines buffer-string)) | ||
(ok-msg (car (cl-remove-if-not | ||
(lambda (x) | ||
(and (s-contains? "OK" x) | ||
(s-contains? "test" x) | ||
(s-contains? "assertion" x))) | ||
buffer-lines))) | ||
(time-msg (car (cl-remove-if-not | ||
(lambda (x) | ||
(and (s-contains? "Time" x) | ||
(s-contains? "Memory" x))) | ||
buffer-lines)))) | ||
(when ok-msg | ||
(delete-windows-on buffer) | ||
(message "%s %s" ok-msg time-msg))))) | ||
|
||
;; API | ||
;; ---- | ||
|
@@ -250,7 +311,9 @@ https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.anno | |
(let ((args (s-concat " --filter '" | ||
(phpunit-get-current-class) | ||
"::" | ||
(phpunit-get-current-test) "'"))) | ||
(phpunit-get-current-test) "'" | ||
" " | ||
(s-chop-prefix (phpunit-get-root-directory) buffer-file-name)))) | ||
(phpunit-run args))) | ||
|
||
|
||
|
This file contains 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
This file contains 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
This file contains 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