aboutsummaryrefslogtreecommitdiff
path: root/internal/engine/exclude_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/engine/exclude_test.go')
-rw-r--r--internal/engine/exclude_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/engine/exclude_test.go b/internal/engine/exclude_test.go
index 7069623..7d9ce2a 100644
--- a/internal/engine/exclude_test.go
+++ b/internal/engine/exclude_test.go
@@ -576,3 +576,44 @@ func TestDuplicateExcludeFailsClosed(t *testing.T) {
}
}
}
+
+// TestUndecidedStopRuleStops: a (stop) rule whose condition cannot be
+// decided ends the search for that file, so a later rule does not act on a
+// file the stop rule was written to keep (plan 12).
+func TestUndecidedStopRuleStops(t *testing.T) {
+ big := "confidential " + strings.Repeat("x", 2048)
+ h, dl := excludeTree(t, map[string]string{"big.txt": big, "small.txt": "nothing"})
+ main := writeConfig(t, h, `(include "dl")`, map[string]string{"dl": `
+(path "~/dl")
+(max-read 1K)
+(rule "keep" (when (content "confidential")) (stop))
+(rule "all" (move "Out"))
+`})
+ e, errs := Load(main)
+ if len(errs) > 0 {
+ t.Fatal(errs)
+ }
+ r, err := e.Match(context.Background(), e.Dirs[0])
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, fm := range append(append([]FileMatch{}, r.Matched...), r.Unmatched...) {
+ switch fm.File.Rel {
+ case "big.txt":
+ if len(fm.Rules) != 0 || len(fm.Warnings) == 0 {
+ t.Errorf("big.txt: rules %d, warnings %v; want no rule and the warning", len(fm.Rules), fm.Warnings)
+ }
+ case "small.txt":
+ if len(fm.Rules) != 1 {
+ t.Errorf("small.txt: rules %d; want the move", len(fm.Rules))
+ }
+ }
+ }
+ x, err := e.Explain(context.Background(), filepath.Join(dl, "big.txt"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(x.Rules) != 2 || x.Rules[1].Stopped != "stopped by rule keep, which could not be decided" {
+ t.Errorf("explain rules = %+v; want all stopped by the undecided keep", x.Rules)
+ }
+}