diff --git a/checks.nix b/checks.nix index 85caa92..b0cc7a8 100644 --- a/checks.nix +++ b/checks.nix @@ -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; @@ -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 @@ -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 = ""; }; } diff --git a/doomdirs/test/init.el b/doomdirs/test/init.el deleted file mode 100644 index c99e78c..0000000 --- a/doomdirs/test/init.el +++ /dev/null @@ -1,16 +0,0 @@ -;; Copyright 2024 Google LLC -;; -;; Licensed under the Apache License, Version 2.0 (the "License"); -;; you may not use this file except in compliance with the License. -;; You may obtain a copy of the License at -;; -;; http://www.apache.org/licenses/LICENSE-2.0 -;; -;; Unless required by applicable law or agreed to in writing, software -;; distributed under the License is distributed on an "AS IS" BASIS, -;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -;; See the License for the specific language governing permissions and -;; limitations under the License. - -;; Doom doesn't like a completely empty doom! block. -(doom! :config default) diff --git a/doomdirs/test/config.el b/tests.el similarity index 66% rename from doomdirs/test/config.el rename to tests.el index 0de99da..c675f27 100644 --- a/doomdirs/test/config.el +++ b/tests.el @@ -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)