Improved code generation
This commit is contained in:
11
tests/programs/exit.q
Normal file
11
tests/programs/exit.q
Normal file
@ -0,0 +1,11 @@
|
||||
main() {
|
||||
exit(f(1) + f(2) + f(3))
|
||||
}
|
||||
|
||||
exit(code) {
|
||||
syscall(60, code)
|
||||
}
|
||||
|
||||
f(x) {
|
||||
return x + 1
|
||||
}
|
@ -18,6 +18,15 @@ var programs = []struct {
|
||||
{"empty.q", "", 0},
|
||||
{"square-sum.q", "", 25},
|
||||
{"multi-calls.q", "", 9},
|
||||
{"exit.q", "", 9},
|
||||
}
|
||||
|
||||
func TestPrograms(t *testing.T) {
|
||||
for _, test := range programs {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
run(t, filepath.Join("programs", test.Name), test.ExpectedOutput, test.ExpectedExitCode)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPrograms(b *testing.B) {
|
||||
@ -33,14 +42,6 @@ func BenchmarkPrograms(b *testing.B) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrograms(t *testing.T) {
|
||||
for _, test := range programs {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
run(t, filepath.Join("programs", test.Name), test.ExpectedOutput, test.ExpectedExitCode)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// run builds and runs the file to check if the output matches the expected output.
|
||||
func run(t *testing.T, name string, expectedOutput string, expectedExitCode int) {
|
||||
b := build.New(name)
|
||||
|
Reference in New Issue
Block a user