diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-29 11:46:17 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-29 11:46:17 +0200 |
| commit | 8ddd910dd545c45a7227da87ca125758b4a0e2cb (patch) | |
| tree | b652bb239c622e2f8806a443db21a0b0bf8c8962 /internal/config | |
| parent | 79f9ae051c1e8f179e2e7c17f590c105eb18bef1 (diff) | |
| download | lectio-8ddd910dd545c45a7227da87ca125758b4a0e2cb.tar.gz lectio-8ddd910dd545c45a7227da87ca125758b4a0e2cb.zip | |
test(bible): skip corpus-dependent tests when optional corpora aren't embedded
Since 51c0f4e split the corpora (only vul embedded by default; wuj/drb/grb
behind -tags fullbible), `go test ./...` on the default build was red across six
packages -- every failure was a test assuming an optional corpus is present.
Guard those assertions with a skip keyed on bible.Meta(code), so they run under
-tags fullbible and skip -- not fail -- on the default vul-only build. Mixed
tests are split into subtests so the always-embedded vul assertions and pure
logic (pl->vul fallback, explicit passthrough, bt-rejection, i18n labels) keep
running on both builds. Test-only change; no product code or corpora touched.
- internal/bible: TestVerses, TestLookup, TestCorpusBooks, TestChapters,
TestGrbNoApparatusMarkers, TestCrossChapterRange* (requireCorpus helper).
- internal/cli, config, render, tui, web: the same pattern for their
corpus-dependent tests.
- Fixes an index-out-of-range panic in internal/tui's reader tests that was
aborting the package binary and masking 3 further corpus-absence failures
(TestReaderBookmarkFlow, TestReaderChapterJump, TestReaderRemembersPlace).
Verified: `go test ./...` and `go test -tags fullbible ./...` both green (0 FAIL);
guards active only on the default build (29 skips vs 1 unrelated pre-existing);
gofmt and go vet clean.
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config_test.go | 82 |
1 files changed, 54 insertions, 28 deletions
diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 4d172c0..b1f3ddd 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -4,8 +4,22 @@ import ( "os" "path/filepath" "testing" + + "github.com/lukaszkasprzak/lectio/internal/bible" ) +// requireCorpus skips the test when corpus `code` is not embedded in this +// build. The optional corpora (wuj, drb, grb) compile in only with +// `-tags fullbible` (or when dropped into the user corpora dir); mirrors the +// helper in internal/bible so these tests run under fullbible and skip -- not +// fail -- on the default vul-only build. +func requireCorpus(t *testing.T, code string) { + t.Helper() + if _, ok := bible.Meta(code); !ok { + t.Skipf("corpus %q not embedded; build with -tags fullbible", code) + } +} + func TestLoadSeeds(t *testing.T) { dir := t.TempDir() t.Setenv("XDG_CONFIG_HOME", dir) @@ -16,26 +30,32 @@ func TestLoadSeeds(t *testing.T) { if cfg.DefaultVersion != "vul" || cfg.Offline { t.Errorf("defaults wrong: %+v", cfg) } - // Versions defaults to the corpora actually available in this build, Vulgate - // first then the rest sorted. Tests build with -tags fullbible, so all four - // are present (see Makefile); a default vul-only binary would list just vul. - wantVersions := []string{"vul", "drb", "grb", "wuj"} - if len(cfg.Versions) != len(wantVersions) { - t.Errorf("versions default = %v, want %v", cfg.Versions, wantVersions) - } else { - for i, v := range wantVersions { - if cfg.Versions[i] != v { - t.Errorf("versions default = %v, want %v", cfg.Versions, wantVersions) - break - } - } - } if cfg.Lectionary != "new" { t.Errorf("lectionary default wrong: %+v", cfg) } if _, err := os.Stat(filepath.Join(dir, "lectio", "config.ini")); err != nil { t.Error("config not seeded") } + // Versions defaults to the corpora actually available in this build, Vulgate + // first then the rest sorted. With -tags fullbible all four are present (see + // Makefile); a default vul-only binary would list just vul, so this + // assertion needs the optional corpora embedded. + t.Run("all corpora listed", func(t *testing.T) { + requireCorpus(t, "drb") + requireCorpus(t, "grb") + requireCorpus(t, "wuj") + wantVersions := []string{"vul", "drb", "grb", "wuj"} + if len(cfg.Versions) != len(wantVersions) { + t.Errorf("versions default = %v, want %v", cfg.Versions, wantVersions) + } else { + for i, v := range wantVersions { + if cfg.Versions[i] != v { + t.Errorf("versions default = %v, want %v", cfg.Versions, wantVersions) + break + } + } + } + }) } // TestLoadMigratesBT checks a legacy config still carrying the retired "bt" @@ -324,20 +344,26 @@ func TestPartShown(t *testing.T) { } func TestReadingCorpusResolution(t *testing.T) { - // drb is an embedded corpus with lang=en. - c := Config{ReadingVersion: "drb"} - if got := c.ReadingCorpus(); got != "drb" { - t.Fatalf("explicit reading_version: got %q", got) - } - c = Config{ReadingLang: "en"} - if got := c.ReadingCorpus(); got != "drb" { - t.Fatalf("reading_lang match: got %q", got) - } - c = Config{UILanguage: "en"} - if got := c.ReadingCorpus(); got != "drb" { - t.Fatalf("ui_language fallback: got %q", got) - } - c = Config{UILanguage: "pl"} // no pl corpus embedded + // The explicit-passthrough, reading_lang and ui_language cases all resolve to + // the embedded drb (lang=en) via bible.Meta/CorporaForLang, so they need drb. + t.Run("drb", func(t *testing.T) { + requireCorpus(t, "drb") + c := Config{ReadingVersion: "drb"} + if got := c.ReadingCorpus(); got != "drb" { + t.Fatalf("explicit reading_version: got %q", got) + } + c = Config{ReadingLang: "en"} + if got := c.ReadingCorpus(); got != "drb" { + t.Fatalf("reading_lang match: got %q", got) + } + c = Config{UILanguage: "en"} + if got := c.ReadingCorpus(); got != "drb" { + t.Fatalf("ui_language fallback: got %q", got) + } + }) + // No pl corpus is autoselect-eligible, so pl resolves to "" on either build + // -- pure logic, keep it running. + c := Config{UILanguage: "pl"} if got := c.ReadingCorpus(); got != "" { t.Fatalf("no match should be empty: got %q", got) } |
