diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-16 01:34:45 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-16 01:34:45 +0200 |
| commit | ecfaeabf2a92e26c6a521d5fac404a0fff6263b6 (patch) | |
| tree | 4147dd6809a45fe5b773447352354dbee2295900 /internal/config/load_test.go | |
| parent | be4b1275c76b9cad984dfafaa8023db94eb3eecf (diff) | |
| download | krino-ecfaeabf2a92e26c6a521d5fac404a0fff6263b6.tar.gz krino-ecfaeabf2a92e26c6a521d5fac404a0fff6263b6.zip | |
milestone 1 review: claims span the run, explain's chain is opt-in and its own, overrides keyed by clean path, splice and enum guards
Diffstat (limited to 'internal/config/load_test.go')
| -rw-r--r-- | internal/config/load_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/config/load_test.go b/internal/config/load_test.go index 13ef9d8..d522316 100644 --- a/internal/config/load_test.go +++ b/internal/config/load_test.go @@ -142,3 +142,37 @@ func TestLoadWithOverriddenText(t *testing.T) { t.Errorf("the files on disk were read differently: %v %+v", errs, cfg.Dirs) } } + +// TestLoadWithReportsAnUnusedOverride: an override whose path does not name +// a file the load reads - a different spelling of it, or a directory not in +// include - is reported, instead of the file on disk being read as though +// the unsaved text were fine (plan 13 review F4). +func TestLoadWithReportsAnUnusedOverride(t *testing.T) { + h := t.TempDir() + t.Setenv("HOME", h) + main := filepath.Join(h, "krino.conf") + os.MkdirAll(filepath.Join(h, "dirs"), 0o755) + os.WriteFile(main, []byte("(include \"dl\")\n"), 0o644) + os.WriteFile(filepath.Join(h, "dirs", "dl.conf"), []byte("(path \"/tmp\")\n"), 0o644) + + broken := []byte("(path \"/tmp\")\n(rule \"BROKEN\")\n") + // The same file, spelled with a "." segment: the text must still be used. + uncleaned := filepath.Join(h, "dirs", ".", "dl.conf") + if _, errs := LoadWith(main, map[string][]byte{uncleaned: broken}); len(errs) == 0 { + t.Error("an override keyed by an uncleaned path was ignored") + } + // A file this load never reads: say so rather than pass silently. + other := filepath.Join(h, "dirs", "other.conf") + errs := diagText(func() []*Diag { _, e := LoadWith(main, map[string][]byte{other: broken}); return e }()) + if !strings.Contains(errs, "other.conf") { + t.Errorf("an override for a file that is not read went unreported: %s", errs) + } +} + +func diagText(ds []*Diag) string { + var b strings.Builder + for _, d := range ds { + b.WriteString(d.Error() + "\n") + } + return b.String() +} |
