56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package tests_test
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"git.akyoto.dev/cli/q/src/build"
|
|
"git.akyoto.dev/cli/q/src/build/config"
|
|
"git.akyoto.dev/go/assert"
|
|
)
|
|
|
|
var examples = []struct {
|
|
Name string
|
|
Input string
|
|
Output string
|
|
ExitCode int
|
|
}{
|
|
{"hello", "", "Hello\n", 0},
|
|
{"factorial", "", "120", 0},
|
|
{"fibonacci", "", "55", 0},
|
|
{"gcd", "", "21", 0},
|
|
{"array", "", "Hello", 0},
|
|
{"echo", "Echo", "Echo", 0},
|
|
{"itoa", "", "9223372036854775807", 0},
|
|
{"collatz", "", "6 3 10 5 16 8 4 2 1", 0},
|
|
}
|
|
|
|
func TestExamples(t *testing.T) {
|
|
for _, test := range examples {
|
|
directory := filepath.Join("..", "examples", test.Name)
|
|
|
|
t.Run(test.Name+"/debug", func(t *testing.T) {
|
|
config.ConstantFold = false
|
|
run(t, directory, "debug", test.Name, test.Input, test.Output, test.ExitCode)
|
|
})
|
|
|
|
t.Run(test.Name+"/release", func(t *testing.T) {
|
|
config.ConstantFold = true
|
|
run(t, directory, "release", test.Name, test.Input, test.Output, test.ExitCode)
|
|
})
|
|
}
|
|
}
|
|
|
|
func BenchmarkExamples(b *testing.B) {
|
|
for _, test := range examples {
|
|
b.Run(test.Name, func(b *testing.B) {
|
|
compiler := build.New(filepath.Join("..", "examples", test.Name))
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
_, err := compiler.Run()
|
|
assert.Nil(b, err)
|
|
}
|
|
})
|
|
}
|
|
}
|