diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-01 13:51:28 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-01 13:51:28 -0400 |
| commit | f2d3f6c6586ede7f757ca74ea699982562f069a7 (patch) | |
| tree | 86f292b6ad19c2affd067d6ba13ce3865629a7c0 /tests/test-wttrin-favorite-override.el | |
| parent | b1aca874b9a2b5282c0cc83bd4fece981a94e19c (diff) | |
| download | emacs-wttrin-f2d3f6c6586ede7f757ca74ea699982562f069a7.tar.gz emacs-wttrin-f2d3f6c6586ede7f757ca74ea699982562f069a7.zip | |
fix: keep a d-set favorite from reverting to the init value on restart
wttrin-favorite-location did two jobs: a defcustom the user sets in init, and the savehist-persisted value that `d`/make-default mutated. Setting it in init (setopt) clobbered the `d` choice on every startup. So a favorite promoted with `d` reverted to the init value after a restart, and the mode-line showed the wrong location's weather. wttrin-saved-locations had the same defect.
I split the two roles. The defcustoms stay as the init-set base. New savehist-persisted runtime vars, wttrin--favorite-override and wttrin--saved-locations-runtime, hold what `d`, save, rename, remove, and the geolocation commands write. Reads go through resolvers: wttrin--favorite-location returns the override or the configured favorite, and wttrin--saved-locations overlays the runtime directory on the configured one (runtime wins on a name collision). Init and `d` now write different variables, so neither clobbers the other.
Removing a saved location that only comes from init can't delete it, since the runtime removal has nothing to touch. The command now says so instead of reporting a removal that didn't happen.
There's no automatic migration. A favorite set in init is unaffected, and a favorite set only with `d` before this version is re-set once with `d`. The README documents the behavior.
Diffstat (limited to 'tests/test-wttrin-favorite-override.el')
| -rw-r--r-- | tests/test-wttrin-favorite-override.el | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/test-wttrin-favorite-override.el b/tests/test-wttrin-favorite-override.el new file mode 100644 index 0000000..0236901 --- /dev/null +++ b/tests/test-wttrin-favorite-override.el @@ -0,0 +1,80 @@ +;;; test-wttrin-favorite-override.el --- Tests for the runtime favorite override -*- lexical-binding: t; -*- + +;; Copyright (C) 2026 Craig Jennings + +;;; Commentary: +;; Unit tests for the split between the configured favorite +;; (`wttrin-favorite-location', a defcustom set in init) and the runtime +;; favorite (`wttrin--favorite-override', set by `d'/the geolocation commands +;; and persisted by savehist). The effective favorite resolves via +;; `wttrin--favorite-location': the override wins over the config, so a favorite +;; chosen at runtime is not clobbered by an init that also sets the option. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(require 'wttrin) + +;;; wttrin--favorite-location (resolver) + +(ert-deftest test-wttrin-favorite-override-normal-config-when-no-override () + "Normal: with no override, the effective favorite is the configured one." + (let ((wttrin-favorite-location "New Orleans, LA") + (wttrin--favorite-override nil)) + (should (equal "New Orleans, LA" (wttrin--favorite-location))))) + +(ert-deftest test-wttrin-favorite-override-normal-override-wins () + "Normal: a runtime override shadows the configured favorite." + (let ((wttrin-favorite-location "New Orleans, LA") + (wttrin--favorite-override "Hyatt Place Warwick, RI")) + (should (equal "Hyatt Place Warwick, RI" (wttrin--favorite-location))))) + +(ert-deftest test-wttrin-favorite-override-boundary-both-nil () + "Boundary: no config and no override yields nil (favorite disabled)." + (let ((wttrin-favorite-location nil) + (wttrin--favorite-override nil)) + (should (null (wttrin--favorite-location))))) + +(ert-deftest test-wttrin-favorite-override-boundary-auto-detect-override () + "Boundary: the override carries the tri-state t (auto-detect)." + (let ((wttrin-favorite-location "New Orleans, LA") + (wttrin--favorite-override t)) + (should (eq t (wttrin--favorite-location))))) + +(ert-deftest test-wttrin-favorite-override-regression-init-does-not-clobber () + "Regression: setting the config after an override (as an init `setopt' would) +does not change the effective favorite. This is the bug where a favorite set +with `d' reverted to the init value on restart." + (let ((wttrin--favorite-override "Hyatt Place Warwick, RI") + (wttrin-favorite-location nil)) + ;; Simulate the init running its (setopt wttrin-favorite-location ...). + (setq wttrin-favorite-location "New Orleans, LA") + (should (equal "Hyatt Place Warwick, RI" (wttrin--favorite-location))))) + +;;; wttrin--set-favorite-location writes the override, not the config + +(ert-deftest test-wttrin-favorite-override-normal-setter-writes-override () + "Normal: the setter writes the runtime override and leaves the config intact." + (let ((wttrin-favorite-location "New Orleans, LA") + (wttrin--favorite-override nil) + (wttrin--location-history nil)) + (wttrin--set-favorite-location "Paris, FR") + (should (equal "Paris, FR" wttrin--favorite-override)) + (should (equal "New Orleans, LA" wttrin-favorite-location)) + (should (equal "Paris, FR" (wttrin--favorite-location))))) + +;;; savehist registration targets the runtime vars, not the config defcustoms + +(ert-deftest test-wttrin-favorite-override-normal-savehist-registers-override () + "Normal: savehist persists the override, not the config defcustom." + (require 'savehist) + (let ((savehist-additional-variables '(kill-ring))) + (wttrin--savehist-register) + (should (memq 'wttrin--favorite-override savehist-additional-variables)) + (should (memq 'wttrin--saved-locations-runtime savehist-additional-variables)) + (should-not (memq 'wttrin-favorite-location savehist-additional-variables)) + (should-not (memq 'wttrin-saved-locations savehist-additional-variables)))) + +(provide 'test-wttrin-favorite-override) +;;; test-wttrin-favorite-override.el ends here |
