Skip to content

Commit

Permalink
Lay the groundwork of a test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov committed May 30, 2014
1 parent 3cb4c2d commit 27dcb63
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@

# Emacs byte-compiled files
*.elc
.cask
19 changes: 19 additions & 0 deletions .travis.yml
@@ -0,0 +1,19 @@
language: emacs-lisp
env:
- EMACS=emacs24
- EMACS=emacs-snapshot
before_install:
# Stable Emacs 24.3
- sudo add-apt-repository -y ppa:cassou/emacs
# Nightly Emacs snapshot builds
- sudo add-apt-repository -y ppa:ubuntu-elisp/ppa
# Update and install the Emacs for our environment
- sudo apt-get update -qq
- sudo apt-get install -qq -yy ${EMACS}-nox
# Install and bootstrap cask
- curl -fsSkL https://raw.github.com/cask/cask/master/go | python
- export PATH="${HOME}/.cask/bin:$PATH"
install:
- cask install
script:
- make compile test
7 changes: 7 additions & 0 deletions Cask
@@ -0,0 +1,7 @@
(source gnu)
(source melpa)

(package-file "clojure-mode.el")

(development
(depends-on "ert-runner"))
28 changes: 28 additions & 0 deletions Makefile
@@ -0,0 +1,28 @@
CASK = cask
EMACS = emacs
EMACSFLAGS =
TESTFLAGS =

export EMACS

PKGDIR := $(shell EMACS=$(EMACS) $(CASK) package-directory)

SRCS = clojure-mode.el
OBJS = $(SRCS:.el=.elc)

.PHONY: compile test clean

compile: $(OBJS)

clean:
rm -f $(OBJS)

test: $(PKGDIR)
$(CASK) exec ert-runner $(TESTFLAGS)

%.elc : %.el $(PKGDIR)
$(CASK) exec $(EMACS) -Q --batch $(EMACSFLAGS) -f batch-byte-compile $<

$(PKGDIR) : Cask
$(CASK) install
touch $(PKGDIR)
4 changes: 4 additions & 0 deletions README.md
@@ -1,3 +1,5 @@
[![travis][badge-travis]][travis]

# Clojure Mode

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

Distributed under the GNU General Public License; type <kbd>C-h C-c</kbd> to view it.

[travis]: https://travis-ci.org/clojure-emacs/clojure-mode
83 changes: 83 additions & 0 deletions test/clojure-mode-test.el
@@ -0,0 +1,83 @@
;;; clojure-mode-test.el --- Clojure Mode: Unit test suite -*- lexical-binding: t; -*-

;; Copyright (C) 2014 Bozhidar Batsov <bozhidar@batsov.com>

;; This file is not part of GNU Emacs.

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; The unit test suite of Clojure Mode

;;; Code:

(require 'clojure-mode)
(require 'ert)


;;;; Utilities

(defmacro clojure-test-with-temp-buffer (content &rest body)
"Evaluate BODY in a temporary buffer with CONTENTS."
(declare (debug t)
(indent 1))
`(with-temp-buffer
(insert ,content)
(clojure-mode)
(font-lock-fontify-buffer)
(goto-char (point-min))
,@body))

(defun clojure-test-face-at (pos &optional content)
"Get the face at POS in CONTENT.
If CONTENT is not given, return the face at POS in the current
buffer."
(if content
(clojure-test-with-temp-buffer content
(get-text-property pos 'face))
(get-text-property pos 'face)))

(defconst clojure-test-syntax-classes
[whitespace punctuation word symbol open-paren close-paren expression-prefix
string-quote paired-delim escape character-quote comment-start
comment-end inherit generic-comment generic-string]
"Readable symbols for syntax classes.
Each symbol in this vector corresponding to the syntax code of
its index.")

(defun clojure-test-syntax-at (pos)
"Get the syntax at POS.
Get the syntax class symbol at POS, or nil if there is no syntax a
POS."
(let ((code (syntax-class (syntax-after pos))))
(aref clojure-test-syntax-classes code)))


;;;; Font locking

(ert-deftest clojure-mode-syntax-table/fontify-clojure-keyword ()
:tags '(fontification syntax-table)
(should (eq (clojure-test-face-at 2 "{:something 20}") 'font-lock-constant-face)))

(provide 'clojure-mode-test)

;; Local Variables:
;; indent-tabs-mode: nil
;; End:

;;; clojure-mode-test.el ends here
39 changes: 39 additions & 0 deletions test/test-helper.el
@@ -0,0 +1,39 @@
;;; test-helper.el --- Clojure Mode: Non-interactive unit-test setup -*- lexical-binding: t; -*-

;; Copyright (C) 2014 Bozhidar Batsov <bozhidar@batsov.com>

;; This file is not part of GNU Emacs.

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Non-interactive test suite setup for ERT Runner.

;;; Code:

(message "Running tests on Emacs %s" emacs-version)

(let* ((current-file (if load-in-progress load-file-name (buffer-file-name)))
(source-directory (locate-dominating-file current-file "Cask"))
;; Do not load outdated byte code for tests
(load-prefer-newer t))
;; Load the file under test
(load (expand-file-name "clojure-mode" source-directory)))

;; Local Variables:
;; indent-tabs-mode: nil
;; End:

;;; test-helper.el ends here

0 comments on commit 27dcb63

Please sign in to comment.