Skip to content

Commit f9c3aee

Browse files
kyleconroyclaude
andauthored
Remove testify dependency in favor of stdlib testing (#5)
Replace github.com/stretchr/testify/require calls with the equivalent stdlib testing patterns (if-cond t.Fatal/t.Fatalf). Use reflect.DeepEqual for value comparisons that aren't directly comparable with ==. https://claude.ai/code/session_01SzZiuen17CDNi8REpAGw1k Co-authored-by: Claude <noreply@anthropic.com>
1 parent 77b6dcc commit f9c3aee

39 files changed

Lines changed: 4038 additions & 1393 deletions

ast/base_test.go

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import (
2020
"testing"
2121

2222
"github.com/sqlc-dev/marino/charset"
23-
"github.com/stretchr/testify/require"
23+
24+
"reflect"
2425
)
2526

2627
func TestNodeSetText(t *testing.T) {
@@ -37,8 +38,12 @@ func TestNodeSetText(t *testing.T) {
3738
}
3839
for _, tt := range tests {
3940
n.SetText(tt.enc, tt.text)
40-
require.Equal(t, tt.expectUTF8Text, n.Text())
41-
require.Equal(t, tt.expectText, n.OriginalText())
41+
if !reflect.DeepEqual(tt.expectUTF8Text, n.Text()) {
42+
t.Fatalf("got %v, want %v", n.Text(), tt.expectUTF8Text)
43+
}
44+
if !reflect.DeepEqual(tt.expectText, n.OriginalText()) {
45+
t.Fatalf("got %v, want %v", n.OriginalText(), tt.expectText)
46+
}
4247
}
4348
}
4449

@@ -66,7 +71,9 @@ func TestBinaryStringLiteralConversion(t *testing.T) {
6671
}
6772
for _, tt := range printableTests {
6873
n.SetText(charset.EncodingUTF8Impl, tt.text)
69-
require.Equal(t, tt.want, n.Text(), tt.name)
74+
if !reflect.DeepEqual(tt.want, n.Text()) {
75+
t.Fatalf("%v: got %v, want %v", tt.name, n.Text(), tt.want)
76+
}
7077
}
7178

7279
// Binary (non-printable) strings — should convert to 0x hex literals
@@ -98,7 +105,9 @@ func TestBinaryStringLiteralConversion(t *testing.T) {
98105
}
99106
for _, tt := range binaryTests {
100107
n.SetText(charset.EncodingUTF8Impl, tt.text)
101-
require.Equal(t, tt.want, n.Text(), tt.name)
108+
if !reflect.DeepEqual(tt.want, n.Text()) {
109+
t.Fatalf("%v: got %v, want %v", tt.name, n.Text(), tt.want)
110+
}
102111
}
103112
}
104113

@@ -206,7 +215,9 @@ func TestBinaryStringLiteralSkipsComments(t *testing.T) {
206215
}
207216
for _, tt := range tests {
208217
n.SetText(charset.EncodingUTF8Impl, tt.text)
209-
require.Equal(t, tt.want, n.Text(), tt.name)
218+
if !reflect.DeepEqual(tt.want, n.Text()) {
219+
t.Fatalf("%v: got %v, want %v", tt.name, n.Text(), tt.want)
220+
}
210221
}
211222
}
212223

@@ -215,15 +226,21 @@ func TestBinaryStringLiteralNoBackslashEscapes(t *testing.T) {
215226

216227
n.SetText(charset.EncodingUTF8Impl, "SELECT '\\n'")
217228
n.SetNoBackslashEscapes(true)
218-
require.Equal(t, "SELECT '\\n'", n.Text(), "NO_BACKSLASH_ESCAPES literal \\n")
229+
if !reflect.DeepEqual("SELECT '\\n'", n.Text()) {
230+
t.Fatalf("%v: got %v, want %v", "NO_BACKSLASH_ESCAPES literal \\n", n.Text(), "SELECT '\\n'")
231+
}
219232

220233
n.SetText(charset.EncodingUTF8Impl, "SELECT '\\' , 'after'")
221234
n.SetNoBackslashEscapes(true)
222-
require.Equal(t, "SELECT '\\' , 'after'", n.Text(), "NO_BACKSLASH_ESCAPES quote boundary")
235+
if !reflect.DeepEqual("SELECT '\\' , 'after'", n.Text()) {
236+
t.Fatalf("%v: got %v, want %v", "NO_BACKSLASH_ESCAPES quote boundary", n.Text(), "SELECT '\\' , 'after'")
237+
}
223238

224239
n.SetText(charset.EncodingUTF8Impl, "SELECT '\xd2\xe4'")
225240
n.SetNoBackslashEscapes(true)
226-
require.Equal(t, "SELECT 0xd2e4", n.Text(), "NO_BACKSLASH_ESCAPES binary")
241+
if !reflect.DeepEqual("SELECT 0xd2e4", n.Text()) {
242+
t.Fatalf("%v: got %v, want %v", "NO_BACKSLASH_ESCAPES binary", n.Text(), "SELECT 0xd2e4")
243+
}
227244
}
228245

