aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/krino/exclude_test.go23
-rw-r--r--cmd/krino/explain.go5
2 files changed, 27 insertions, 1 deletions
diff --git a/cmd/krino/exclude_test.go b/cmd/krino/exclude_test.go
index e9d4433..f76be0c 100644
--- a/cmd/krino/exclude_test.go
+++ b/cmd/krino/exclude_test.go
@@ -165,3 +165,26 @@ func TestVerboseListsDirectoriesLeftOutOfTheWalk(t *testing.T) {
t.Errorf("listed without -v:\n%s", out)
}
}
+
+// TestExplainShowsAnUndecidedRule: explain names a rule it could not decide
+// "undecided", not "no" (plan 12).
+func TestExplainShowsAnUndecidedRule(t *testing.T) {
+ h := home(t)
+ dl := filepath.Join(h, "dl")
+ os.MkdirAll(dl, 0o755)
+ p := filepath.Join(dl, "big.txt")
+ os.WriteFile(p, []byte("confidential "+strings.Repeat("x", 2048)), 0o644)
+ old := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
+ os.Chtimes(p, old, old)
+ if code, _, errOut := runCLI(t, "init"); code != 0 {
+ t.Fatal(errOut)
+ }
+ if code, _, errOut := runCLI(t, "new", "dl", dl); code != 0 {
+ t.Fatal(errOut)
+ }
+ os.WriteFile(filepath.Join(h, ".config", "krino", "dirs", "dl.conf"), []byte("(path \"~/dl\")\n(max-read 1K)\n(rule \"keep\" (when (content \"confidential\")) (stop))\n(rule \"all\" (move \"Out\"))\n"), 0o644)
+ _, out, errOut := runCLI(t, "explain", p)
+ if !strings.Contains(out, "rule keep: undecided") || !strings.Contains(out, "rule all: not evaluated, stopped by rule keep, which could not be decided") {
+ t.Errorf("explain output:\n%s\n%s", out, errOut)
+ }
+}
diff --git a/cmd/krino/explain.go b/cmd/krino/explain.go
index f65df42..09145b9 100644
--- a/cmd/krino/explain.go
+++ b/cmd/krino/explain.go
@@ -72,8 +72,11 @@ func cmdExplain(g *globals, args []string, stdout, stderr io.Writer) int {
continue
}
status := "no"
- if rt.Match {
+ switch {
+ case rt.Match:
status = "MATCH"
+ case rt.Trace != nil && rt.Trace.Unknown:
+ status = "undecided"
}
fmt.Fprintf(stdout, "rule %s: %s\n", rt.Rule.Name, status)
printTrace(stdout, rt.Trace)