Created
September 12, 2024 15:42
-
-
Save apstndb/db15a21c61ac9a2cfd396a3dcad0102a to your computer and use it in GitHub Desktop.
memefish cloud-spanner-emulator test runner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"encoding/csv" | |
"flag" | |
"fmt" | |
parser "github.com/cloudspannerecosystem/memefish" | |
"github.com/cloudspannerecosystem/memefish/token" | |
"log" | |
"os" | |
"strings" | |
) | |
const ( | |
testCaseDelimiter = "==" | |
inputDelimiter = "--" | |
commentPrefix = "# " | |
regexFlag = "--regex" | |
) | |
func run(ctx context.Context) error { | |
file := flag.String("file", "", "") | |
flag.Parse() | |
b, err := os.ReadFile(*file) | |
if err != nil { | |
return err | |
} | |
csvWriter := csv.NewWriter(os.Stdout) | |
csvWriter.Write([]string{"filename", "no", "input", "expected", "err", "result", "comment"}) | |
for i, testcase := range strings.Split(string(b), "\n"+testCaseDelimiter+"\n") { | |
if strings.TrimSpace(testcase) == "" { | |
continue | |
} | |
before, after, found := strings.Cut(testcase, "\n"+inputDelimiter+"\n") | |
shouldError := !found || | |
strings.HasPrefix(after, "ERROR:") || | |
strings.HasPrefix(after, "Cannot") || | |
strings.HasPrefix(after, "Unsupported") || | |
strings.HasSuffix(strings.TrimSpace(after), ".") | |
p := &parser.Parser{ | |
Lexer: &parser.Lexer{ | |
File: &token.File{FilePath: *file, Buffer: before}, | |
}, | |
} | |
_, err := p.ParseDDLs() | |
// if !shouldError { | |
// if err != nil { | |
// log.Printf("fail: %v: %v", err, before) | |
// continue | |
// } | |
// continue | |
// log.Printf("success: %v", before) | |
// } else { | |
// if err != nil { | |
// continue | |
// log.Printf("error as expected: %v", before) | |
// continue | |
// } | |
// log.Printf("should %v: %v", after, before) | |
// } | |
csvWriter.Write([]string{*file, fmt.Sprint(i), before, after, fmt.Sprint(err), fmt.Sprint(shouldError == (err != nil)), ""}) | |
} | |
csvWriter.Flush() | |
return nil | |
} | |
func main() { | |
if err := run(context.Background()); err != nil { | |
log.Fatalln(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment