Fix, rename & move doom/run-tests => doom-run-tests
This commit is contained in:
parent
fac587d21e
commit
cbfb3eeda4
3 changed files with 70 additions and 62 deletions
|
@ -13,3 +13,70 @@
|
|||
finally return (intern (format "%s::%s" path name))) ()
|
||||
()
|
||||
,@body)))
|
||||
|
||||
;;;###autoload
|
||||
(defun doom-run-tests (&optional modules)
|
||||
"Run all loaded tests, specified by MODULES (a list of module cons cells) or
|
||||
command line args following a double dash (each arg should be in the
|
||||
'module/submodule' format).
|
||||
|
||||
If neither is available, run all tests in all enabled modules."
|
||||
(interactive) ;; TODO Add completing-read selection of tests
|
||||
;; FIXME Refactor this
|
||||
(condition-case-unless-debug ex
|
||||
(let (targets)
|
||||
;; ensure DOOM is initialized
|
||||
(let (noninteractive)
|
||||
(unload-feature 'core t)
|
||||
(load (expand-file-name "init.el" user-emacs-directory) nil t))
|
||||
(run-hooks 'emacs-startup-hook)
|
||||
;; collect targets
|
||||
(cond ((and command-line-args-left
|
||||
(equal (car command-line-args-left) "--"))
|
||||
(cl-loop for arg in (cdr argv)
|
||||
if (equal arg "core")
|
||||
do (push (expand-file-name "test/" doom-core-dir) targets)
|
||||
else
|
||||
collect
|
||||
(cl-destructuring-bind (car &optional cdr) (split-string arg "/" t)
|
||||
(cons (intern (concat ":" car))
|
||||
(and cdr (intern cdr))))
|
||||
into args
|
||||
finally do (setq modules args
|
||||
command-line-args-left nil)))
|
||||
|
||||
(modules
|
||||
(unless (cl-loop for module in modules
|
||||
unless (and (consp module)
|
||||
(keywordp (car module))
|
||||
(symbolp (cdr module)))
|
||||
return t)
|
||||
(error "Expected a list of cons, got: %s" modules)))
|
||||
|
||||
(t
|
||||
(setq modules (doom--module-pairs)
|
||||
targets (list (expand-file-name "test/" doom-core-dir)))))
|
||||
;; resolve targets to a list of test files and load them
|
||||
(cl-loop with targets =
|
||||
(append targets
|
||||
(cl-loop for (module . submodule) in modules
|
||||
if submodule
|
||||
collect (doom-module-path module submodule "test/")
|
||||
else
|
||||
nconc
|
||||
(cl-loop with module-name = (substring (symbol-name module) 1)
|
||||
with module-path = (expand-file-name module-name doom-modules-dir)
|
||||
for path in (directory-files module-path t "^\\w")
|
||||
collect (expand-file-name "test/" path))))
|
||||
for dir in targets
|
||||
if (file-directory-p dir)
|
||||
nconc (reverse (directory-files-recursively dir "\\.el$"))
|
||||
into items
|
||||
finally do (quiet! (mapc #'load-file items)))
|
||||
;; run all loaded tests
|
||||
(when noninteractive
|
||||
(ert-run-tests-batch-and-exit)))
|
||||
('error
|
||||
(lwarn 'doom-test :error
|
||||
"%s -> %s"
|
||||
(car ex) (error-message-string ex)))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue