diff --git a/.ert-runner b/.ert-runner new file mode 100644 index 0000000..e35e9c9 --- /dev/null +++ b/.ert-runner @@ -0,0 +1 @@ +-L . diff --git a/.travis.yml b/.travis.yml index 46de31d..2d39c1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Cask b/Cask index 4f57af3..82ed87f 100644 --- a/Cask +++ b/Cask @@ -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 + ) diff --git a/Makefile b/Makefile index 761d3a8..9c5476b 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/test/test-checkdoc.el b/test/test-checkdoc.el new file mode 100644 index 0000000..5337e0f --- /dev/null +++ b/test/test-checkdoc.el @@ -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))) diff --git a/test/test-helper.el b/test/test-helper.el new file mode 100644 index 0000000..c1911da --- /dev/null +++ b/test/test-helper.el @@ -0,0 +1,5 @@ +(require 'ert) +(when (require 'undercover nil t) + (undercover "web-beautify.el")) + +(require 'web-beautify) diff --git a/test/test-package-install.el b/test/test-package-install.el new file mode 100644 index 0000000..b8a32dd --- /dev/null +++ b/test/test-package-install.el @@ -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) diff --git a/test/web-beautify-test.el b/test/web-beautify-test.el new file mode 100644 index 0000000..b330ae9 --- /dev/null +++ b/test/web-beautify-test.el @@ -0,0 +1,41 @@ +;;; web-beautify-test.el --- web-beautify: unit test suite + +;; Copyright (C) 2016 Yasuyuki Oka + +;; Author: Yasuyuki Oka +;; 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 . + +;;; 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