Skip to content

Commit

Permalink
Support more tests than just startup
Browse files Browse the repository at this point in the history
It looks like I will need tests that some of the more interesting
packages actually work, not just build.
  • Loading branch information
marienz committed May 26, 2024
1 parent 4597bb5 commit 80a9518
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
24 changes: 16 additions & 8 deletions checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@

{
emacs29,
lib,
linkFarm,
runCommand,
testers,
tmux,
writeText,
writeTextDir,

makeDoomPackages,
toInit,
}:
let
inherit (lib.generators) toPretty;
common = {
# TODO: drop after NixOS 24.05 release.
emacs = emacs29;
Expand All @@ -31,12 +35,19 @@ let
mkDoom = args: (makeDoomPackages (common // args)).doomEmacs;
mkDoomDir = args: writeTextDir "init.el" (toInit args);
minimalDoomDir = mkDoomDir { config = [ "default" ]; };
doomTest = assertion: args: testers.testEqualContents {
inherit assertion;
doomTest = name: init: doomArgs: testers.testEqualContents {
assertion = "name = ${name}; modules = ${toPretty {} init}; args = ${toPretty {} doomArgs};";
expected = writeText "doom-expected" "Doom functions";
# Runs Doom in tmux, waiting (by polling) until its window disappears.
actual = runCommand "interactive" {
nativeBuildInputs = [ tmux (mkDoom args) ];
# Read by tests.el.
testName = name;
nativeBuildInputs = [ tmux (mkDoom (doomArgs // {
doomDir = linkFarm "test-doomdir" {
"config.el" = ./tests.el;
"init.el" = writeText "init.el" (toInit init);
};
})) ];
} ''
tmux new-session -s doom-testing -d
tmux new-window -n doom-window doom-emacs
Expand All @@ -61,9 +72,6 @@ in {
doomDir = ./doomdirs/example;
profileName = "";
};
interactive = doomTest "minimal doom starts" { doomDir = ./doomdirs/test; };
interactive-without-loader = doomTest "minimal doom (without loader) starts" {
doomDir = ./doomdirs/test;
profileName = "";
};
interactive = doomTest "minimal" { config = [ "default" ]; } { };
interactive-without-loader = doomTest "minimal" { config = [ "default" ]; } { profileName = ""; };
}
16 changes: 0 additions & 16 deletions doomdirs/test/init.el

This file was deleted.

15 changes: 13 additions & 2 deletions doomdirs/test/config.el → tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,20 @@
;; This tries to hook into startup as late as possible, write a sign of life
;; (currently a string written to $out), and then exits.

(defun test-minimal ()
;; The minimal test is a noop.
)

(defun test-doom ()
(let ((out (getenv "out")))
(write-region "Doom functions" nil out nil nil nil 'mustbenew))
(let* ((out (getenv "out"))
(test (intern-soft (format "test-%s" (getenv "testName"))))
(result (condition-case err
(funcall test)
(error
(format "%s failed: %s" test err))
(:success
"Doom functions"))))
(write-region result nil out nil nil nil 'mustbenew))
(kill-emacs))

(add-hook 'doom-after-init-hook 'test-doom)

0 comments on commit 80a9518

Please sign in to comment.