Skip to content

Commit 8d8ec41

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 8d465b9 commit 8d8ec41

File tree

4 files changed

+173
-0
lines changed

4 files changed

+173
-0
lines changed

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: generic
2+
sudo: false
3+
before_install:
4+
- curl -fsSkL https://gist.github.com/rejeep/ebcd57c3af83b049833b/raw > x.sh && source ./x.sh
5+
- evm install $EVM_EMACS --use --skip
6+
- cask
7+
env:
8+
- EVM_EMACS=emacs-24.3-travis
9+
- EVM_EMACS=emacs-24.4-travis
10+
- EVM_EMACS=emacs-24.5-travis
11+
- EVM_EMACS=emacs-25.1-travis
12+
- EVM_EMACS=emacs-25.2-travis
13+
- EVM_EMACS=emacs-25.3-travis
14+
script:
15+
- emacs --version
16+
- cask install
17+
- cask exec ./run_tests.sh

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: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
`(ert-with-test-buffer (,@args)
41+
(inf-clojure-minor-mode)
42+
(insert ,initial-contents)
43+
,@body))
44+
45+
(defun ict-bounds-string (bounds)
46+
(buffer-substring (car bounds) (cdr bounds)))
47+
48+
(ert-deftest clojure-expr-break-chars-tests ()
49+
(ict-with-minor-mode-buffer
50+
(:name "clojure-expr-break-chars")
51+
"plain-text"
52+
(should
53+
(string-equal
54+
"plain-text"
55+
(ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point))))
56+
57+
(erase-buffer)
58+
(insert "@")
59+
(goto-char 2)
60+
(should
61+
(null (inf-clojure-completion-bounds-of-expr-at-point)))
62+
63+
(erase-buffer)
64+
(insert "@text-with-deref")
65+
(goto-char 6) ;; arbitrary in the middle of the string
66+
(should
67+
(string-equal
68+
"text-with-deref"
69+
(ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point))))
70+
71+
(erase-buffer)
72+
(insert "^")
73+
(goto-char 2)
74+
(should
75+
(null (inf-clojure-completion-bounds-of-expr-at-point)))
76+
77+
(erase-buffer)
78+
(insert "^:")
79+
(should
80+
(string-equal
81+
":"
82+
(ict-bounds-string (inf-clojure-completion-bounds-of-expr-at-point))))))
83+
84+
;;; inf-clojure-tests.el ends here

0 commit comments

Comments
 (0)