Change how unit tests are set up and run
Moves init.test.el to core/test/init.el and initializes the test environment from within the current session, rather than through a bash script middle man. TODO: don't buffer the unit test results
This commit is contained in:
parent
af26a14230
commit
aad0b2f842
5 changed files with 74 additions and 110 deletions
1
bin/doom
1
bin/doom
|
@ -7,7 +7,6 @@
|
||||||
":"; [ "$1" = -d ] || [ "$1" = --debug ] && { shift; export DEBUG=1; }
|
":"; [ "$1" = -d ] || [ "$1" = --debug ] && { shift; export DEBUG=1; }
|
||||||
":"; [ "$1" = doc ] || [ "$1" = doctor ] && { cd "$DOOMBASE"; shift; exec $EMACS --script bin/doom-doctor "$@"; exit 0; }
|
":"; [ "$1" = doc ] || [ "$1" = doctor ] && { cd "$DOOMBASE"; shift; exec $EMACS --script bin/doom-doctor "$@"; exit 0; }
|
||||||
":"; [ "$1" = run ] && { cd "$DOOMBASE"; shift; exec $EMACS -q --no-splash -l bin/doom "$@"; exit 0; }
|
":"; [ "$1" = run ] && { cd "$DOOMBASE"; shift; exec $EMACS -q --no-splash -l bin/doom "$@"; exit 0; }
|
||||||
":"; [ "$1" = test ] && { cd "$DOOMBASE"; shift; exec bin/doom-test "$@"; }
|
|
||||||
":"; exec $EMACS --script "$0" -- "$@"
|
":"; exec $EMACS --script "$0" -- "$@"
|
||||||
":"; exit 0
|
":"; exit 0
|
||||||
|
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Set up test config
|
|
||||||
export DOOMDIR=/tmp/doom/
|
|
||||||
export DOOMLOCALDIR=/tmp/doom/.local/
|
|
||||||
if [[ ! -d "$DOOMDIR" ]]; then
|
|
||||||
mkdir -p "$DOOMDIR"
|
|
||||||
ln -s ~/.emacs.d/init.test.el "$DOOMDIR"/init.el
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Set up testing library
|
|
||||||
BUTTERCUPLIB="${DOOMLOCALDIR}buttercup"
|
|
||||||
EMACSBIN="emacs --batch -l ~/.emacs.d/init.el -L $BUTTERCUPLIB -l buttercup"
|
|
||||||
if [[ ! -d "$BUTTERCUPLIB" ]]; then
|
|
||||||
git clone https://github.com/jorgenschaefer/emacs-buttercup "$BUTTERCUPLIB"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run the tests
|
|
||||||
if [[ ! -f $DOOMLOCALDIR/init || $1 == "-f" ]]; then
|
|
||||||
doom -y refresh
|
|
||||||
echo 1 > $DOOMLOCALDIR/init
|
|
||||||
fi
|
|
||||||
echo
|
|
||||||
echo
|
|
||||||
error=
|
|
||||||
args=( $@ )
|
|
||||||
(( $# == 0 )) && args=( core modules/*/* )
|
|
||||||
for base in $args; do
|
|
||||||
if [[ -d "$base/test" ]]; then
|
|
||||||
echo Running $base
|
|
||||||
$EMACSBIN -f doom-run-tests "$base" || error=1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
[[ $error ]] && exit 1
|
|
137
core/cli/test.el
137
core/cli/test.el
|
@ -1,75 +1,66 @@
|
||||||
;;; core/cli/test.el -*- lexical-binding: t; -*-
|
;;; core/cli/test.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
(defcli! test ()
|
(defcli! test (&rest targets)
|
||||||
"Run Doom unit tests.")
|
"Run Doom unit tests."
|
||||||
|
(let (files error)
|
||||||
|
(unless targets
|
||||||
;;
|
(setq targets
|
||||||
;;; Library
|
(cons doom-core-dir
|
||||||
|
(cl-remove-if-not
|
||||||
(defun doom-run-tests ()
|
(lambda (path) (file-in-directory-p path doom-emacs-dir))
|
||||||
"Discover and load test files, then run all defined suites.
|
;; Omit `doom-private-dir', which is always first
|
||||||
|
(let (doom-modules)
|
||||||
Takes directories as command line arguments, defaulting to the
|
(load! "test/init" doom-core-dir)
|
||||||
current directory."
|
(cdr (doom-module-load-path)))))))
|
||||||
(let ((dirs nil)
|
(while targets
|
||||||
(patterns nil)
|
(let ((target (pop targets)))
|
||||||
(args command-line-args-left)
|
(cond ((equal target ":core")
|
||||||
(doom-modules (doom-modules)))
|
(appendq! files (nreverse (doom-glob doom-core-dir "test/test-*.el"))))
|
||||||
(doom-load-autoloads-file doom-autoload-file)
|
((file-directory-p target)
|
||||||
(doom-load-autoloads-file doom-package-autoload-file)
|
(setq target (expand-file-name target))
|
||||||
(while args
|
(appendq! files (nreverse (doom-glob target "test/test-*.el"))))
|
||||||
(cond
|
((file-exists-p target)
|
||||||
;; ((member (car args) '("--traceback"))
|
(push target files)))))
|
||||||
;; (when (not (cdr args))
|
(require 'restart-emacs)
|
||||||
;; (error "Option requires argument: %s" (car args)))
|
(with-temp-buffer
|
||||||
;; ;; Make sure it's a valid style by trying to format a dummy
|
(setenv "DOOMDIR" (concat doom-core-dir "test/"))
|
||||||
;; ;; frame with it
|
(setenv "DOOMLOCALDIR" (concat doom-local-dir "test/"))
|
||||||
;; (buttercup--format-stack-frame '(t myfun 1 2) (intern (cadr args)))
|
(print! (start "Bootstrapping test environment, if necessary..."))
|
||||||
;; (setq buttercup-stack-frame-style (intern (cadr args)))
|
(if (zerop
|
||||||
;; (setq args (cddr args)))
|
(call-process
|
||||||
;; ((member (car args) '("-p" "--pattern"))
|
(restart-emacs--get-emacs-binary)
|
||||||
;; (when (not (cdr args))
|
nil t nil "--batch"
|
||||||
;; (error "Option requires argument: %s" (car args)))
|
"-l" (concat doom-core-dir "core.el")
|
||||||
;; (push (cadr args) patterns)
|
"--eval" (prin1-to-string
|
||||||
;; (setq args (cddr args)))
|
`(progn (doom-initialize 'force)
|
||||||
;; ((member (car args) '("-c" "--no-color"))
|
(doom-initialize-modules)
|
||||||
;; (setq buttercup-color nil)
|
(require 'core-cli)
|
||||||
;; (setq args (cdr args)))
|
(unless (package-installed-p 'buttercup)
|
||||||
(t
|
(package-refresh-contents)
|
||||||
(push (car args) dirs)
|
(package-install 'buttercup))
|
||||||
(setq args (cdr args)))))
|
(doom-reload-core-autoloads 'force)
|
||||||
(setq command-line-args-left nil)
|
(when (doom-packages-install 'auto-accept)
|
||||||
(dolist (dir (or dirs '(".")))
|
(doom-reload-package-autoloads 'force))))))
|
||||||
(setq dir (if (string= dir "core")
|
(message "%s" (buffer-string))
|
||||||
doom-core-dir
|
(message "%s" (buffer-string))
|
||||||
(expand-file-name dir doom-modules-dir)))
|
(error "Failed to bootstrap unit tests")))
|
||||||
(let ((test-dir (expand-file-name "test" dir)))
|
(dolist (file files)
|
||||||
(when (or (string= dir doom-core-dir)
|
(if (doom-file-cookie-p file)
|
||||||
(cl-destructuring-bind (category . module)
|
(with-temp-buffer
|
||||||
(or (doom-module-from-path dir)
|
(unless
|
||||||
(cons nil nil))
|
(zerop
|
||||||
(and category module (doom-module-p category module))))
|
(call-process
|
||||||
(dolist (file (nreverse (doom-glob test-dir "test-*.el")))
|
(restart-emacs--get-emacs-binary)
|
||||||
(when (doom-file-cookie-p file)
|
nil t nil "--batch"
|
||||||
(load file nil t))))))
|
"-l" (concat doom-core-dir "core.el")
|
||||||
(when patterns
|
"-l" (concat doom-core-dir "test/helpers.el")
|
||||||
(dolist (spec (buttercup--specs buttercup-suites))
|
"--eval" (prin1-to-string `(doom-initialize 'force))
|
||||||
(let ((spec-full-name (buttercup-spec-full-name spec)))
|
"-l" "buttercup"
|
||||||
(unless (cl-dolist (p patterns)
|
"-l" file
|
||||||
(when (string-match p spec-full-name)
|
"-f" "buttercup-run"))
|
||||||
(cl-return t)))
|
(setq error t))
|
||||||
(setf (buttercup-spec-function spec)
|
(message "%s" (buffer-string)))
|
||||||
(lambda () (signal 'buttercup-pending "SKIPPED")))))))
|
(print! (info "Ignoring %s" (relpath file)))))
|
||||||
(buttercup-run)))
|
(if error
|
||||||
|
(error "A test failed")
|
||||||
|
t)))
|
||||||
;;
|
|
||||||
;; Test library
|
|
||||||
|
|
||||||
(defmacro insert!! (&rest text)
|
|
||||||
"Insert TEXT in buffer, then move cursor to last {0} marker."
|
|
||||||
`(progn
|
|
||||||
(insert ,@text)
|
|
||||||
(when (search-backward "{0}" nil t)
|
|
||||||
(replace-match "" t t))))
|
|
||||||
|
|
9
core/test/helpers.el
Normal file
9
core/test/helpers.el
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
;; -*- no-byte-compile: t; -*-
|
||||||
|
;;; core/test/helpers.el
|
||||||
|
|
||||||
|
(defmacro insert!! (&rest text)
|
||||||
|
"Insert TEXT in buffer, then move cursor to last {0} marker."
|
||||||
|
`(progn
|
||||||
|
(insert ,@text)
|
||||||
|
(when (search-backward "{0}" nil t)
|
||||||
|
(replace-match "" t t))))
|
|
@ -1,4 +1,4 @@
|
||||||
;;; init.test.el -*- lexical-binding: t; -*-
|
;;; core/test/init.el -*- lexical-binding: t; no-byte-compile: t; -*-
|
||||||
|
|
||||||
;; An init.el for our unit test suites. Do not use this!
|
;; An init.el for our unit test suites. Do not use this!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue