nit(cli): stub 'doom test'

To prep for v3.1.
This commit is contained in:
Henrik Lissner 2022-07-29 12:53:01 +02:00
parent 6ffee6ece7
commit 04a09128d4
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -1,120 +1,48 @@
;;; core/cli/test.el -*- lexical-binding: t; -*-
;;; Commentary:
;;
;; The heart of Doom's test DSL and framework. Powered by either ERT or
;; Buttercup, this extends testing frameworks to allow for isolated execution
;; contexts on several levels, a more sophisticated CLI for tests, and
;; integration with Doom's profiles system so testing environments can be
;; generated on-the-fly.
;;
;;; Code:
;;
;;; Variables
;; None yet!
;; TODO Implement me
(defvar doom-test-backend 'ert
"One of `ert' or `buttercup'.")
;; TODO Implement me
(defvar doom-test-isolation-level nil
"Determines the testing strategy for tests.
Should be one of:
nil -- Run all tests in the same session.
file -- Run each test file in isolated sessions.
group -- Run each group of tests in isolated sessions.
t -- Run each individual test in isolated sessions (very slow).")
;;
;;; Commands
(defcli! test (&rest targets)
"Run Doom unit tests."
:disable t
;; FIXME Tests don't work; will be fixed in v3.1
(doom-initialize 'force 'noerror)
(require 'ansi-color)
(let (files read-files)
(unless targets
(setq targets
(cons doom-core-dir
(cl-remove-if-not
(doom-rpartial #'file-in-directory-p doom-emacs-dir)
;; Omit `doom-private-dir', which is always first
(let (doom-modules)
(load (expand-file-name "test/init" doom-core-dir) nil t)
(cdr (doom-module-load-path)))))))
(while targets
(let ((target (pop targets)))
;; FIXME Module targets don't work
(cond ((equal target ":core")
(appendq! files (nreverse (doom-glob doom-core-dir "test/test-*.el"))))
((file-directory-p target)
(setq target (expand-file-name target))
(appendq! files (nreverse (doom-glob target "test/test-*.el"))))
((file-exists-p target)
(push target files)))))
(setenv "DOOMLOCALDIR" (concat doom-local-dir "test/"))
(setenv "DOOMDIR" (concat doom-core-dir "test/"))
(with-temp-buffer
(print! (start "Bootstrapping test environment, if necessary..."))
(cl-destructuring-bind (status . output)
(doom-exec-process
(doom-test--emacs-binary)
"--batch"
"--eval"
(prin1-to-string
`(progn
(setq user-emacs-directory ,doom-emacs-dir)
(require 'core ,(locate-library "core"))
(require 'core-cli)
(doom-initialize 'force 'noerror)
(doom-initialize-modules)
(doom-cli-reload-core-autoloads)
(when (doom-cli-packages-install)
(doom-cli-reload-package-autoloads)))))
(unless (zerop status)
(error "Failed to bootstrap unit tests"))))
(with-temp-buffer
(dolist (file files)
(if (doom-file-cookie-p file "if" t)
(cl-destructuring-bind (_status . output)
(apply #'doom-exec-process
(doom-test--emacs-binary)
"--batch"
"-l" (concat doom-core-dir "core.el")
"-l" (concat doom-core-dir "test/helpers.el")
(append (when (file-in-directory-p file doom-modules-dir)
(list "-f" "doom-initialize-core"))
(list "-l" file
"-f" "buttercup-run")))
(insert (replace-regexp-in-string ansi-color-control-seq-regexp "" output))
(push file read-files))
(print! (item "Ignoring %s" (relpath file)))))
(let ((total 0)
(total-failed 0)
(i 0))
(print! "\n----------------------------------------\nTests finished")
(print-group!
(goto-char (point-min))
(while (re-search-forward "^Ran \\([0-9]+\\) specs, \\([0-9]+\\) failed," nil t)
(let ((ran (string-to-number (match-string 1)))
(failed (string-to-number (match-string 2))))
(when (> failed 0)
(terpri)
(print! (warn "(%s) Failed %d/%d tests")
(path (nth i read-files))
failed ran)
(save-excursion
(print-group!
(print!
"%s" (string-trim
(buffer-substring
(match-beginning 0)
(dotimes (_ failed (point))
(search-backward "========================================"))))))))
(cl-incf total ran)
(cl-incf total-failed failed)
(cl-incf i))))
(terpri)
(if (= total-failed 0)
(print! (success "Ran %d tests successfully." total total-failed))
(print! (error "Ran %d tests, %d failed") total total-failed)
(kill-emacs 1)))
t)))
;; FIXME Will be fixed in v3.1
(defstub! test
((backend ("--ert" "--buttercup"))
(jobs ("-j" "--jobs" int))
&rest targets)
"Run Doom unit tests.")
;;
;;; Helpers
(defun doom-test--emacs-binary ()
(let ((emacs-binary-path (doom-path invocation-directory invocation-name))
(runemacs-binary-path (if IS-WINDOWS (doom-path invocation-directory "runemacs.exe"))))
(if (and runemacs-binary-path (file-exists-p runemacs-binary-path))
runemacs-binary-path
emacs-binary-path)))
;; Nothing here yet
(provide 'core-cli-test)
;;; test.el ends here