Skip to content

Commit

Permalink
Merge pull request #13 from glojurelang/fix/regex-fuzz-exception
Browse files Browse the repository at this point in the history
Add fuzz test exception for different behavior between go and java
  • Loading branch information
jfhamlin authored Dec 4, 2022
2 parents 738b79e + e4aaf37 commit 9e54bbd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions reader/clj_conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func FuzzCLJConformance(f *testing.F) {
gljValue, gljErr := r.ReadOne()

if (cljErr == nil) != (gljErr == nil) {
if isCLJConformanceErrorException(cljErr, cljExpr) {
t.Skipf("clj error: %v", cljErr)
}
t.Logf("clj out: %v", cljExpr)
t.Fatalf("error mismatch: cljErr=%v gljErr=%v", cljErr, gljErr)
}
Expand Down Expand Up @@ -109,6 +112,23 @@ func FuzzCLJConformance(f *testing.F) {
})
}

// isCLJConformanceErrorException returns true if the error is one that
// we expect to see in the clj conformance tests.
func isCLJConformanceErrorException(cljErr error, cljOut string) bool {
if cljErr == nil {
return false
}

// Java and Go both support regex repetitions in braces (e.g. "a{n,
// m}" for multiple "a"s), but Go's regex engine is more permissive
// and will interpret braces as literals if they don't match the
// regex repetition syntax.
if strings.Contains(cljOut, "Execution error (PatternSyntaxException) at java.util.regex.Pattern/error") && strings.Contains(cljOut, "Illegal repetition") {
return true
}
return false
}

type cljReaderCommand struct {
cmd *exec.Cmd
pipeIn io.WriteCloser
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
false
Execution error (PatternSyntaxException) at java.util.regex.Pattern/error (Pattern.java:2028).
Illegal repetition near index 37
(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9_]{{{{{+)(SNAPSHOT))?
^

Full report at:
/var/folders/0m/y60b85m145lffbfdfk86129r0000gn/T/clojure-708558860762531557.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
false
Execution error at user/eval1 (REPL:1).
Invalid token: :b::c

Full report at:
/var/folders/0m/y60b85m145lffbfdfk86129r0000gn/T/clojure-5969457839634569061.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
go test fuzz v1
string("#\"(\\d+)\\.(\\d+)\\.(\\d+)(?:-([a-zA-Z0-9_]{{{{{+)(SNAPSHOT))?\"\n")

0 comments on commit 9e54bbd

Please sign in to comment.