aboutsummaryrefslogtreecommitdiff
path: root/internal/ignore/fuzz_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 20:10:01 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 20:10:01 +0200
commitaa24cfb344b1b3eaef7217d996359023cd72ba28 (patch)
treeee0d981d3add58451a83de13ac56be4a8b165eea /internal/ignore/fuzz_test.go
parent00aae60378982902b871a87850e0ed427b28a347 (diff)
downloadkrino-aa24cfb344b1b3eaef7217d996359023cd72ba28.tar.gz
krino-aa24cfb344b1b3eaef7217d996359023cd72ba28.zip
plan 8: fuzz decoders; fold ẞ and invalid UTF-8 correctly, refuse non-UTF-8 paths in krino new
Diffstat (limited to 'internal/ignore/fuzz_test.go')
-rw-r--r--internal/ignore/fuzz_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/ignore/fuzz_test.go b/internal/ignore/fuzz_test.go
new file mode 100644
index 0000000..0e9f0a3
--- /dev/null
+++ b/internal/ignore/fuzz_test.go
@@ -0,0 +1,44 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package ignore
+
+import (
+ "strings"
+ "testing"
+)
+
+// FuzzMatch: any pattern either fails to compile or matches any walked
+// path without panicking, and gives the same answer twice. The oracle test
+// checks answers against git; this checks everything else.
+func FuzzMatch(f *testing.F) {
+ for _, p := range []string{"*.log", "/a.txt", "build/", "**/readme.md", "[!a]*.txt", "[[:digit:]]*", `\`, "[", "a[/]b", "!", "**/**/**", "*a*a*a*b"} {
+ f.Add(p, "dir/sub/a.txt")
+ }
+ f.Fuzz(func(t *testing.T, pattern, rel string) {
+ m, err := New([]string{pattern})
+ if err != nil {
+ return
+ }
+ rel = walkedRel(rel)
+ if rel == "" {
+ return
+ }
+ if m.Match(rel, false) != m.Match(rel, false) {
+ t.Fatalf("Match(%q) under %q is not deterministic", rel, pattern)
+ }
+ m.Match(rel, true)
+ })
+}
+
+// walkedRel turns any string into a path of the shape Match accepts, as a
+// directory walk produces it: slash-separated, with no empty, "." or ".."
+// components.
+func walkedRel(s string) string {
+ var parts []string
+ for _, p := range strings.Split(s, "/") {
+ if p != "" && p != "." && p != ".." {
+ parts = append(parts, p)
+ }
+ }
+ return strings.Join(parts, "/")
+}