Improved tests
This commit is contained in:
@ -53,19 +53,17 @@ var programs = []struct {
|
||||
}
|
||||
|
||||
func TestPrograms(t *testing.T) {
|
||||
config.ConstantFold = false
|
||||
|
||||
for _, test := range programs {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
run(t, filepath.Join("programs", test.Name+".q"), test.Input, test.Output, test.ExitCode)
|
||||
file := filepath.Join("programs", test.Name+".q")
|
||||
|
||||
t.Run(test.Name+"/debug", func(t *testing.T) {
|
||||
config.ConstantFold = false
|
||||
run(t, file, "debug", test.Name, test.Input, test.Output, test.ExitCode)
|
||||
})
|
||||
}
|
||||
|
||||
config.ConstantFold = true
|
||||
|
||||
for _, test := range programs {
|
||||
t.Run(test.Name+" (optimized)", func(t *testing.T) {
|
||||
run(t, filepath.Join("programs", test.Name+".q"), test.Input, test.Output, test.ExitCode)
|
||||
t.Run(test.Name+"/release", func(t *testing.T) {
|
||||
config.ConstantFold = true
|
||||
run(t, file, "release", test.Name, test.Input, test.Output, test.ExitCode)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -84,21 +82,24 @@ func BenchmarkPrograms(b *testing.B) {
|
||||
}
|
||||
|
||||
// run builds and runs the file to check if the output matches the expected output.
|
||||
func run(t *testing.T, name string, input string, expectedOutput string, expectedExitCode int) {
|
||||
b := build.New(name)
|
||||
assert.True(t, len(b.Executable()) > 0)
|
||||
|
||||
func run(t *testing.T, path string, version string, name string, input string, expectedOutput string, expectedExitCode int) {
|
||||
b := build.New(path)
|
||||
result, err := b.Run()
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = result.Write(b.Executable())
|
||||
directory := filepath.Join(os.TempDir(), "q", version)
|
||||
err = os.MkdirAll(directory, 0755)
|
||||
assert.Nil(t, err)
|
||||
|
||||
stat, err := os.Stat(b.Executable())
|
||||
executable := filepath.Join(directory, name)
|
||||
err = result.WriteFile(executable)
|
||||
assert.Nil(t, err)
|
||||
|
||||
stat, err := os.Stat(executable)
|
||||
assert.Nil(t, err)
|
||||
assert.True(t, stat.Size() > 0)
|
||||
|
||||
cmd := exec.Command(b.Executable())
|
||||
cmd := exec.Command(executable)
|
||||
cmd.Stdin = strings.NewReader(input)
|
||||
output, err := cmd.Output()
|
||||
exitCode := 0
|
||||
|
Reference in New Issue
Block a user