From 88cbe4e623eab9adb608566ac636d36eed72e551 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Tue, 15 Sep 2026 22:12:31 +0200 Subject: check refuses placeholders that could never expand --- internal/engine/engine_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'internal/engine/engine_test.go') diff --git a/internal/engine/engine_test.go b/internal/engine/engine_test.go index 9de3ea4..4af8f79 100644 --- a/internal/engine/engine_test.go +++ b/internal/engine/engine_test.go @@ -256,3 +256,41 @@ func TestLoadAcceptsDuplicateWithMove(t *testing.T) { } } } + +// TestLoadRefusesBadPlaceholders: a copy or move destination or a rename +// name whose placeholders could never expand is a config error at load, so +// krino check reports it at the action's position instead of a run skipping +// the step (plan 12). +func TestLoadRefusesBadPlaceholders(t *testing.T) { + for _, c := range []struct { + action, want string + }{ + {`(move "Out/{foo}")`, "unknown placeholder {foo}"}, + {`(move "Out/{mtime}")`, "unknown placeholder {mtime}"}, + {`(move "Out/{now}")`, "unknown placeholder {now}"}, + {`(move "Out/{mtime:%B}")`, "%B"}, + {`(rename "{0}-x")`, "numbered from 1"}, + {`(copy "Out/{10}")`, "unknown placeholder {10}"}, + {`(move "Out/{name")`, "unclosed placeholder"}, + } { + h := sandbox(t) + os.MkdirAll(filepath.Join(h, "dl"), 0o755) + main := writeConfig(t, h, `(include "dl")`, map[string]string{"dl": "(path \"~/dl\")\n(rule \"r\" (when (name \"^(a)\")) " + c.action + ")\n"}) + _, errs := Load(main) + found := false + for _, e := range errs { + if strings.Contains(e.Error(), c.want) && strings.Contains(e.Error(), "dl.conf:2:") { + found = true + } + } + if !found { + t.Errorf("%s: errors %v; want %q at line 2", c.action, errs, c.want) + } + } + h := sandbox(t) + os.MkdirAll(filepath.Join(h, "dl"), 0o755) + main := writeConfig(t, h, `(include "dl")`, map[string]string{"dl": "(path \"~/dl\")\n(rule \"r\" (when (name \"^(a)\")) (rename \"{1}-{stem}{ext}\") (move \"Out/{mtime:%Y/%m}/{{x}}/{now:%j}\"))\n"}) + if _, errs := Load(main); len(errs) > 0 { + t.Errorf("valid placeholders refused: %v", errs) + } +} -- cgit v1.3