Skip to content

Commit aea2916

Browse files
committed
Add custom tests
1 parent e7ab66a commit aea2916

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
*.test
77
*.out
88
*.html
9+
custom_tests.json

expr_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"os"
78
"reflect"
89
"testing"
910
"time"
@@ -2053,6 +2054,35 @@ func TestMemoryBudget(t *testing.T) {
20532054
}
20542055
}
20552056

2057+
func TestExpr_custom_tests(t *testing.T) {
2058+
f, err := os.Open("custom_tests.json")
2059+
if os.IsNotExist(err) {
2060+
t.Skip("no custom tests")
2061+
return
2062+
}
2063+
2064+
require.NoError(t, err, "open file error")
2065+
defer f.Close()
2066+
2067+
var tests []string
2068+
err = json.NewDecoder(f).Decode(&tests)
2069+
require.NoError(t, err, "decode json error")
2070+
2071+
for id, tt := range tests {
2072+
t.Run(fmt.Sprintf("line %v", id+2), func(t *testing.T) {
2073+
program, err := expr.Compile(tt)
2074+
require.NoError(t, err)
2075+
2076+
out, err := expr.Run(program, nil)
2077+
2078+
// Make sure out is used.
2079+
_ = fmt.Sprintf("%v", out)
2080+
2081+
assert.Error(t, err)
2082+
})
2083+
}
2084+
}
2085+
20562086
func TestIssue432(t *testing.T) {
20572087
env := map[string]any{
20582088
"func": func(

0 commit comments

Comments
 (0)