Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
- checkdoc
- pakage-lint
- pakage-install
  • Loading branch information
yasuyk committed Nov 5, 2016
1 parent 1ca9841 commit 0c265a4
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 31 deletions.
1 change: 1 addition & 0 deletions .ert-runner
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-L .
44 changes: 28 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
language: emacs-lisp
sudo: false
# Allow Emacs snapshot builds to fail and don’t wait for these as they can take
# a looooong time
matrix:
fast_finish: true
allow_failures:
- env: EMACS_VERSION=snapshot
env:
matrix:
- EMACS=emacs24
# - EMACS=emacs-snapshot
global:
- CASK=$HOME/.cask/bin/cask
- EMACS_VERSION=24.5
- EMACS_VERSION=25.1-rc2
- EMACS_VERSION=snapshot
-cache:
- directories:
- .cask/
before_install:
- sudo add-apt-repository -y ppa:cassou/emacs
- sudo add-apt-repository -y ppa:ubuntu-elisp/ppa
- sudo apt-get update -qq
- sudo apt-get install -qq $EMACS
- if [ "$EMACS" = 'emacs-snapshot' ]; then
sudo apt-get install -qq emacs-snapshot-el emacs-snapshot-nox;
fi
- sudo apt-get install -qq global
- curl -fsSkL --max-time 10 --retry 10 --retry-delay 10
https://raw.github.com/cask/cask/master/go | python
# Configure $PATH: Executables are installed to $HOME/bin
- export PATH="$HOME/bin:$PATH"
# Download the makefile to emacs-travis.mk
- wget 'https://raw.githubusercontent.com/flycheck/emacs-travis/master/emacs-travis.mk'
# Install Emacs (according to $EMACS_VERSION) and Cask
- make -f emacs-travis.mk install_emacs
- make -f emacs-travis.mk install_cask
# Install Texinfo, if you need to build info manuals for your project
# - make -f emacs-travis.mk install_texinfo
install:
# Install your dependencies
- cask install
script:
make test
# Run your tests
- emacs --version
- make travis-ci
7 changes: 7 additions & 0 deletions Cask
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
(source melpa)

(package-file "web-beautify.el")

(development
(depends-on "cask")
(depends-on "package-lint")
(depends-on "ert") ; Unit test library
(depends-on "ert-runner") ; Unit test runner
)
78 changes: 63 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,77 @@
TAEGET ?= web-beautify.el

EMACS ?= emacs
CASK ?= cask
SRC ?= web-beautify.el
TEST_CHECKDOC_EL ?= test/test-checkdoc.el
TEST_PACKAGE_INSTALL_EL ?= test/test-package-install.el
LOADPATH = -L .
ELPA_DIR = $(shell EMACS=$(EMACS) $(CASK) package-directory)

INIT_PACKAGE_EL="(progn (require 'cask) (cask-initialize \".\"))"

.PHONY : test
test: test-checkdoc package-lint test-package-install unit-tests

EMACS ?= emacs
CASK ?= cask
.PHONY : travis-ci
travis-ci: print-deps package-lint test-package-install unit-tests

.PHONY : unit-tests
# `clean-elc` task needs to remove byte-compiled files to collect coverage by undercover.el.
unit-tests: clean-elc elpa
@echo "-- Running unit-tests --"
${CASK} exec ert-runner

.PHONY : clean-elpa
clean-elpa:
rm -rf .cask

.PHONY : clean-elc
clean-elc:
${CASK} clean-elc

ELPA_DIR = \
.cask/$(shell $(EMACS) -Q --batch --eval '(princ emacs-version)')/elpa
.PHONY : clean
clean: clean-elpa clean-elc

test: elpa test-compile
$(CASK) exec $(EMACS) -Q -batch $(LOADPATH) \
$(patsubst %,-l %,$(wildcard test/test-*.el)) \
-f ert-run-tests-batch-and-exit
.PHONY : print-deps
print-deps:
${EMACS} --version
@echo CASK=${CASK}

