Skip to content

Commit

Permalink
[tests] get make check working
Browse files Browse the repository at this point in the history
Fixes #119.
  • Loading branch information
dunn committed Apr 2, 2017
1 parent 6c96f92 commit 04e8963
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 86 deletions.
79 changes: 31 additions & 48 deletions test/el-test-runner.el
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
31 changes: 17 additions & 14 deletions test/run-test.sh
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
47 changes: 23 additions & 24 deletions test/test-twittering-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,17 @@
'("http_proxy=http://proxy1.example.com:8080/"))))))

(defcase test-user-agent nil nil
(test-assert-string-equal (format "Emacs/%d.%d Twittering-mode/%s"
emacs-major-version
emacs-minor-version
twittering-mode-version)
(twittering-user-agent))
(setq twittering-user-agent-function
(lambda () "foo user agent"))
(test-assert-string-equal "foo user agent"
(twittering-user-agent))
)
(progn
(setq twittering-user-agent-function 'twittering-user-agent-default-function)
(test-assert-string-equal (format "Emacs/%d.%d Twittering-mode/%s"
emacs-major-version
emacs-minor-version
twittering-mode-version)
(twittering-user-agent)))
(progn
(setq twittering-user-agent-function (lambda () "foo user agent"))
(test-assert-string-equal "foo user agent"
(twittering-user-agent))))

(defcase test-icon-mode nil nil
(setq twittering-icon-mode nil)
Expand Down Expand Up @@ -132,7 +133,7 @@
(case-string "Manaka"
(("Rinko") "Kobayakawa")
(t "unknown")))

(test-assert-string-equal "Kobayakawa"
(case-string "Rinko"
(("Manaka") "Takane")
Expand Down Expand Up @@ -367,11 +368,10 @@
(defcase test-format-status nil nil
(test-assert-string-equal "hello world"
(format-status status "hello world"))

(test-assert-string-equal "%"
(format-status status "%%"))



(test-assert-string-equal "something like emacs"
(format-status status "something like %s"))

Expand Down Expand Up @@ -504,24 +504,23 @@
(oldest-status (car (last (get-fixture 'timeline-data)))))
(format-status oldest-status "\n%FILL[ ]{%T // from %f%L%r}")))

(test-assert-string-equal
(if (> 22 emacs-major-version)
;; `fill-region' on Emacs21 does not keep white spaces and
;; tabs adjacent to hard newlines.
"
(when (> 22 emacs-major-version)
(test-assert-string-equal
;; `fill-region' on Emacs21 does not keep white spaces and
;; tabs adjacent to hard newlines.
"
--Edit XHTML5 documents in nxml-mode with on-the-fly validation:
--http://bit.ly/lYnEg
--
-- (by @hober) // from web"
"
--Edit XHTML5 documents in nxml-mode with on-the-fly validation:
--http://bit.ly/lYnEg
--
-- (by @hober) // from web")
(let ((twittering-fill-column 80)
(oldest-status (car (last (get-fixture 'timeline-data)))))
(format-status oldest-status "\n%FOLD[--]{%T // from %f%L%r}")))
))
--
-- (by @hober) // from web"
(let ((twittering-fill-column 80)
(oldest-status (car (last (get-fixture 'timeline-data)))))
(format-status oldest-status "\n%FOLD[--]{%T // from %f%L%r}"))))))

(defcase test-find-curl-program nil nil
(test-assert-string-match "curl" (twittering-find-curl-program))
Expand Down

0 comments on commit 04e8963

Please sign in to comment.