-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #119.
- Loading branch information
Showing
3 changed files
with
71 additions
and
86 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,55 @@ | ||
;;; el-test-runner --- test runner for twittering-mode | ||
|
||
(defvar twittering-test-dir nil) | ||
;;; Commentary: | ||
|
||
(when load-file-name | ||
(setq twittering-test-dir (file-name-directory load-file-name)) | ||
(add-to-list 'load-path twittering-test-dir)) | ||
;;; Code: | ||
(require 'test) | ||
(require 'twittering-mode) | ||
|
||
(require 'twittering-mode (expand-file-name "../twittering-mode.el" | ||
twittering-test-dir)) | ||
(require 'test (expand-file-name "./vendor/test.el" | ||
twittering-test-dir)) | ||
(setq twittering-test-dir (file-name-directory | ||
(or load-file-name buffer-file-name))) | ||
|
||
(defun get-fixture (name) | ||
"Read the fixture file specified by NAME." | ||
(when (symbolp name) | ||
(setq name (symbol-name name))) | ||
(let ((fixture-path (expand-file-name | ||
(concat name ".el") | ||
(expand-file-name "fixture" twittering-test-dir)))) | ||
(if (file-exists-p fixture-path) | ||
(with-temp-buffer | ||
(insert-file-contents fixture-path) | ||
(beginning-of-buffer) | ||
(read (current-buffer))) | ||
nil))) | ||
(concat name ".el") | ||
(expand-file-name "fixture" twittering-test-dir)))) | ||
(when (file-exists-p fixture-path) | ||
(with-temp-buffer | ||
(insert-file-contents fixture-path) | ||
(goto-char (point-min)) | ||
(read (current-buffer)))))) | ||
|
||
(defmacro with-network (&rest body) | ||
"Evaluate BODY when the NETWORK env variable is set." | ||
`(when (getenv "NETWORK") | ||
,@body)) | ||
|
||
(defun twittering-run-test () | ||
"Run the test suite." | ||
(interactive) | ||
|
||
(dolist (file-name (directory-files twittering-test-dir)) | ||
(when (string-match "^test-" file-name) | ||
(let ((file-name (expand-file-name file-name twittering-test-dir))) | ||
(load file-name)))) | ||
|
||
(test-run-all-cases) | ||
|
||
(let* ((fail-count (cdr (assoc 'fail test-last-summary))) | ||
(exit-status (if (eq 0 fail-count) 0 1))) | ||
(save-excursion | ||
(set-buffer "*test-result*") | ||
(end-of-buffer) | ||
(search-backward-regexp "" nil t) | ||
(beginning-of-buffer) | ||
(while (search-forward-regexp "\\b\\([0-9]+\\) pass\\b" nil t) | ||
(replace-match | ||
(concat "\033[1m\033[32m" (match-string 0) "\033[0m"))) | ||
|
||
(beginning-of-buffer) | ||
(while (search-forward-regexp "\\b\\([0-9]+\\) fail\\b" nil t) | ||
(let ((pass (string-equal "0" (match-string 1)))) | ||
(replace-match | ||
(concat "\033[1m\033[31m" (match-string 0) "\033[0m")) | ||
(beginning-of-line) | ||
(when (search-forward-regexp "^\\([^:#]+\\):" nil t) | ||
(replace-match | ||
(concat (if pass | ||
"\033[1m\033[32m" | ||
"\033[1m\033[31m") | ||
(match-string 1) | ||
"\033[0m") | ||
nil nil nil 1)) | ||
)) | ||
(princ (buffer-string))) | ||
(terpri) | ||
(when noninteractive | ||
(kill-emacs exit-status)) | ||
)) | ||
(with-current-buffer "*test-result*" | ||
(let* ((buf (buffer-string)) | ||
(failures (car (twittering-extract-matched-substring-all | ||
"Total: [0-9]+ pass, \\([0-9]+\\) fail" | ||
(substring-no-properties buf nil)))) | ||
(exit-status (if (string= "0" failures) | ||
0 | ||
1))) | ||
(when noninteractive | ||
(message "%s" buf) | ||
(kill-emacs exit-status))))) | ||
|
||
(twittering-run-test) | ||
|
||
(provide 'el-test-runner) | ||
;;; el-test-runner.el ends here |
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 |
---|---|---|
@@ -1,29 +1,32 @@ | ||
#!/bin/bash | ||
|
||
emacsen="emacs emacs23 emacs22 emacs21" | ||
emacsen="emacs emacs25 emacs24 emacs23 emacs22 emacs21" | ||
|
||
continue_on_error= | ||
if [ $# -gt 0 ]; then | ||
continue_on_error="yes" | ||
continue_on_error="yes" | ||
fi | ||
exit_status=0 | ||
|
||
for emacs in $(echo ${emacsen}); do | ||
if ! which $emacs 1> /dev/null 2> /dev/null; then | ||
echo "No such executable found: ${emacs}: skipped." | ||
continue | ||
fi | ||
$emacs -q --no-site-file --batch --load $(dirname $0)/el-test-runner.el | ||
exit_status=$? | ||
if [ $exit_status != 0 ]; then | ||
echo "Test failed on $(${emacs} --version | head -n 1)" | ||
if [ -z "${continue_on_error}" ]; then | ||
if ! which $emacs 1> /dev/null 2> /dev/null; then | ||
echo "No such executable found: ${emacs}: skipped." | ||
continue | ||
fi | ||
$emacs -q --no-site-file --batch \ | ||
--load $(dirname $0)/../twittering-mode.el \ | ||
--load $(dirname $0)/vendor/test.el \ | ||
--load $(dirname $0)/el-test-runner.el | ||
exit_status=$? | ||
if [ $exit_status != 0 ]; then | ||
echo "Test failed on $(${emacs} --version | head -n 1)" | ||
if [ -z "${continue_on_error}" ]; then | ||
exit 1 | ||
else | ||
else | ||
echo "sleep 5 secs..." | ||
sleep 5 | ||
fi | ||
fi | ||
fi | ||
fi | ||
done | ||
|
||
exit $exit_status |
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