aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-29 20:56:46 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-29 20:56:46 +0200
commit7d26aa60349e72c3d437d329a678a51331914233 (patch)
tree1f54e498d7a55f71b655a0cffbb306f84193ea8b
parent790d89eaaa130d3446f8e9af4dff793a569bb98d (diff)
downloadlectio-7d26aa60349e72c3d437d329a678a51331914233.tar.gz
lectio-7d26aa60349e72c3d437d329a678a51331914233.zip
test(cli): isolate the suite from the real ~/.config/lectio
The ref/rand cli tests assume English book abbreviations ("Jn 3:16"), but with no LECTIO_CONFIG set they read the developer's real user config. On a machine whose config has ui_language = pl (sigla_style = auto -> Polish dialect), "Jn" is not a valid abbreviation and TestRefSingle, TestRefEnglishDialect, TestRefRejectsPolishAbbrevInEnglish, TestRefCompare and TestRandVerse fail -- while passing on a clean CI. Add a package TestMain that points LECTIO_CONFIG at a throwaway temp path, forcing built-in defaults for every cli test and guaranteeing the suite never reads or writes the real user config. Suite now green on a Polish config too.
-rw-r--r--internal/cli/main_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/internal/cli/main_test.go b/internal/cli/main_test.go
new file mode 100644
index 0000000..62989e5
--- /dev/null
+++ b/internal/cli/main_test.go
@@ -0,0 +1,26 @@
+package cli
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+)
+
+// TestMain isolates the cli test suite from the developer's real
+// ~/.config/lectio. Several reference/random tests assume English book
+// abbreviations (e.g. "Jn 3:16"); a user config with ui_language = pl makes
+// sigla_style = auto resolve to the Polish dialect, where "Jn" is not a valid
+// abbreviation, so those tests fail on such a developer's machine even though
+// they pass on a clean CI. Pointing LECTIO_CONFIG at a throwaway,
+// non-existent path forces the built-in defaults for every cli test and keeps
+// the suite from ever reading -- or writing -- the real user config.
+func TestMain(m *testing.M) {
+ dir, err := os.MkdirTemp("", "lectio-cli-test")
+ if err != nil {
+ panic(err)
+ }
+ os.Setenv("LECTIO_CONFIG", filepath.Join(dir, "config.ini"))
+ code := m.Run()
+ os.RemoveAll(dir)
+ os.Exit(code)
+}