test/test-%: elpa
$(CASK) exec $(EMACS) -Q -batch $(LOADPATH) \
-l $@ \
-f ert-run-tests-batch-and-exit
.PHONY : test-checkdoc
test-checkdoc: elpa
@echo "-- test ckeckdoc --"
$(CASK) exec $(EMACS) -batch -Q $(LOADPATH) -l $(TEST_CHECKDOC_EL) 2>&1 | tee /dev/tty | [ $$(wc -l) -gt 0 ] && exit 1 || exit 0

test-compile:
$(CASK) exec $(EMACS) -batch -Q -L . -eval "(progn (setq byte-compile-error-on-warn t) (batch-byte-compile))" $(TAEGET)

.PHONY : package-lint
package-lint: elpa
@echo "-- package lint --"
$(CASK) exec $(EMACS) -batch -Q --eval $(INIT_PACKAGE_EL) -l package-lint.el -f package-lint-batch-and-exit $(SRC)

.PHONY : test-package-install
test-package-install: elpa
@echo "-- test install package --"
$(CASK) exec $(EMACS) -batch -Q $(LOADPATH) -l $(TEST_PACKAGE_INSTALL_EL) 2>&1 | tee /dev/tty | grep Error && exit 1 || exit 0

.PHONY : elpa
elpa: $(ELPA_DIR)

$(ELPA_DIR): Cask
$(CASK) install
touch $@

.PHONY : check-coveralls-token
check-coveralls-token:
ifdef COVERALLS_REPO_TOKEN
@true
else
@echo COVERALLS_REPO_TOKEN is undefined
@false
endif

.PHONY : clean-coveralls-report
clean-coveralls-report: check-coveralls-token
@( [ -f /tmp/undercover_coveralls_report ] && rm /tmp/undercover_coveralls_report ) || :

.PHONY : coveralls
coveralls: clean-coveralls-report unit-tests
9 changes: 9 additions & 0 deletions test/test-checkdoc.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(add-to-list 'load-path default-directory)
(defvar web-beautify-el "web-beautify.el")
;; test byte-comple
(mapc #'byte-compile-file `(,web-beautify-el))

;; test checkdoc
(with-current-buffer (find-file-noselect web-beautify-el)
(let ((checkdoc-diagnostic-buffer "*warn*"))
(checkdoc-current-buffer t)))
5 changes: 5 additions & 0 deletions test/test-helper.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(require 'ert)
(when (require 'undercover nil t)
(undercover "web-beautify.el"))

(require 'web-beautify)
19 changes: 19 additions & 0 deletions test/test-package-install.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
(require 'cask)
(cask-initialize ".")
(setq byte-compile-error-on-warn t)
(require 'package)
(package-install-file "web-beautify.el")


(defun should-autoloadp (c)
(let ((s (symbol-function c)))
(unless (autoloadp s)
(message "%s is not autoload" c)
(kill-emacs 1))))

(should-autoloadp 'web-beautify-html)
(should-autoloadp 'web-beautify-css)
(should-autoloadp 'web-beautify-js)
(should-autoloadp 'web-beautify-html-buffer)
(should-autoloadp 'web-beautify-css-buffer)
(should-autoloadp 'web-beautify-js-buffer)
41 changes: 41 additions & 0 deletions test/web-beautify-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
;;; web-beautify-test.el --- web-beautify: unit test suite

;; Copyright (C) 2016 Yasuyuki Oka

;; Author: Yasuyuki Oka <[email protected]>
;; URL: https://github.com/yasuyk/web-beautify

;; 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:

;; Unit test suite of web-beautify

;;; Code:


(eval-when-compile (require 'cl))

(require 'ert)


(provide 'web-beautify-test)

;; Local Variables:
;; coding: utf-8
;; End:

;;; web-beautify-test.el ends here

0 comments on commit 0c265a4

Please sign in to comment.