Skip to content

Commit

Permalink
feat(testing): add test suite and fix failing tests (#74)
Browse files Browse the repository at this point in the history
* Set up build & test infrastructure

This has a few layers:
1. Eldev, for Emacs package management;
2. Nix, for coördination (e.g., running multiple test configurations, building
   against multiple Emacs distributions); and
3. garnix, for CI.

Each should work without the ones after it, so it is somewhat modular. E.g.,
garnix could be replaced with GitHub workflows (but at the cost of more
configuration).

* Appease the linters

There are a couple things in here that should be changed:
- don’t use `fboundp` on every invocation
- don’t set `fill-column` to 167

* Add a test suite

There are three pieces to this
- “standard” unit tests (currently fairly minimal)
- initialization tests that check how various styles of user init behave
- a library for simulating the Emacs init process

* Pre-load themes & update state when vars set

Pre-loading themes helps shift `custom-safe-theme` interactions to when the user
sets the variable instead of during initialization or mode change, but this
isn’t a full fix for #64, since it doesn’t address the conundrum of
`custom-safe-themes` being set after `auto-dark-mode` is enabled.

Updating the state when the variables are set fixes the “it seems to only work
after one dark mode toggle” issue (which especially crops up when variables are
customized after the mode is enabled). Users of the timer likely don’t notice
this, as it only takes five seconds for Auto-Dark to fix the state, but the
pub/sub detection methods wouldn’t otherwise update until the next mode change.

* Set themes even if detection mechanism fails

Previously, failing to “determine a viable theme detection mechanism” would
error, preventing the rest of `auto-dark-mode` setup from running. This is now a
warning, and you are effectively left in “manual” mode.

This is technically a fix for #66, but doesn’t address all the related changes
there. Those will be addressed in #62. It also partially addresses #73 by adding
`auto-dark-toggle-appearance`.

* Defer setting old variables

Since the old `auto-dark-dark/light-theme` variables have defaults, a
traditional configuration (enabling Auto-Dark before customizing vars) can lead
to a `default` → `auto-dark-dark/light-theme` → `auto-dark-theme` “flicker”
sequence during Emacs initialization.

This avoids that by deferring initialization of the old variables until
`after-init-mode`, so they only affect the display if both `auto-dark-themes`
and `custom-enabled-themes` are `nil`.

The consequence is that users of the old variables may have a slightly longer
delay until the initial Auto-Dark theme appears. (And also that Auto-Dark has a
bit more defensive code to ensure it doesn’t try to set themes before enough is
initialized.)
  • Loading branch information
sellout authored Oct 18, 2024
1 parent 1b6c184 commit 988121d
Show file tree
Hide file tree
Showing 24 changed files with 1,558 additions and 108 deletions.
8 changes: 8 additions & 0 deletions .dir-locals.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
;; TODO: We have to be careful what variables we set here. Some can cause the
;; Eldev linters to not read the settings here. See emacs-eldev/eldev#83.
((nil
;; FIXME: This is just set to silence linter line-length warnings. It should
;; be set to an intentional value, then the long-lines fixed.
(fill-column . 167)
(indent-tabs-mode . nil)
(sentence-end-double-space . nil)))
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
direnv_layout_dir="$PWD/.cache/direnv"
use flake
10 changes: 10 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:base"],
"lockFileMaintenance": {
"enabled":true
},
"nix": {
"enabled":true
}
}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
*.DS_Store
*.elc
/.cache/direnv/
/dist
/.eldev
/result
30 changes: 30 additions & 0 deletions Eldev
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
;;; Eldev --- Build configuration -*- mode: emacs-lisp; lexical-binding: t; -*-

(require 'eldev)
(require 'elisp-lint)

(define-error 'auto-dark-test-invalid-test-selection "Unknown test type")

(eldev-add-loading-roots 'test "initialize")

(eldev-defoption auto-dark-test-selection (type)
"Select tests to run; type can be `main' or `integration'"
:options (-T --test-type)
:for-command test
:value TYPE
:default-value 'main
(pcase (intern type)
('main
(setf eldev-test-fileset
`(:and ,eldev-test-fileset (:not "./tests/initialization"))))
('integration (setf eldev-test-fileset "./tests/initialization"))
(_ (signal 'auto-dark-test-invalid-test-selection (list type)))))

(setq
;; run all linters by default
eldev-lint-default t
;; ignore lisp files in the example directory
eldev-standard-excludes `(:or ,eldev-standard-excludes "./example")
;; and disable the ‘elisp-lint’ validators that are already covered by
;; ‘eldev-lint’ (see ‘eldev-linter-elisp’).
elisp-lint-ignored-validators '("checkdoc" "package-lint"))
Loading

0 comments on commit 988121d

Please sign in to comment.