public
Description: Emacs unit test front-end
Homepage: http://nschum.de/src/emacs/test-case-mode/
Clone URL: git://github.com/ieure/test-case-mode.git
test-case-mode / test-case-phpunit.el
100644 88 lines (76 sloc) 3.033 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
;; test-case-phpunit.el --- PHPUnit support for test-case-mode
;;
;; Copyright (C) 2009 Ian Eure
;;
;; Author: Ian Eure <ian.eure@gmail.com>
;; Version: 1.0
;; Keywoards: testing
;; URL: http://github.com/ieure/test-case-mode
;; Compatibility: GNU Emacs 22.x, GNU Emacs 23.x
;; Package-Requires: ((fringe-helper "0.1.1") (test-case-mode "0.1"))
;;
;; This file is NOT part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 2
;; of the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>
;;
;; Commentary:
;;
;; `test-case-phpunit' adds PHPUnit support to test-case-mode.
;;
;; Installation:
;;
;; Place in your `load-path', then:
;; (require 'test-case-phpunit)
 
(require 'test-case-mode)
 
(defcustom test-case-phpunit-executable (executable-find "phpunit")
  "The phpunit executable used to run PHPUnit tests."
  :group 'test-case
  :type 'file)
 
(defcustom test-case-phpunit-arguments ""
  "The command line arguments used to run PHPUnit tests."
  :group 'test-case
  :type 'string)
 
(defconst test-case-phpunit-failure-pattern
  '("^[0-9]+)\s+\\(.*\\)\n\\(Failed.*\\)\n\\([^:]+\\):\\([0-9]+\\)"
    3 4 nil 2 0)
  "Regular expression for matchin PHPUnit failute output.")
 
(defconst test-case-phpunit-test-pattern
  "\\<extends\\>.*Tests?_?\\(Case\\|Suite\\)?"
  "Regular expression for locating classes which extend PHPUnit.")
 
(defconst test-case-phpunit-font-lock-keywords
  '("\\<$this->assert[^\s(]+\\>"
    (0 'test-case-assertion prepend))
  "Regular expression for PHPUnit assertions.")
 
(defconst test-case-phpunit-class-pattern
  "class\s+\\([^\s]*Test[^\s]*\\)"
  "Regular expression for matchin PHPUnit test class names.")
 
(defun test-case-phpunit-find-test-class ()
  "Determine the name of the test class"
  (test-case-grep test-case-phpunit-class-pattern))
 
(defun test-case-phpunit-backend (command)
  "PHPUnit back-end for `test-case-mode'."
  (case command
    ('name "PHPUnit")
    ('supported (and (derived-mode-p 'php-mode)
                     (test-case-grep test-case-phpunit-test-pattern)
                     t))
    ('command (format "%s %s %s %s" test-case-phpunit-executable
                      test-case-phpunit-arguments
                      (test-case-phpunit-find-test-class)
                      buffer-file-name))
    ('save t)
    ('failure-pattern test-case-phpunit-failure-pattern)
    ('font-lock-keywords test-case-phpunit-font-lock-keywords)))
 
(add-to-list 'test-case-backends 'test-case-phpunit-backend)
 
(provide 'test-case-phpunit)