Skip to content

Commit 5711734

Browse files
authored
internal/endtoend: Move more tests to the record/replay framework
The tests contained in `query_test.go` and `checks_test.go` have been ported to the endtoend testing framework. Those tests now live in directories under internal/endtoend/testdata. The old tests only focused on parts of the execution path run by `sqlc generate`. The new tests execute the exact same code as `sqlc generate`, end to end. Going forward, most tests should be written using this framework.
1 parent f2ad76c commit 5711734

File tree

228 files changed

+4461
-1116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+4461
-1116
lines changed

internal/cmd/generate.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"io/ioutil"
88
"path/filepath"
9+
"strings"
910

1011
"github.com/kyleconroy/sqlc/internal/dinosql"
1112
"github.com/kyleconroy/sqlc/internal/mysql"
@@ -26,6 +27,11 @@ The only supported version is "1".
2627

2728
const errMessageNoPackages = `No packages are configured`
2829

30+
func printFileErr(stderr io.Writer, dir string, fileErr dinosql.FileErr) {
31+
filename := strings.TrimPrefix(fileErr.Filename, dir+"/")
32+
fmt.Fprintf(stderr, "%s:%d:%d: %s\n", filename, fileErr.Line, fileErr.Column, fileErr.Err)
33+
}
34+
2935
func Generate(dir string, stderr io.Writer) (map[string]string, error) {
3036
blob, err := ioutil.ReadFile(filepath.Join(dir, "sqlc.json"))
3137
if err != nil {
@@ -68,7 +74,7 @@ func Generate(dir string, stderr io.Writer) (map[string]string, error) {
6874
fmt.Fprintf(stderr, "# package %s\n", name)
6975
if parserErr, ok := err.(*dinosql.ParserErr); ok {
7076
for _, fileErr := range parserErr.Errs {
71-
fmt.Fprintf(stderr, "%s:%d:%d: %s\n", fileErr.Filename, fileErr.Line, fileErr.Column, fileErr.Err)
77+
printFileErr(stderr, dir, fileErr)
7278
}
7379
} else {
7480
fmt.Fprintf(stderr, "error parsing schema: %s\n", err)
@@ -84,7 +90,7 @@ func Generate(dir string, stderr io.Writer) (map[string]string, error) {
8490
fmt.Fprintf(stderr, "# package %s\n", name)
8591
if parserErr, ok := err.(*dinosql.ParserErr); ok {
8692
for _, fileErr := range parserErr.Errs {
87-
fmt.Fprintf(stderr, "%s:%d:%d: %s\n", fileErr.Filename, fileErr.Line, fileErr.Column, fileErr.Err)
93+
printFileErr(stderr, dir, fileErr)
8894
}
8995
} else {
9096
fmt.Fprintf(stderr, "error parsing schema: %s\n", err)
@@ -98,7 +104,7 @@ func Generate(dir string, stderr io.Writer) (map[string]string, error) {
98104
fmt.Fprintf(stderr, "# package %s\n", name)
99105
if parserErr, ok := err.(*dinosql.ParserErr); ok {
100106
for _, fileErr := range parserErr.Errs {
101-
fmt.Fprintf(stderr, "%s:%d:%d: %s\n", fileErr.Filename, fileErr.Line, fileErr.Column, fileErr.Err)
107+
printFileErr(stderr, dir, fileErr)
102108
}
103109
} else {
104110
fmt.Fprintf(stderr, "error parsing queries: %s\n", err)

internal/dinosql/checks_test.go

Lines changed: 0 additions & 84 deletions
This file was deleted.

0 commit comments

Comments
 (0)