diff --git a/internal/endtoend/case_test.go b/internal/endtoend/case_test.go index 367b9dd158..208b3fb9fa 100644 --- a/internal/endtoend/case_test.go +++ b/internal/endtoend/case_test.go @@ -21,6 +21,8 @@ type Exec struct { Command string `json:"command"` Contexts []string `json:"contexts"` Process string `json:"process"` + OS []string `json:"os"` + WASM bool `json:"wasm"` Env map[string]string `json:"env"` } diff --git a/internal/endtoend/ddl_test.go b/internal/endtoend/ddl_test.go index c77389207d..71ea2052c9 100644 --- a/internal/endtoend/ddl_test.go +++ b/internal/endtoend/ddl_test.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "runtime" "slices" "strings" "testing" @@ -19,6 +20,10 @@ import ( ) func TestValidSchema(t *testing.T) { + if os.Getenv("CI") != "" && runtime.GOOS != "linux" { + t.Skipf("only run these tests in CI on linux: %s %s", os.Getenv("CI"), runtime.GOOS) + } + ctx := context.Background() projectID := os.Getenv("CI_SQLC_PROJECT_ID") diff --git a/internal/endtoend/endtoend_test.go b/internal/endtoend/endtoend_test.go index 10cd065c37..2054baeee3 100644 --- a/internal/endtoend/endtoend_test.go +++ b/internal/endtoend/endtoend_test.go @@ -1,7 +1,3 @@ -// Currently requires cgo for wasmtime and has line-ending issues on windows. -//go:build cgo && !windows -// +build cgo,!windows - package main import ( @@ -10,6 +6,7 @@ import ( "os" osexec "os/exec" "path/filepath" + "runtime" "slices" "strings" "testing" @@ -19,9 +16,24 @@ import ( "github.com/sqlc-dev/sqlc/internal/cmd" "github.com/sqlc-dev/sqlc/internal/config" + "github.com/sqlc-dev/sqlc/internal/ext/wasm" "github.com/sqlc-dev/sqlc/internal/opts" ) +func lineEndings() cmp.Option { + return cmp.Transformer("LineEndings", func(in string) string { + // Replace Windows new lines with Unix newlines + return strings.Replace(in, "\r\n", "\n", -1) + }) +} + +func stderrTransformer() cmp.Option { + return cmp.Transformer("Stderr", func(in string) string { + s := strings.Replace(in, "\r", "", -1) + return strings.Replace(s, "\\", "/", -1) + }) +} + func TestExamples(t *testing.T) { t.Parallel() ctx := context.Background() @@ -115,7 +127,15 @@ func TestReplay(t *testing.T) { } }, Enabled: func() bool { - return len(os.Getenv("SQLC_AUTH_TOKEN")) > 0 + // Return false if no auth token exists + if len(os.Getenv("SQLC_AUTH_TOKEN")) == 0 { + return false + } + // In CI, only run these tests from Linux + if os.Getenv("CI") != "" { + return runtime.GOOS == "linux" + } + return true }, }, } @@ -157,6 +177,16 @@ func TestReplay(t *testing.T) { } } + if args.WASM && !wasm.Enabled() { + t.Skipf("wasm support not enabled") + } + + if len(args.OS) > 0 { + if !slices.Contains(args.OS, runtime.GOOS) { + t.Skipf("unsupported os: %s", runtime.GOOS) + } + } + opts := cmd.Options{ Env: cmd.Env{ Debug: opts.DebugFromString(args.Env["SQLCDEBUG"]), @@ -184,7 +214,11 @@ func TestReplay(t *testing.T) { t.Fatalf("sqlc %s failed: %s", args.Command, stderr.String()) } - diff := cmp.Diff(strings.TrimSpace(expected), strings.TrimSpace(stderr.String())) + diff := cmp.Diff( + strings.TrimSpace(expected), + strings.TrimSpace(stderr.String()), + stderrTransformer(), + ) if diff != "" { t.Fatalf("stderr differed (-want +got):\n%s", diff) } @@ -237,7 +271,12 @@ func cmpDirectory(t *testing.T, dir string, actual map[string]string) { t.Fatal(err) } - if !cmp.Equal(expected, actual, cmpopts.EquateEmpty()) { + opts := []cmp.Option{ + cmpopts.EquateEmpty(), + lineEndings(), + } + + if !cmp.Equal(expected, actual, opts...) { t.Errorf("%s contents differ", dir) for name, contents := range expected { name := name @@ -245,7 +284,7 @@ func cmpDirectory(t *testing.T, dir string, actual map[string]string) { t.Errorf("%s is empty", name) return } - if diff := cmp.Diff(contents, actual[name]); diff != "" { + if diff := cmp.Diff(contents, actual[name], opts...); diff != "" { t.Errorf("%s differed (-want +got):\n%s", name, diff) } } diff --git a/internal/endtoend/testdata/process_plugin_sqlc_gen_test/exec.json b/internal/endtoend/testdata/process_plugin_sqlc_gen_test/exec.json index 7865c9ec17..1aa4920cb9 100644 --- a/internal/endtoend/testdata/process_plugin_sqlc_gen_test/exec.json +++ b/internal/endtoend/testdata/process_plugin_sqlc_gen_test/exec.json @@ -1,3 +1,4 @@ { - "process": "sqlc-gen-test" -} \ No newline at end of file + "process": "sqlc-gen-test", + "os": ["linux", "darwin"] +} diff --git a/internal/endtoend/testdata/wasm_plugin_sqlc_gen_greeter/exec.json b/internal/endtoend/testdata/wasm_plugin_sqlc_gen_greeter/exec.json new file mode 100644 index 0000000000..efe8bbc9aa --- /dev/null +++ b/internal/endtoend/testdata/wasm_plugin_sqlc_gen_greeter/exec.json @@ -0,0 +1,3 @@ +{ + "wasm": true +} diff --git a/internal/endtoend/testdata/wasm_plugin_sqlc_gen_test/exec.json b/internal/endtoend/testdata/wasm_plugin_sqlc_gen_test/exec.json new file mode 100644 index 0000000000..efe8bbc9aa --- /dev/null +++ b/internal/endtoend/testdata/wasm_plugin_sqlc_gen_test/exec.json @@ -0,0 +1,3 @@ +{ + "wasm": true +} diff --git a/internal/ext/wasm/nowasm.go b/internal/ext/wasm/nowasm.go index 419c6eefef..14af0b54a2 100644 --- a/internal/ext/wasm/nowasm.go +++ b/internal/ext/wasm/nowasm.go @@ -10,6 +10,10 @@ import ( "google.golang.org/grpc/status" ) +func Enabled() bool { + return false +} + func (r *Runner) Invoke(ctx context.Context, method string, args any, reply any, opts ...grpc.CallOption) error { return status.Error(codes.FailedPrecondition, "sqlc built without wasmtime support") } diff --git a/internal/ext/wasm/wasm.go b/internal/ext/wasm/wasm.go index d0a2d4c047..c096ec9844 100644 --- a/internal/ext/wasm/wasm.go +++ b/internal/ext/wasm/wasm.go @@ -31,6 +31,10 @@ import ( "github.com/sqlc-dev/sqlc/internal/plugin" ) +func Enabled() bool { + return true +} + // This version must be updated whenever the wasmtime-go dependency is updated const wasmtimeVersion = `v14.0.0`