229246
func TestBinaryStringLiteralGBK(t *testing.T) {
@@ -233,23 +250,33 @@ func TestBinaryStringLiteralGBK(t *testing.T) {
233250
// This should be decoded as valid GBK and left as a printable string,
234251
// not converted to a hex literal.
235252
n.SetText(charset.EncodingGBKImpl, "select '\xb1\xed\x31'")
236-
require.Equal(t, "select '表1'", n.Text(), "GBK printable")
253+
if !reflect.DeepEqual("select '表1'", n.Text()) {
254+
t.Fatalf("%v: got %v, want %v", "GBK printable", n.Text(), "select '表1'")
255+
}
237256

238257
// GBK with actual invalid bytes should still convert to hex
239258
n.SetText(charset.EncodingGBKImpl, "select '\x80\xff'")
240-
require.Equal(t, "select 0x80ff", n.Text(), "GBK binary")
259+
if !reflect.DeepEqual("select 0x80ff", n.Text()) {
260+
t.Fatalf("%v: got %v, want %v", "GBK binary", n.Text(), "select 0x80ff")
261+
}
241262

242263
// 筡 = \xb9\x5c in GBK; trail byte 0x5c must not be mistaken for backslash
243264
n.SetText(charset.EncodingGBKImpl, "select '\xb9\x5c'")
244-
require.Equal(t, "select '筡'", n.Text(), "GBK 0x5c trail byte")
265+
if !reflect.DeepEqual("select '筡'", n.Text()) {
266+
t.Fatalf("%v: got %v, want %v", "GBK 0x5c trail byte", n.Text(), "select '筡'")
267+
}
245268

246269
// Multiple GBK chars with 0x5c trail bytes: 筡 = \xb9\x5c, 臷 = \xc5\x5c
247270
n.SetText(charset.EncodingGBKImpl, "select '\xb9\x5c\xc5\x5c'")
248-
require.Equal(t, "select '筡臷'", n.Text(), "GBK multiple 0x5c trail bytes")
271+
if !reflect.DeepEqual("select '筡臷'", n.Text()) {
272+
t.Fatalf("%v: got %v, want %v", "GBK multiple 0x5c trail bytes", n.Text(), "select '筡臷'")
273+
}
249274

250275
// 0x5c trail byte right before closing quote must not escape the quote
251276
n.SetText(charset.EncodingGBKImpl, "select '\xb9\x5c', 'after'")
252-
require.Equal(t, "select '筡', 'after'", n.Text(), "GBK 0x5c before quote")
277+
if !reflect.DeepEqual("select '筡', 'after'", n.Text()) {
278+
t.Fatalf("%v: got %v, want %v", "GBK 0x5c before quote", n.Text(), "select '筡', 'after'")
279+
}
253280
}
254281

255282
func buildBinaryClause() string {

ast/ddl_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import (
1818

1919
. "github.com/sqlc-dev/marino/ast"
2020
"github.com/sqlc-dev/marino/format"
21-
"github.com/stretchr/testify/require"
21+
22+
"reflect"
2223
)
2324

2425
func TestDDLVisitorCover(t *testing.T) {
@@ -59,8 +60,12 @@ func TestDDLVisitorCover(t *testing.T) {
5960
for _, v := range stmts {
6061
ce.reset()
6162
v.node.Accept(checkVisitor{})
62-
require.Equal(t, v.expectedEnterCnt, ce.enterCnt)
63-
require.Equal(t, v.expectedLeaveCnt, ce.leaveCnt)
63+
if !reflect.DeepEqual(v.expectedEnterCnt, ce.enterCnt) {
64+
t.Fatalf("got %v, want %v", ce.enterCnt, v.expectedEnterCnt)
65+
}
66+
if !reflect.DeepEqual(v.expectedLeaveCnt, ce.leaveCnt) {
67+
t.Fatalf("got %v, want %v", ce.leaveCnt, v.expectedLeaveCnt)
68+
}
6469
v.node.Accept(visitor1{})
6570
}
6671
}

ast/dml_test.go

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ import (
1717
"fmt"
1818
"testing"
1919

20-
"github.com/sqlc-dev/marino/parser"
2120
. "github.com/sqlc-dev/marino/ast"
2221
"github.com/sqlc-dev/marino/format"
23-
"github.com/stretchr/testify/require"
22+
"github.com/sqlc-dev/marino/parser"
23+
24+
"reflect"
25+
"regexp"
26+
"strings"
2427
)
2528

2629
func TestDMLVisitorCover(t *testing.T) {
@@ -68,8 +71,12 @@ func TestDMLVisitorCover(t *testing.T) {
6871
for _, v := range stmts {
6972
ce.reset()
7073
v.node.Accept(checkVisitor{})
71-
require.Equal(t, v.expectedEnterCnt, ce.enterCnt)
72-
require.Equal(t, v.expectedLeaveCnt, ce.leaveCnt)
74+
if !reflect.DeepEqual(v.expectedEnterCnt, ce.enterCnt) {
75+
t.Fatalf("got %v, want %v", ce.enterCnt, v.expectedEnterCnt)
76+
}
77+
if !reflect.DeepEqual(v.expectedLeaveCnt, ce.leaveCnt) {
78+
t.Fatalf("got %v, want %v", ce.leaveCnt, v.expectedLeaveCnt)
79+
}
7380
v.node.Accept(visitor1{})
7481
}
7582
}
@@ -630,9 +637,15 @@ func TestImportIntoRestore(t *testing.T) {
630637
}
631638

632639
func TestFulltextSearchModifier(t *testing.T) {
633-
require.False(t, FulltextSearchModifier(FulltextSearchModifierNaturalLanguageMode).IsBooleanMode())
634-
require.True(t, FulltextSearchModifier(FulltextSearchModifierNaturalLanguageMode).IsNaturalLanguageMode())
635-
require.False(t, FulltextSearchModifier(FulltextSearchModifierNaturalLanguageMode).WithQueryExpansion())
640+
if FulltextSearchModifier(FulltextSearchModifierNaturalLanguageMode).IsBooleanMode() {
641+
t.Fatal("expected false")
642+
}
643+
if !(FulltextSearchModifier(FulltextSearchModifierNaturalLanguageMode).IsNaturalLanguageMode()) {
644+
t.Fatal("expected true")
645+
}
646+
if FulltextSearchModifier(FulltextSearchModifierNaturalLanguageMode).WithQueryExpansion() {
647+
t.Fatal("expected false")
648+
}
636649
}
637650

638651
func TestImportIntoSecureText(t *testing.T) {
@@ -658,19 +671,31 @@ func TestImportIntoSecureText(t *testing.T) {
658671
for _, tc := range testCases {
659672
comment := fmt.Sprintf("input = %s", tc.input)
660673
node, err := p.ParseOneStmt(tc.input, "", "")
661-
require.NoError(t, err, comment)
674+
if err != nil {
675+
t.Fatalf("%v: %v", comment, err)
676+
}
662677
n, ok := node.(SensitiveStmtNode)
663-
require.True(t, ok, comment)
664-
require.Regexp(t, tc.secured, n.SecureText(), comment)
678+
if !(ok) {
679+
t.Fatal(comment)
680+
}
681+
if !regexp.MustCompile(tc.secured).MatchString(n.SecureText()) {
682+
t.Fatalf("%v: expected %q to match %q", comment, n.SecureText(), tc.secured)
683+
}
665684
}
666685
}
667686

668687
func TestImportIntoFromSelectInvalidStmt(t *testing.T) {
669688
p := parser.New()
670689
_, err := p.ParseOneStmt("IMPORT INTO t1(a, @1) FROM select * from t2;", "", "")
671-
require.ErrorContains(t, err, "Cannot use user variable(1) in IMPORT INTO FROM SELECT statement")
690+
if err == nil || !strings.Contains(err.Error(), "Cannot use user variable(1) in IMPORT INTO FROM SELECT statement") {
691+
t.Fatalf("expected error containing %q, got %v", "Cannot use user variable(1) in IMPORT INTO FROM SELECT statement", err)
692+
}
672693
_, err = p.ParseOneStmt("IMPORT INTO t1(a, @b) FROM select * from t2;", "", "")
673-
require.ErrorContains(t, err, "Cannot use user variable(b) in IMPORT INTO FROM SELECT statement")
694+
if err == nil || !strings.Contains(err.Error(), "Cannot use user variable(b) in IMPORT INTO FROM SELECT statement") {
695+
t.Fatalf("expected error containing %q, got %v", "Cannot use user variable(b) in IMPORT INTO FROM SELECT statement", err)
696+
}
674697
_, err = p.ParseOneStmt("IMPORT INTO t1(a) set a=1 FROM select a from t2;", "", "")
675-
require.ErrorContains(t, err, "Cannot use SET clause in IMPORT INTO FROM SELECT statement.")
698+
if err == nil || !strings.Contains(err.Error(), "Cannot use SET clause in IMPORT INTO FROM SELECT statement.") {
699+
t.Fatalf("expected error containing %q, got %v", "Cannot use SET clause in IMPORT INTO FROM SELECT statement.", err)
700+
}
676701
}

ast/expressions_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import (
1919
. "github.com/sqlc-dev/marino/ast"
2020
"github.com/sqlc-dev/marino/format"
2121
"github.com/sqlc-dev/marino/mysql"
22-
"github.com/stretchr/testify/require"
22+
23+
"reflect"
2324
)
2425

2526
type checkVisitor struct{}
@@ -94,8 +95,12 @@ func TestExpresionsVisitorCover(t *testing.T) {
9495
for _, v := range stmts {
9596
ce.reset()
9697
v.node.Accept(checkVisitor{})
97-
require.Equal(t, v.expectedEnterCnt, ce.enterCnt)
98-
require.Equal(t, v.expectedLeaveCnt, ce.leaveCnt)
98+
if !reflect.DeepEqual(v.expectedEnterCnt, ce.enterCnt) {
99+
t.Fatalf("got %v, want %v", ce.enterCnt, v.expectedEnterCnt)
100+
}
101+
if !reflect.DeepEqual(v.expectedLeaveCnt, ce.leaveCnt) {
102+
t.Fatalf("got %v, want %v", ce.leaveCnt, v.expectedLeaveCnt)
103+
}
99104
v.node.Accept(visitor1{})
100105
}
101106
}

ast/flag_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
package ast_test
1515

1616
import (
17+
"fmt"
1718
"testing"
1819

19-
"github.com/sqlc-dev/marino/parser"
2020
"github.com/sqlc-dev/marino/ast"
21-
"github.com/stretchr/testify/require"
21+
"github.com/sqlc-dev/marino/parser"
22+
23+
"reflect"
2224
)
2325

2426
func TestHasAggFlag(t *testing.T) {
@@ -33,7 +35,9 @@ func TestHasAggFlag(t *testing.T) {
3335
}
3436
for _, tt := range flagTests {
3537
expr.SetFlag(tt.flag)
36-
require.Equal(t, tt.hasAgg, ast.HasAggFlag(expr))
38+
if !reflect.DeepEqual(tt.hasAgg, ast.HasAggFlag(expr)) {
39+
t.Fatalf("got %v, want %v", ast.HasAggFlag(expr), tt.hasAgg)
40+
}
3741
}
3842
}
3943

@@ -130,10 +134,14 @@ func TestFlag(t *testing.T) {
130134
p := parser.New()
131135
for _, tt := range flagTests {
132136
stmt, err := p.ParseOneStmt("select "+tt.expr, "", "")
133-
require.NoError(t, err)
137+
if err != nil {
138+
t.Fatal(err)
139+
}
134140
selectStmt := stmt.(*ast.SelectStmt)
135141
ast.SetFlag(selectStmt)
136142
expr := selectStmt.Fields.Fields[0].Expr
137-
require.Equalf(t, tt.flag, expr.GetFlag(), "For %s", tt.expr)
143+
if !reflect.DeepEqual(tt.flag, expr.GetFlag()) {
144+
t.Fatalf("%s: got %v, want %v", fmt.Sprintf("For %s", tt.expr), expr.GetFlag(), tt.flag)
145+
}
138146
}
139147
}

ast/format_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import (
55
"fmt"
66
"testing"
77

8-
"github.com/sqlc-dev/marino/parser"
98
"github.com/sqlc-dev/marino/ast"
10-
"github.com/stretchr/testify/require"
9+
"github.com/sqlc-dev/marino/parser"
10+
11+
"reflect"
1112
)
1213

1314
func getDefaultCharsetAndCollate() (string, string) {
@@ -89,10 +90,14 @@ func TestAstFormat(t *testing.T) {
8990
charset, collation := getDefaultCharsetAndCollate()
9091
stmts, _, err := parser.New().Parse(expr, charset, collation)
9192
node := stmts[0].(*ast.SelectStmt).Fields.Fields[0].Expr
92-
require.NoError(t, err)
93+
if err != nil {
94+
t.Fatal(err)
95+
}
9396

9497
writer := bytes.NewBufferString("")
9598
node.Format(writer)
96-
require.Equal(t, tt.output, writer.String())
99+
if !reflect.DeepEqual(tt.output, writer.String()) {
100+
t.Fatalf("got %v, want %v", writer.String(), tt.output)
101+
}
97102
}
98103
}

0 commit comments

Comments
 (0)