Skip to content

Commit 27dcb63

Browse files
committed
Lay the groundwork of a test suite
1 parent 3cb4c2d commit 27dcb63

File tree

7 files changed

+181
-0
lines changed

7 files changed

+181
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55

66
# Emacs byte-compiled files
77
*.elc
8+
.cask

.travis.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: emacs-lisp
2+
env:
3+
- EMACS=emacs24
4+
- EMACS=emacs-snapshot
5+
before_install:
6+
# Stable Emacs 24.3
7+
- sudo add-apt-repository -y ppa:cassou/emacs
8+
# Nightly Emacs snapshot builds
9+
- sudo add-apt-repository -y ppa:ubuntu-elisp/ppa
10+
# Update and install the Emacs for our environment
11+
- sudo apt-get update -qq
12+
- sudo apt-get install -qq -yy ${EMACS}-nox
13+
# Install and bootstrap cask
14+
- curl -fsSkL https://raw.github.com/cask/cask/master/go | python
15+
- export PATH="${HOME}/.cask/bin:$PATH"
16+
install:
17+
- cask install
18+
script:
19+
- make compile test

Cask

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

Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
CASK = cask
2+
EMACS = emacs
3+
EMACSFLAGS =
4+
TESTFLAGS =
5+
6+
export EMACS
7+
8+
PKGDIR := $(shell EMACS=$(EMACS) $(CASK) package-directory)
9+
10+
SRCS = clojure-mode.el
11+
OBJS = $(SRCS:.el=.elc)
12+
13+
.PHONY: compile test clean
14+
15+
compile: $(OBJS)
16+
17+
clean:
18+
rm -f $(OBJS)
19+
20+
test: $(PKGDIR)
21+
$(CASK) exec ert-runner $(TESTFLAGS)
22+
23+
%.elc : %.el $(PKGDIR)
24+
$(CASK) exec $(EMACS) -Q --batch $(EMACSFLAGS) -f batch-byte-compile $<
25+
26+
$(PKGDIR) : Cask
27+
$(CASK) install
28+
touch $(PKGDIR)

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![travis][badge-travis]][travis]
2+
13
# Clojure Mode
24

35
Provides Emacs font-lock, indentation, and navigation for the
@@ -149,3 +151,5 @@ Copyright © 2007-2014 Jeffrey Chu, Lennart Staflin, Phil Hagelberg, Bozhidar Ba
149151
and [contributors](https://github.com/clojure-emacs/clojure-mode/contributors).
150152

151153
Distributed under the GNU General Public License; type <kbd>C-h C-c</kbd> to view it.
154+
155+
[travis]: https://travis-ci.org/clojure-emacs/clojure-mode

test/clojure-mode-test.el

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
;;; clojure-mode-test.el --- Clojure Mode: Unit test suite -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2014 Bozhidar Batsov <[email protected]>
4+
5+
;; This file is not part of GNU Emacs.
6+
7+
;; This program is free software; you can redistribute it and/or modify
8+
;; it under the terms of the GNU General Public License as published by
9+
;; the Free Software Foundation, either version 3 of the License, or
10+
;; (at your option) any later version.
11+
12+
;; This program is distributed in the hope that it will be useful,
13+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
;; GNU General Public License for more details.
16+
17+
;; You should have received a copy of the GNU General Public License
18+
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
;;; Commentary:
21+
22+
;; The unit test suite of Clojure Mode
23+
24+
;;; Code:
25+
26+
(require 'clojure-mode)
27+
(require 'ert)
28+
29+
30+
;;;; Utilities
31+
32+
(defmacro clojure-test-with-temp-buffer (content &rest body)
33+
"Evaluate BODY in a temporary buffer with CONTENTS."
34+
(declare (debug t)
35+
(indent 1))
36+
`(with-temp-buffer
37+
(insert ,content)
38+
(clojure-mode)
39+
(font-lock-fontify-buffer)
40+
(goto-char (point-min))
41+
,@body))
42+
43+
(defun clojure-test-face-at (pos &optional content)
44+
"Get the face at POS in CONTENT.
45+
46+
If CONTENT is not given, return the face at POS in the current
47+
buffer."
48+
(if content
49+
(clojure-test-with-temp-buffer content
50+
(get-text-property pos 'face))
51+
(get-text-property pos 'face)))
52+
53+
(defconst clojure-test-syntax-classes
54+
[whitespace punctuation word symbol open-paren close-paren expression-prefix
55+
string-quote paired-delim escape character-quote comment-start
56+
comment-end inherit generic-comment generic-string]
57+
"Readable symbols for syntax classes.
58+
59+
Each symbol in this vector corresponding to the syntax code of
60+
its index.")
61+
62+
(defun clojure-test-syntax-at (pos)
63+
"Get the syntax at POS.
64+
65+
Get the syntax class symbol at POS, or nil if there is no syntax a
66+
POS."
67+
(let ((code (syntax-class (syntax-after pos))))
68+
(aref clojure-test-syntax-classes code)))
69+
70+
71+
;;;; Font locking
72+
73+
(ert-deftest clojure-mode-syntax-table/fontify-clojure-keyword ()
74+
:tags '(fontification syntax-table)
75+
(should (eq (clojure-test-face-at 2 "{:something 20}") 'font-lock-constant-face)))
76+
77+
(provide 'clojure-mode-test)
78+
79+
;; Local Variables:
80+
;; indent-tabs-mode: nil
81+
;; End:
82+
83+
;;; clojure-mode-test.el ends here

test/test-helper.el

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
;;; test-helper.el --- Clojure Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2014 Bozhidar Batsov <[email protected]>
4+
5+
;; This file is not part of GNU Emacs.
6+
7+
;; This program is free software; you can redistribute it and/or modify
8+
;; it under the terms of the GNU General Public License as published by
9+
;; the Free Software Foundation, either version 3 of the License, or
10+
;; (at your option) any later version.
11+
12+
;; This program is distributed in the hope that it will be useful,
13+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
;; GNU General Public License for more details.
16+
17+
;; You should have received a copy of the GNU General Public License
18+
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
;;; Commentary:
21+
22+
;; Non-interactive test suite setup for ERT Runner.
23+
24+
;;; Code:
25+
26+
(message "Running tests on Emacs %s" emacs-version)
27+
28+
(let* ((current-file (if load-in-progress load-file-name (buffer-file-name)))
29+
(source-directory (locate-dominating-file current-file "Cask"))
30+
;; Do not load outdated byte code for tests
31+
(load-prefer-newer t))
32+
;; Load the file under test
33+
(load (expand-file-name "clojure-mode" source-directory)))
34+
35+
;; Local Variables:
36+
;; indent-tabs-mode: nil
37+
;; End:
38+
39+
;;; test-helper.el ends here

0 commit comments

Comments
 (0)