Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/endtoend/case_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -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"`
}

Expand Down
5 changes: 5 additions & 0 deletions internal/endtoend/ddl_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"
"slices"
"strings"
"testing"
Expand All@@ -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")
Expand Down
55 changes: 47 additions & 8 deletions internal/endtoend/endtoend_test.go
Original file line numberDiff line numberDiff line change
@@ -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 (
Expand All@@ -10,6 +6,7 @@ import (
"os"
osexec "os/exec"
"path/filepath"
"runtime"
"slices"
"strings"
"testing"
Expand All@@ -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()
Expand DownExpand Up@@ -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
},
},
}
Expand DownExpand Up@@ -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"]),
Expand DownExpand Up@@ -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)
}
Expand DownExpand Up@@ -237,15 +271,20 @@ 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
if actual[name] == ""{
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)
}
}
Expand Down
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
{
"process": "sqlc-gen-test"
}
"process": "sqlc-gen-test",
"os": ["linux", "darwin"]
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"wasm": true
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
{
"wasm": true
}
4 changes: 4 additions & 0 deletions internal/ext/wasm/nowasm.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -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")
}
Expand Down
4 changes: 4 additions & 0 deletions internal/ext/wasm/wasm.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -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`

Expand Down