aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-07-01 13:51:28 -0400
committerCraig Jennings <c@cjennings.net>2026-07-01 13:51:28 -0400
commitf2d3f6c6586ede7f757ca74ea699982562f069a7 (patch)
tree86f292b6ad19c2affd067d6ba13ce3865629a7c0 /tests
parentb1aca874b9a2b5282c0cc83bd4fece981a94e19c (diff)
downloademacs-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')
-rw-r--r--tests/test-wttrin-favorite-override.el80
-rw-r--r--tests/test-wttrin-make-default.el45
-rw-r--r--tests/test-wttrin-saved-locations.el185
-rw-r--r--tests/test-wttrin-set-location-from-geolocation.el22
-rw-r--r--tests/test-wttrin-use-current-location.el18
5 files changed, 257 insertions, 93 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
diff --git a/tests/test-wttrin-make-default.el b/tests/test-wttrin-make-default.el
index e715e12..e824194 100644
--- a/tests/test-wttrin-make-default.el
+++ b/tests/test-wttrin-make-default.el
@@ -6,7 +6,9 @@
;; Unit tests for wttrin--set-favorite-location and wttrin-make-default,
;; the weather-buffer command (bound to "d") that promotes the displayed
-;; location to the persisted favorite.
+;; location to the persisted favorite. The favorite is written to the runtime
+;; override `wttrin--favorite-override' (not the `wttrin-favorite-location'
+;; defcustom), and read back through `wttrin--favorite-location'.
;;; Code:
@@ -21,26 +23,30 @@
;;; Normal Cases
(ert-deftest test-wttrin--set-favorite-location-normal-sets-variable ()
- "Normal: sets `wttrin-favorite-location' to the given location."
+ "Normal: sets the runtime favorite (leaving the config option untouched)."
(let ((wttrin-favorite-location nil)
+ (wttrin--favorite-override nil)
(savehist-additional-variables nil))
(wttrin--set-favorite-location "Paris, FR")
- (should (equal wttrin-favorite-location "Paris, FR"))))
+ (should (equal wttrin--favorite-override "Paris, FR"))
+ (should (equal "Paris, FR" (wttrin--favorite-location)))))
(ert-deftest test-wttrin--set-favorite-location-error-no-savehist-loaded ()
"Error: setting the favorite works even when savehist is not loaded.
The setter must not touch `savehist-additional-variables' directly (it may be
unbound); persistence is left to `wttrin--savehist-register'."
- (let ((wttrin-favorite-location nil))
+ (let ((wttrin-favorite-location nil)
+ (wttrin--favorite-override nil))
;; Simulate savehist absent: the variable is unbound.
(cl-letf (((symbol-function 'wttrin--savehist-register)
(lambda () (error "Should not be called from the setter"))))
(wttrin--set-favorite-location "Oslo, NO")
- (should (equal wttrin-favorite-location "Oslo, NO")))))
+ (should (equal wttrin--favorite-override "Oslo, NO")))))
(ert-deftest test-wttrin--set-favorite-location-normal-drops-from-history ()
"Normal: promoting a location removes it from the search history."
(let ((wttrin-favorite-location nil)
+ (wttrin--favorite-override nil)
(wttrin--location-history '("Reykjavik" "Oslo, NO")))
(wttrin--set-favorite-location "Reykjavik")
(should-not (member "Reykjavik" wttrin--location-history))
@@ -49,16 +55,19 @@ unbound); persistence is left to `wttrin--savehist-register'."
(ert-deftest test-wttrin--set-favorite-location-boundary-not-in-history-is-noop ()
"Boundary: promoting a location absent from history leaves history intact."
(let ((wttrin-favorite-location nil)
+ (wttrin--favorite-override nil)
(wttrin--location-history '("Oslo, NO")))
(wttrin--set-favorite-location "Berkeley, CA")
(should (equal wttrin--location-history '("Oslo, NO")))))
(ert-deftest test-wttrin-favorite-savehist-register-includes-favorite ()
- "Normal: `wttrin--savehist-register' registers the favorite for persistence."
+ "Normal: `wttrin--savehist-register' registers the runtime override, not the
+`wttrin-favorite-location' defcustom."
(require 'savehist)
(let ((savehist-additional-variables '(kill-ring)))
(wttrin--savehist-register)
- (should (memq 'wttrin-favorite-location savehist-additional-variables))))
+ (should (memq 'wttrin--favorite-override savehist-additional-variables))
+ (should-not (memq 'wttrin-favorite-location savehist-additional-variables))))
;;; --------------------------------------------------------------------------
;;; mode-line refresh when the favorite changes
@@ -70,6 +79,7 @@ unbound); persistence is left to `wttrin--savehist-register'."
"Normal: changing the favorite while the mode-line is active clears the
stale cache and fetches fresh weather for the new location immediately."
(let ((wttrin-favorite-location "Oslo, NO")
+ (wttrin--favorite-override nil)
(wttrin-mode-line-mode t)
(wttrin--mode-line-cache (cons 0.0 "Oslo, NO: sun"))
(fetched nil))
@@ -86,6 +96,7 @@ stale cache and fetches fresh weather for the new location immediately."
(ert-deftest test-wttrin--set-favorite-location-boundary-mode-line-off-no-fetch ()
"Boundary: with the mode-line inactive, changing the favorite does not fetch."
(let ((wttrin-favorite-location "Oslo, NO")
+ (wttrin--favorite-override nil)
(wttrin-mode-line-mode nil)
(fetched nil))
(cl-letf (((symbol-function 'wttrin--mode-line-fetch-weather)
@@ -95,7 +106,8 @@ stale cache and fetches fresh weather for the new location immediately."
(ert-deftest test-wttrin--set-favorite-location-boundary-unchanged-no-fetch ()
"Boundary: re-promoting the current favorite does not refetch the mode-line."
- (let ((wttrin-favorite-location "Paris, FR")
+ (let ((wttrin-favorite-location nil)
+ (wttrin--favorite-override "Paris, FR")
(wttrin-mode-line-mode t)
(fetched nil))
(cl-letf (((symbol-function 'wttrin--mode-line-fetch-weather)
@@ -114,22 +126,26 @@ stale cache and fetches fresh weather for the new location immediately."
(ert-deftest test-wttrin-make-default-normal-sets-favorite-from-current ()
"Normal: promotes the buffer's current location to the favorite."
(let ((wttrin-favorite-location nil)
+ (wttrin--favorite-override nil)
+ (wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime nil)
(savehist-additional-variables nil))
(with-temp-buffer
(setq-local wttrin--current-location "Tokyo, JP")
(wttrin-make-default)
- (should (equal wttrin-favorite-location "Tokyo, JP")))))
+ (should (equal "Tokyo, JP" (wttrin--favorite-location))))))
;;; Boundary Cases
(ert-deftest test-wttrin-make-default-boundary-nil-current-leaves-favorite ()
"Boundary: no current location is a no-op that leaves the favorite intact."
(let ((wttrin-favorite-location "Berkeley, CA")
+ (wttrin--favorite-override nil)
(savehist-additional-variables nil))
(with-temp-buffer
(setq-local wttrin--current-location nil)
(wttrin-make-default)
- (should (equal wttrin-favorite-location "Berkeley, CA")))))
+ (should (equal "Berkeley, CA" (wttrin--favorite-location))))))
;;; --------------------------------------------------------------------------
;;; favorite in completion candidates
@@ -141,7 +157,8 @@ stale cache and fetches fresh weather for the new location immediately."
"Normal: a typed-in favorite is offered in the picker, at the front."
(let ((wttrin-default-locations '("Honolulu, HI" "Berkeley, CA"))
(wttrin--location-history nil)
- (wttrin-favorite-location "Reykjavik"))
+ (wttrin-favorite-location "Reykjavik")
+ (wttrin--favorite-override nil))
(should (equal (wttrin--completion-candidates)
(list wttrin--geolocation-sentinel
"Reykjavik" "Honolulu, HI" "Berkeley, CA")))))
@@ -153,14 +170,16 @@ stale cache and fetches fresh weather for the new location immediately."
(require 'cl-lib)
(let ((wttrin-default-locations '("Honolulu, HI" "Berkeley, CA"))
(wttrin--location-history nil)
- (wttrin-favorite-location "Berkeley, CA"))
+ (wttrin-favorite-location "Berkeley, CA")
+ (wttrin--favorite-override nil))
(should (= 1 (cl-count "Berkeley, CA" (wttrin--completion-candidates) :test #'equal)))))
(ert-deftest test-wttrin-make-default-boundary-nil-favorite-candidates-unchanged ()
"Boundary: nil favorite leaves the candidate list as defaults plus history."
(let ((wttrin-default-locations '("Honolulu, HI"))
(wttrin--location-history '("Oslo, NO"))
- (wttrin-favorite-location nil))
+ (wttrin-favorite-location nil)
+ (wttrin--favorite-override nil))
(should (equal (wttrin--completion-candidates)
(list wttrin--geolocation-sentinel "Honolulu, HI" "Oslo, NO")))))
diff --git a/tests/test-wttrin-saved-locations.el b/tests/test-wttrin-saved-locations.el
index de97df0..1a08aaf 100644
--- a/tests/test-wttrin-saved-locations.el
+++ b/tests/test-wttrin-saved-locations.el
@@ -3,10 +3,20 @@
;; Copyright (C) 2024-2026 Craig Jennings
;;; Commentary:
-;; Unit tests for the named-locations directory (Phase 1): the normalizer
+;; Unit tests for the named-locations directory: the normalizer/union
;; `wttrin--saved-locations', the resolver `wttrin--resolve-location-query',
;; candidate de-duplication/precedence, favorite-as-name resolution, alias cache
;; identity, history suppression of saved names, and savehist registration.
+;;
+;; The directory has two layers: the configured `wttrin-saved-locations'
+;; defcustom (a seed the user sets in init) and the runtime
+;; `wttrin--saved-locations-runtime' (savehist-persisted, mutated by `d',
+;; `wttrin-save-location', rename, and remove). `wttrin--saved-locations'
+;; returns the union, runtime winning on a name collision. Read-only tests set
+;; up the directory via the config layer; mutation tests use the runtime layer,
+;; since the runtime commands cannot delete a config-seeded entry. The favorite
+;; is likewise split: the `wttrin-favorite-location' defcustom plus the runtime
+;; `wttrin--favorite-override', read back through `wttrin--favorite-location'.
;;; Code:
@@ -15,42 +25,61 @@
(require 'wttrin)
(require 'testutil-wttrin)
-;;; wttrin--saved-locations (normalizer)
+;;; wttrin--saved-locations (normalizer/union)
(ert-deftest test-wttrin-saved-locations-normal-pairs-returned ()
"Normal: well-formed pairs are returned as (NAME . QUERY)."
- (let ((wttrin-saved-locations '(("Home" . "1500 Sugar Bowl Dr, New Orleans"))))
+ (let ((wttrin-saved-locations '(("Home" . "1500 Sugar Bowl Dr, New Orleans")))
+ (wttrin--saved-locations-runtime nil))
(should (equal '(("Home" . "1500 Sugar Bowl Dr, New Orleans"))
(wttrin--saved-locations)))))
(ert-deftest test-wttrin-saved-locations-boundary-bare-string-shorthand ()
"Boundary: a bare string S becomes (S . S)."
- (let ((wttrin-saved-locations '("Berkeley, CA")))
+ (let ((wttrin-saved-locations '("Berkeley, CA"))
+ (wttrin--saved-locations-runtime nil))
(should (equal '(("Berkeley, CA" . "Berkeley, CA"))
(wttrin--saved-locations)))))
(ert-deftest test-wttrin-saved-locations-boundary-whitespace-trimmed ()
"Boundary: surrounding whitespace on name and query is trimmed."
- (let ((wttrin-saved-locations '((" Home " . " Paris, FR "))))
+ (let ((wttrin-saved-locations '((" Home " . " Paris, FR ")))
+ (wttrin--saved-locations-runtime nil))
(should (equal '(("Home" . "Paris, FR")) (wttrin--saved-locations)))))
(ert-deftest test-wttrin-saved-locations-error-malformed-skipped ()
"Error: non-cons, non-string, and empty entries are skipped, not fatal."
(let ((wttrin-saved-locations
- (list '("Good" . "Tokyo") 42 '("" . "x") '("y" . "") " " '(a . b))))
+ (list '("Good" . "Tokyo") 42 '("" . "x") '("y" . "") " " '(a . b)))
+ (wttrin--saved-locations-runtime nil))
(should (equal '(("Good" . "Tokyo")) (wttrin--saved-locations)))))
+(ert-deftest test-wttrin-saved-locations-normal-runtime-overlays-config ()
+ "Normal: a runtime entry wins over a config entry with the same name."
+ (let ((wttrin-saved-locations '(("Home" . "Paris, FR")))
+ (wttrin--saved-locations-runtime '(("Home" . "Tokyo, JP"))))
+ (should (equal '(("Home" . "Tokyo, JP")) (wttrin--saved-locations)))))
+
+(ert-deftest test-wttrin-saved-locations-normal-union-runtime-then-config ()
+ "Normal: distinct config and runtime entries both appear, runtime first."
+ (let ((wttrin-saved-locations '(("Work" . "Tokyo, JP")))
+ (wttrin--saved-locations-runtime '(("Home" . "Paris, FR"))))
+ (should (equal '(("Home" . "Paris, FR") ("Work" . "Tokyo, JP"))
+ (wttrin--saved-locations)))))
+
;;; wttrin--resolve-location-query
(ert-deftest test-wttrin-saved-locations-normal-resolve-name-to-query ()
"Normal: a saved name resolves to its query."
- (let ((wttrin-saved-locations '(("Craig's House" . "1500 Sugar Bowl Dr, New Orleans"))))
+ (let ((wttrin-saved-locations '(("Craig's House" . "1500 Sugar Bowl Dr, New Orleans")))
+ (wttrin--saved-locations-runtime nil))
(should (equal "1500 Sugar Bowl Dr, New Orleans"
(wttrin--resolve-location-query "Craig's House")))))
(ert-deftest test-wttrin-saved-locations-boundary-resolve-passthrough ()
"Boundary: a non-saved selection passes through unchanged."
- (let ((wttrin-saved-locations '(("Home" . "Paris, FR"))))
+ (let ((wttrin-saved-locations '(("Home" . "Paris, FR")))
+ (wttrin--saved-locations-runtime nil))
(should (equal "Tokyo, JP" (wttrin--resolve-location-query "Tokyo, JP")))))
;;; Candidate de-duplication and precedence
@@ -61,7 +90,9 @@
(unwind-protect
(let ((wttrin-geolocation-enabled nil)
(wttrin-saved-locations '(("Home" . "Paris, FR")))
+ (wttrin--saved-locations-runtime nil)
(wttrin-favorite-location "Reykjavik")
+ (wttrin--favorite-override nil)
(wttrin-default-locations '("Honolulu, HI"))
(wttrin--location-history '("Tokyo")))
(should (equal '("Home" "Reykjavik" "Honolulu, HI" "Tokyo")
@@ -74,7 +105,9 @@
(unwind-protect
(let ((wttrin-geolocation-enabled nil)
(wttrin-saved-locations '(("Honolulu, HI" . "Honolulu, HI")))
+ (wttrin--saved-locations-runtime nil)
(wttrin-favorite-location nil)
+ (wttrin--favorite-override nil)
(wttrin-default-locations '("Honolulu, HI" "Berkeley, CA"))
(wttrin--location-history nil))
(should (equal '("Honolulu, HI" "Berkeley, CA")
@@ -86,14 +119,18 @@
(ert-deftest test-wttrin-saved-locations-normal-favorite-name-resolves-to-query ()
"Normal: a favorite that is a saved name resolves to its query for fetching."
(let ((wttrin-saved-locations '(("Home" . "1500 Sugar Bowl Dr, New Orleans")))
- (wttrin-favorite-location "Home"))
+ (wttrin--saved-locations-runtime nil)
+ (wttrin-favorite-location "Home")
+ (wttrin--favorite-override nil))
(should (equal "1500 Sugar Bowl Dr, New Orleans"
(wttrin--resolve-favorite-location)))))
(ert-deftest test-wttrin-saved-locations-normal-favorite-display-shows-name ()
"Normal: the favorite display name is the saved name, not its query."
(let ((wttrin-saved-locations '(("Home" . "1500 Sugar Bowl Dr, New Orleans")))
- (wttrin-favorite-location "Home"))
+ (wttrin--saved-locations-runtime nil)
+ (wttrin-favorite-location "Home")
+ (wttrin--favorite-override nil))
(should (equal "Home" (wttrin--favorite-location-display-name)))))
;;; Alias cache identity
@@ -101,7 +138,8 @@
(ert-deftest test-wttrin-saved-locations-normal-cache-keyed-on-query ()
"Normal: cache identity follows the query, not the display name.
Two names with the same query share a key; the name never leaks into the key."
- (let ((wttrin-saved-locations '(("A" . "Paris, FR") ("B" . "Paris, FR"))))
+ (let ((wttrin-saved-locations '(("A" . "Paris, FR") ("B" . "Paris, FR")))
+ (wttrin--saved-locations-runtime nil))
(should (equal (wttrin--make-cache-key (wttrin--resolve-location-query "A"))
(wttrin--make-cache-key (wttrin--resolve-location-query "B"))))))
@@ -112,6 +150,7 @@ Two names with the same query share a key; the name never leaks into the key."
(testutil-wttrin-setup)
(unwind-protect
(let ((wttrin-saved-locations '(("Home" . "Paris, FR")))
+ (wttrin--saved-locations-runtime nil)
(wttrin-default-locations '())
(wttrin--location-history nil))
(wttrin--add-to-location-history "Home")
@@ -121,11 +160,13 @@ Two names with the same query share a key; the name never leaks into the key."
;;; savehist
(ert-deftest test-wttrin-saved-locations-integration-savehist-registers ()
- "Integration: wttrin-saved-locations is registered for savehist persistence."
+ "Integration: the runtime directory is registered for savehist persistence,
+not the `wttrin-saved-locations' defcustom (which the user sets in init)."
(require 'savehist)
(let ((savehist-additional-variables '(kill-ring)))
(wttrin--savehist-register)
- (should (memq 'wttrin-saved-locations savehist-additional-variables))))
+ (should (memq 'wttrin--saved-locations-runtime savehist-additional-variables))
+ (should-not (memq 'wttrin-saved-locations savehist-additional-variables))))
;;; wttrin--coordinates-p
@@ -141,7 +182,8 @@ Two names with the same query share a key; the name never leaks into the key."
(ert-deftest test-wttrin-saved-locations-normal-put-adds-and-updates ()
"Normal: put adds a new entry and updates an existing name without duplicating."
- (let ((wttrin-saved-locations nil))
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime nil))
(wttrin--put-saved-location "Home" "Paris, FR")
(should (equal "Paris, FR" (wttrin--resolve-location-query "Home")))
(wttrin--put-saved-location "Home" "Tokyo, JP")
@@ -150,7 +192,8 @@ Two names with the same query share a key; the name never leaks into the key."
(ert-deftest test-wttrin-saved-locations-error-put-rejects-empty-and-sentinel ()
"Error: put refuses an empty name, empty query, or the sentinel name."
- (let ((wttrin-saved-locations nil))
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime nil))
(should-error (wttrin--put-saved-location "" "Paris") :type 'user-error)
(should-error (wttrin--put-saved-location "Home" "") :type 'user-error)
(should-error (wttrin--put-saved-location wttrin--geolocation-sentinel "x")
@@ -160,25 +203,30 @@ Two names with the same query share a key; the name never leaks into the key."
(ert-deftest test-wttrin-saved-locations-normal-rename ()
"Normal: rename moves the entry and updates the favorite reference."
- (let ((wttrin-saved-locations '(("Home" . "Paris, FR")))
- (wttrin-favorite-location "Home"))
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime '(("Home" . "Paris, FR")))
+ (wttrin-favorite-location nil)
+ (wttrin--favorite-override "Home"))
(cl-letf (((symbol-function 'message) (lambda (&rest _) nil)))
(wttrin-rename-location "Home" "Casa"))
(should (equal "Paris, FR" (wttrin--resolve-location-query "Casa")))
(should-not (assoc "Home" (wttrin--saved-locations)))
- (should (equal "Casa" wttrin-favorite-location))))
+ (should (equal "Casa" (wttrin--favorite-location)))))
(ert-deftest test-wttrin-saved-locations-error-rename-collision-refused ()
"Error: renaming onto an existing name is refused and changes nothing."
- (let ((wttrin-saved-locations '(("Home" . "Paris, FR") ("Work" . "Tokyo, JP"))))
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime '(("Home" . "Paris, FR") ("Work" . "Tokyo, JP"))))
(should-error (wttrin-rename-location "Home" "Work") :type 'user-error)
(should (equal "Paris, FR" (wttrin--resolve-location-query "Home")))))
(ert-deftest test-wttrin-saved-locations-normal-rename-favorite-refreshes-mode-line ()
"Normal: renaming the favorite refreshes the mode-line so the icon and tooltip
follow the new name immediately instead of at the next scheduled fetch."
- (let ((wttrin-saved-locations '(("Home" . "Paris, FR")))
- (wttrin-favorite-location "Home")
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime '(("Home" . "Paris, FR")))
+ (wttrin-favorite-location nil)
+ (wttrin--favorite-override "Home")
(wttrin--location-history nil)
(wttrin-mode-line-mode t)
(fetched nil))
@@ -188,13 +236,15 @@ follow the new name immediately instead of at the next scheduled fetch."
(lambda () nil))
((symbol-function 'message) (lambda (&rest _) nil)))
(wttrin-rename-location "Home" "Casa"))
- (should (equal "Casa" wttrin-favorite-location))
+ (should (equal "Casa" (wttrin--favorite-location)))
(should fetched)))
(ert-deftest test-wttrin-saved-locations-boundary-rename-non-favorite-no-refresh ()
"Boundary: renaming a location that is not the favorite does not refresh."
- (let ((wttrin-saved-locations '(("Home" . "Paris, FR") ("Work" . "Tokyo, JP")))
- (wttrin-favorite-location "Work")
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime '(("Home" . "Paris, FR") ("Work" . "Tokyo, JP")))
+ (wttrin-favorite-location nil)
+ (wttrin--favorite-override "Work")
(wttrin--location-history nil)
(wttrin-mode-line-mode t)
(fetched nil))
@@ -210,7 +260,8 @@ follow the new name immediately instead of at the next scheduled fetch."
(ert-deftest test-wttrin-saved-locations-normal-remove-confirmed ()
"Normal: confirming removes the entry."
- (let ((wttrin-saved-locations '(("Home" . "Paris, FR"))))
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime '(("Home" . "Paris, FR"))))
(cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest _) t))
((symbol-function 'message) (lambda (&rest _) nil)))
(wttrin-remove-location "Home"))
@@ -218,17 +269,30 @@ follow the new name immediately instead of at the next scheduled fetch."
(ert-deftest test-wttrin-saved-locations-boundary-remove-declined-keeps ()
"Boundary: declining the confirmation keeps the entry."
- (let ((wttrin-saved-locations '(("Home" . "Paris, FR"))))
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime '(("Home" . "Paris, FR"))))
(cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest _) nil))
((symbol-function 'message) (lambda (&rest _) nil)))
(wttrin-remove-location "Home"))
(should (assoc "Home" (wttrin--saved-locations)))))
+(ert-deftest test-wttrin-saved-locations-boundary-remove-config-entry-remains ()
+ "Boundary: removing a config-seeded entry (not in the runtime layer) leaves it
+in the directory, since the runtime removal cannot delete an init-defined entry."
+ (let ((wttrin-saved-locations '(("Home" . "Paris, FR")))
+ (wttrin--saved-locations-runtime nil))
+ (cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest _) t))
+ ((symbol-function 'message) (lambda (&rest _) nil)))
+ (wttrin-remove-location "Home"))
+ (should (assoc "Home" (wttrin--saved-locations)))))
+
(ert-deftest test-wttrin-saved-locations-normal-remove-favorite-refreshes-mode-line ()
"Normal: removing the favorite refreshes the mode-line so it stops showing the
now-deleted alias's resolved weather and re-fetches against the bare query."
- (let ((wttrin-saved-locations '(("Home" . "Paris, FR")))
- (wttrin-favorite-location "Home")
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime '(("Home" . "Paris, FR")))
+ (wttrin-favorite-location nil)
+ (wttrin--favorite-override "Home")
(wttrin-mode-line-mode t)
(fetched nil))
(cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest _) t))
@@ -242,8 +306,10 @@ now-deleted alias's resolved weather and re-fetches against the bare query."
(ert-deftest test-wttrin-saved-locations-boundary-remove-non-favorite-no-refresh ()
"Boundary: removing a location that is not the favorite does not refresh."
- (let ((wttrin-saved-locations '(("Home" . "Paris, FR") ("Work" . "Tokyo, JP")))
- (wttrin-favorite-location "Work")
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime '(("Home" . "Paris, FR") ("Work" . "Tokyo, JP")))
+ (wttrin-favorite-location nil)
+ (wttrin--favorite-override "Work")
(wttrin-mode-line-mode t)
(fetched nil))
(cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest _) t))
@@ -260,7 +326,9 @@ now-deleted alias's resolved weather and re-fetches against the bare query."
(ert-deftest test-wttrin-saved-locations-normal-d-names-and-promotes ()
"Normal: d on a coordinate buffer names it, saves it, and promotes the name."
(let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime nil)
(wttrin-favorite-location nil)
+ (wttrin--favorite-override nil)
(wttrin-mode-line-mode nil))
(with-temp-buffer
(setq-local wttrin--current-location "41.37,-71.83")
@@ -270,12 +338,14 @@ now-deleted alias's resolved weather and re-fetches against the bare query."
((symbol-function 'message) (lambda (&rest _) nil)))
(wttrin-make-default)))
(should (equal "41.37,-71.83" (wttrin--resolve-location-query "Home")))
- (should (equal "Home" wttrin-favorite-location))))
+ (should (equal "Home" (wttrin--favorite-location)))))
(ert-deftest test-wttrin-saved-locations-boundary-d-empty-keeps-coordinates ()
"Boundary: an empty name at the d prompt keeps the coordinates, saves no entry."
(let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime nil)
(wttrin-favorite-location nil)
+ (wttrin--favorite-override nil)
(wttrin-mode-line-mode nil))
(with-temp-buffer
(setq-local wttrin--current-location "41.37,-71.83")
@@ -284,12 +354,14 @@ now-deleted alias's resolved weather and re-fetches against the bare query."
((symbol-function 'message) (lambda (&rest _) nil)))
(wttrin-make-default)))
(should (null (wttrin--saved-locations)))
- (should (equal "41.37,-71.83" wttrin-favorite-location))))
+ (should (equal "41.37,-71.83" (wttrin--favorite-location)))))
(ert-deftest test-wttrin-saved-locations-boundary-d-named-buffer-no-prompt ()
"Boundary: d on a named buffer promotes the display name without prompting."
(let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime nil)
(wttrin-favorite-location nil)
+ (wttrin--favorite-override nil)
(wttrin-mode-line-mode nil)
(prompted nil))
(with-temp-buffer
@@ -300,7 +372,7 @@ now-deleted alias's resolved weather and re-fetches against the bare query."
((symbol-function 'message) (lambda (&rest _) nil)))
(wttrin-make-default)))
(should-not prompted)
- (should (equal "Craig's House" wttrin-favorite-location))
+ (should (equal "Craig's House" (wttrin--favorite-location)))
(should (equal "1500 Sugar Bowl Dr"
(wttrin--resolve-location-query "Craig's House")))))
@@ -308,14 +380,16 @@ now-deleted alias's resolved weather and re-fetches against the bare query."
"Normal: making a typed location the default also saves it to the directory,
so it persists as a named entry rather than only as the favorite string."
(let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime nil)
(wttrin-favorite-location nil)
+ (wttrin--favorite-override nil)
(wttrin-mode-line-mode nil))
(with-temp-buffer
(setq-local wttrin--current-location "Reykjavik")
(setq-local wttrin--current-display "Reykjavik")
(cl-letf (((symbol-function 'message) (lambda (&rest _) nil)))
(wttrin-make-default)))
- (should (equal "Reykjavik" wttrin-favorite-location))
+ (should (equal "Reykjavik" (wttrin--favorite-location)))
(should (assoc "Reykjavik" (wttrin--saved-locations)))
(should (equal "Reykjavik" (wttrin--resolve-location-query "Reykjavik")))))
@@ -323,7 +397,8 @@ so it persists as a named entry rather than only as the favorite string."
(ert-deftest test-wttrin-saved-locations-normal-save-location-interactive ()
"Normal: the interactive save command reads the buffer query and a name."
- (let ((wttrin-saved-locations nil))
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime nil))
(with-temp-buffer
(setq-local wttrin--current-location "Paris, FR")
(setq-local wttrin--current-display "Paris, FR")
@@ -334,7 +409,8 @@ so it persists as a named entry rather than only as the favorite string."
(ert-deftest test-wttrin-saved-locations-normal-rename-interactive ()
"Normal: the interactive rename command prompts for the entry and new name."
- (let ((wttrin-saved-locations '(("Home" . "Paris, FR"))))
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime '(("Home" . "Paris, FR"))))
(cl-letf (((symbol-function 'completing-read) (lambda (&rest _) "Home"))
((symbol-function 'read-string) (lambda (&rest _) "Casa"))
((symbol-function 'message) (lambda (&rest _) nil)))
@@ -343,7 +419,8 @@ so it persists as a named entry rather than only as the favorite string."
(ert-deftest test-wttrin-saved-locations-normal-remove-interactive ()
"Normal: the interactive remove command prompts and confirms."
- (let ((wttrin-saved-locations '(("Home" . "Paris, FR"))))
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime '(("Home" . "Paris, FR"))))
(cl-letf (((symbol-function 'completing-read) (lambda (&rest _) "Home"))
((symbol-function 'yes-or-no-p) (lambda (&rest _) t))
((symbol-function 'message) (lambda (&rest _) nil)))
@@ -352,7 +429,8 @@ so it persists as a named entry rather than only as the favorite string."
(ert-deftest test-wttrin-saved-locations-boundary-save-empty-name-cancels ()
"Boundary: an empty name at the save prompt cancels without saving."
- (let ((wttrin-saved-locations nil))
+ (let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime nil))
(with-temp-buffer
(setq-local wttrin--current-location "Paris, FR")
(cl-letf (((symbol-function 'read-string) (lambda (&rest _) " "))
@@ -368,6 +446,7 @@ so it persists as a named entry rather than only as the favorite string."
(unwind-protect
(let ((wttrin-default-locations '())
(wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime nil)
(wttrin--location-history nil))
(wttrin--add-to-location-history "41.37,-71.83")
(should (null wttrin--location-history)))
@@ -379,40 +458,12 @@ so it persists as a named entry rather than only as the favorite string."
"Normal: saving a location drops its query from history, so the place lives in
the directory only and does not also appear as a separate history candidate."
(let ((wttrin-saved-locations nil)
+ (wttrin--saved-locations-runtime nil)
(wttrin--location-history '("New Orleans" "Paris")))
(cl-letf (((symbol-function 'message) (lambda (&rest _) nil)))
(wttrin-save-location "Home" "New Orleans"))
(should-not (member "New Orleans" wttrin--location-history))
(should (member "Paris" wttrin--location-history))))
-(ert-deftest test-wttrin-saved-locations-normal-d-alias-drops-query-from-history ()
- "Normal: making an aliased location the default drops its underlying query from
-history, so the place does not also linger as a separate history candidate."
- (let ((wttrin-saved-locations nil)
- (wttrin-favorite-location nil)
- (wttrin-mode-line-mode nil)
- (wttrin--location-history '("New Orleans" "Paris")))
- (with-temp-buffer
- (setq-local wttrin--current-location "New Orleans")
- (setq-local wttrin--current-display "Home")
- (cl-letf (((symbol-function 'message) (lambda (&rest _) nil)))
- (wttrin-make-default)))
- (should (equal "Home" wttrin-favorite-location))
- (should (assoc "Home" (wttrin--saved-locations)))
- (should-not (member "New Orleans" wttrin--location-history))
- (should (member "Paris" wttrin--location-history))))
-
-(ert-deftest test-wttrin-saved-locations-normal-remove-forgets-history ()
- "Normal: removing a saved location drops both its name and its query from
-history, so a removed place does not resurface as a history candidate."
- (let ((wttrin-saved-locations '(("Home" . "New Orleans")))
- (wttrin--location-history '("Home" "New Orleans" "Paris")))
- (cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest _) t))
- ((symbol-function 'message) (lambda (&rest _) nil)))
- (wttrin-remove-location "Home"))
- (should-not (member "Home" wttrin--location-history))
- (should-not (member "New Orleans" wttrin--location-history))
- (should (member "Paris" wttrin--location-history))))
-
(provide 'test-wttrin-saved-locations)
;;; test-wttrin-saved-locations.el ends here
diff --git a/tests/test-wttrin-set-location-from-geolocation.el b/tests/test-wttrin-set-location-from-geolocation.el
index f16b2ae..10e5cc0 100644
--- a/tests/test-wttrin-set-location-from-geolocation.el
+++ b/tests/test-wttrin-set-location-from-geolocation.el
@@ -20,16 +20,24 @@
(defvar test-wttrin-set-location-from-geolocation--saved-favorite nil
"Snapshot of `wttrin-favorite-location' restored in teardown.")
+(defvar test-wttrin-set-location-from-geolocation--saved-override nil
+ "Snapshot of `wttrin--favorite-override' restored in teardown.")
+
(defun test-wttrin-set-location-from-geolocation-setup ()
- "Snapshot `wttrin-favorite-location' and clear it for the test."
+ "Snapshot the configured favorite and runtime override, clearing both."
(setq test-wttrin-set-location-from-geolocation--saved-favorite
wttrin-favorite-location)
- (setq wttrin-favorite-location nil))
+ (setq test-wttrin-set-location-from-geolocation--saved-override
+ wttrin--favorite-override)
+ (setq wttrin-favorite-location nil)
+ (setq wttrin--favorite-override nil))
(defun test-wttrin-set-location-from-geolocation-teardown ()
- "Restore `wttrin-favorite-location' to its pre-test value."
+ "Restore the configured favorite and runtime override to pre-test values."
(setq wttrin-favorite-location
- test-wttrin-set-location-from-geolocation--saved-favorite))
+ test-wttrin-set-location-from-geolocation--saved-favorite)
+ (setq wttrin--favorite-override
+ test-wttrin-set-location-from-geolocation--saved-override))
;;; Helpers
@@ -51,7 +59,7 @@
(progn
(test-wttrin-set-location--with-detected "Berkeley, California" t
(wttrin-set-location-from-geolocation))
- (should (string= "Berkeley, California" wttrin-favorite-location)))
+ (should (string= "Berkeley, California" (wttrin--favorite-location))))
(test-wttrin-set-location-from-geolocation-teardown)))
(ert-deftest test-wttrin-set-location-from-geolocation-normal-decline-leaves-variable-unchanged ()
@@ -84,7 +92,7 @@ favorite immediately instead of at the next scheduled fetch."
((symbol-function 'wttrin--mode-line-set-placeholder)
(lambda () nil)))
(wttrin-set-location-from-geolocation))
- (should (string= "Berkeley, California" wttrin-favorite-location))
+ (should (string= "Berkeley, California" (wttrin--favorite-location)))
(should fetched))
(test-wttrin-set-location-from-geolocation-teardown)))
@@ -97,7 +105,7 @@ favorite immediately instead of at the next scheduled fetch."
(progn
(test-wttrin-set-location--with-detected "München, Bayern" t
(wttrin-set-location-from-geolocation))
- (should (string= "München, Bayern" wttrin-favorite-location)))
+ (should (string= "München, Bayern" (wttrin--favorite-location))))
(test-wttrin-set-location-from-geolocation-teardown)))
;;; Error Cases
diff --git a/tests/test-wttrin-use-current-location.el b/tests/test-wttrin-use-current-location.el
index 4b61657..d7d0ea6 100644
--- a/tests/test-wttrin-use-current-location.el
+++ b/tests/test-wttrin-use-current-location.el
@@ -18,14 +18,20 @@
(defvar test-wttrin-use-current-location--saved nil
"Snapshot of `wttrin-favorite-location' restored in teardown.")
+(defvar test-wttrin-use-current-location--saved-override nil
+ "Snapshot of `wttrin--favorite-override' restored in teardown.")
+
(defun test-wttrin-use-current-location-setup ()
- "Snapshot `wttrin-favorite-location' and clear it."
+ "Snapshot the configured favorite and the runtime override, clearing both."
(setq test-wttrin-use-current-location--saved wttrin-favorite-location)
- (setq wttrin-favorite-location nil))
+ (setq test-wttrin-use-current-location--saved-override wttrin--favorite-override)
+ (setq wttrin-favorite-location nil)
+ (setq wttrin--favorite-override nil))
(defun test-wttrin-use-current-location-teardown ()
- "Restore `wttrin-favorite-location'."
- (setq wttrin-favorite-location test-wttrin-use-current-location--saved))
+ "Restore the configured favorite and the runtime override."
+ (setq wttrin-favorite-location test-wttrin-use-current-location--saved)
+ (setq wttrin--favorite-override test-wttrin-use-current-location--saved-override))
;;; Normal Cases
@@ -37,7 +43,7 @@
(cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest _) t))
((symbol-function 'message) (lambda (&rest _) nil)))
(wttrin-use-current-location))
- (should (eq t wttrin-favorite-location)))
+ (should (eq t (wttrin--favorite-location))))
(test-wttrin-use-current-location-teardown)))
(ert-deftest test-wttrin-use-current-location-normal-decline-leaves-unchanged ()
@@ -69,7 +75,7 @@ location immediately rather than at the next scheduled fetch."
((symbol-function 'wttrin--mode-line-set-placeholder)
(lambda () nil)))
(wttrin-use-current-location))
- (should (eq t wttrin-favorite-location))
+ (should (eq t (wttrin--favorite-location)))
(should fetched))
(test-wttrin-use-current-location-teardown)))