aboutsummaryrefslogtreecommitdiff
path: root/internal/config/load_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config/load_test.go')
-rw-r--r--internal/config/load_test.go34
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()
+}