Skip to content

Commit bc14f8a

Browse files
committed
Add test harness (finally?)
This patch add ert test harness and some tests around the inf-clojure-completion-bounds-of-expr-at-point function.
1 parent d5e6ac0 commit bc14f8a

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed

Cask

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
(source gnu)
2+
(source melpa)
3+
4+
(package-file "inf-clojure.el")
5+
6+
(files "*.el" (:exclude ".dir-locals.el"))
7+
8+
(development
9+
(depends-on "clojure-mode")
10+
(depends-on "ert-runner"))

run-tests.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/sh
2+
#
3+
# Copyright © 2014-2018 Bozhidar Batsov
4+
# Authors: Bozhidar Batsov <[email protected]>
5+
# Andrea Richiardi <[email protected]>
6+
# URL: http://github.com/clojure-emacs/inf-clojure
7+
8+
# This file is part of GNU Emacs.
9+
10+
# GNU Emacs is free software: you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License as published by
12+
# the Free Software Foundation, either version 3 of the License, or
13+
# (at your option) any later version.
14+
15+
# GNU Emacs is distributed in the hope that it will be useful,
16+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
# GNU General Public License for more details.
19+
20+
# You should have received a copy of the GNU General Public License
21+
# along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22+
23+
# This runs the test for emacs inf-clojure.
24+
# Either $EMACS must be set, or it must be possible to find emacs via PATH.
25+
26+
if [ -z "$EMACS" ]; then
27+
EMACS=emacs
28+
fi
29+
30+
$EMACS --batch || {
31+
echo "You must set EMACS to a program that runs emacs."
32+
exit 1
33+
}
34+
35+
$( $EMACS -batch > /dev/null 2>&1 ) || {
36+
echo "Your emacs command ($EMACS) does not run properly."
37+
exit 2
38+
};
39+
40+
$( $EMACS -batch --eval "(require 'ert)" > /dev/null 2>&1 ) || {
41+
echo 'You must install the `ert` dependency; see README.md'
42+
exit 3
43+
};
44+
45+
# All the files inf-clojure depends on (in dependency order!)
46+
DEPS_INCLUDES="-l inf-clojure.el"
47+
48+
WARNINGS="$($EMACS -Q -batch $DEPS_INCLUDES -f batch-byte-compile inf-clojure.el 2>&1 | grep -v '^Wrote ')"
49+
if [ -n "$WARNINGS" ]; then
50+
echo "Byte-compilation failed:"
51+
echo "$WARNINGS"
52+
rm *.elc
53+
exit 4
54+
else
55+
rm *.elc
56+
echo "Byte-compilation passed."
57+
fi
58+
59+
TEST_INCLUDES=$(ls test/*.el | sed -e 's/^/-l /' | xargs)
60+
61+
# Note that the order of the -l counts
62+
$EMACS -batch -l ert $DEPS_INCLUDES -l inf-clojure.el $TEST_INCLUDES -f ert-run-tests-batch-and-exit

test/inf-clojure-tests.el

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
;;; inf-clojure-tests.el --- Tests for Inf-Clojure -*- lexical-binding: t; -*-
2+
;;
3+
;; Copyright © 2014-2018 Bozhidar Batsov
4+
5+
;; Authors: Bozhidar Batsov <[email protected]>
6+
;; Andrea Richiardi <[email protected]>
7+
;; URL: http://github.com/clojure-emacs/inf-clojure
8+
;; Keywords: processes, clojure
9+
;; Package-Requires: ((emacs "24.4") (clojure-mode "5.3"))
10+
11+
;; This file is part of GNU Emacs.
12+
13+
;; GNU Emacs is free software: you can redistribute it and/or modify
14+
;; it under the terms of the GNU General Public License as published by
15+
;; the Free Software Foundation, either version 3 of the License, or
16+
;; (at your option) any later version.
17+
18+
;; GNU Emacs is distributed in the hope that it will be useful,
19+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
;; GNU General Public License for more details.
22+
23+
;; You should have received a copy of the GNU General Public License
24+
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25+
26+
;;; Commentary:
27+
;;
28+
;; Code completion using alexander-yakushev/compliment.
29+
30+
;;; Code:
31+
32+
;; Tests for inf-clojure.el
33+
34+
(message "Running tests on Emacs %s" emacs-version)
35+
36+
(require 'ert-x)
37+
(require 'inf-clojure)
38+
39+
(cl-defmacro ict-with-minor-mode-buffer ((&rest args) initial-contents &body body)
40+
(declare (indent 2))
41+
`(ert-with-test-buffer (,@args)
42+
(inf-clojure-minor-mode)
43+
(insert ,initial-contents)
44+
,@body))
45+
46+
(defun ict-bounds-string (bounds)
47+
(buffer-substring (car bounds) (cdr bounds)))
48+
49+
(ert-deftest clojure-expr-break-chars-tests ()
50+
(ict-with-minor-mode-buffer
51+
(:name "clojure-expr-break-chars")
52+
"plain-text"
53+
(should
54+
(string-equal
55+
"plain-text"
56+
(ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point))))
57+
58+
(erase-buffer)
59+
(insert "@text-with-deref")
60+
(should
61+
(string-equal
62+
"text-with-deref"
63+
(ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point)))))
64+
65+
66+
67+
)
68+
69+
70+
71+
;;; inf-clojure-tests.el ends here

0 commit comments

Comments
 (0)