1- // Currently requires cgo for wasmtime and has line-ending issues on windows.
2- //go:build cgo && !windows
3- // +build cgo,!windows
4-
51package main
62
73import (
@@ -10,6 +6,7 @@ import (
106 "os"
117 osexec "os/exec"
128 "path/filepath"
9+ "runtime"
1310 "slices"
1411 "strings"
1512 "testing"
@@ -19,9 +16,24 @@ import (
1916
2017 "github.com/sqlc-dev/sqlc/internal/cmd"
2118 "github.com/sqlc-dev/sqlc/internal/config"
19+ "github.com/sqlc-dev/sqlc/internal/ext/wasm"
2220 "github.com/sqlc-dev/sqlc/internal/opts"
2321)
2422
23+ func lineEndings () cmp.Option {
24+ return cmp .Transformer ("LineEndings" , func (in string ) string {
25+ // Replace Windows new lines with Unix newlines
26+ return strings .Replace (in , "\r \n " , "\n " , - 1 )
27+ })
28+ }
29+
30+ func stderrTransformer () cmp.Option {
31+ return cmp .Transformer ("Stderr" , func (in string ) string {
32+ s := strings .Replace (in , "\r " , "" , - 1 )
33+ return strings .Replace (s , "\\ " , "/" , - 1 )
34+ })
35+ }
36+
2537func TestExamples (t * testing.T ) {
2638 t .Parallel ()
2739 ctx := context .Background ()
@@ -115,7 +127,15 @@ func TestReplay(t *testing.T) {
115127 }
116128 },
117129 Enabled : func () bool {
118- return len (os .Getenv ("SQLC_AUTH_TOKEN" )) > 0
130+ // Return false if no auth token exists
131+ if len (os .Getenv ("SQLC_AUTH_TOKEN" )) == 0 {
132+ return false
133+ }
134+ // In CI, only run these tests from Linux
135+ if os .Getenv ("CI" ) != "" {
136+ return runtime .GOOS == "linux"
137+ }
138+ return true
119139 },
120140 },
121141 }
@@ -157,6 +177,16 @@ func TestReplay(t *testing.T) {
157177 }
158178 }
159179
180+ if args .WASM && ! wasm .Enabled () {
181+ t .Skipf ("wasm support not enabled" )
182+ }
183+
184+ if len (args .OS ) > 0 {
185+ if ! slices .Contains (args .OS , runtime .GOOS ) {
186+ t .Skipf ("unsupported os: %s" , runtime .GOOS )
187+ }
188+ }
189+
160190 opts := cmd.Options {
161191 Env : cmd.Env {
162192 Debug : opts .DebugFromString (args .Env ["SQLCDEBUG" ]),
@@ -184,7 +214,11 @@ func TestReplay(t *testing.T) {
184214 t .Fatalf ("sqlc %s failed: %s" , args .Command , stderr .String ())
185215 }
186216
187- diff := cmp .Diff (strings .TrimSpace (expected ), strings .TrimSpace (stderr .String ()))
217+ diff := cmp .Diff (
218+ strings .TrimSpace (expected ),
219+ strings .TrimSpace (stderr .String ()),
220+ stderrTransformer (),
221+ )
188222 if diff != "" {
189223 t .Fatalf ("stderr differed (-want +got):\n %s" , diff )
190224 }
@@ -237,15 +271,20 @@ func cmpDirectory(t *testing.T, dir string, actual map[string]string) {
237271 t .Fatal (err )
238272 }
239273
240- if ! cmp .Equal (expected , actual , cmpopts .EquateEmpty ()) {
274+ opts := []cmp.Option {
275+ cmpopts .EquateEmpty (),
276+ lineEndings (),
277+ }
278+
279+ if ! cmp .Equal (expected , actual , opts ... ) {
241280 t .Errorf ("%s contents differ" , dir )
242281 for name , contents := range expected {
243282 name := name
244283 if actual [name ] == "" {
245284 t .Errorf ("%s is empty" , name )
246285 return
247286 }
248- if diff := cmp .Diff (contents , actual [name ]); diff != "" {
287+ if diff := cmp .Diff (contents , actual [name ], opts ... ); diff != "" {
249288 t .Errorf ("%s differed (-want +got):\n %s" , name , diff )
250289 }
251290 }
0 commit comments