Implemented echo example
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/build"
|
||||
@ -11,34 +12,35 @@ import (
|
||||
)
|
||||
|
||||
var programs = []struct {
|
||||
Name string
|
||||
ExpectedOutput string
|
||||
ExpectedExitCode int
|
||||
Name string
|
||||
Input string
|
||||
Output string
|
||||
ExitCode int
|
||||
}{
|
||||
{"empty", "", 0},
|
||||
{"math", "", 10},
|
||||
{"precedence", "", 10},
|
||||
{"square-sum", "", 25},
|
||||
{"chained-calls", "", 9},
|
||||
{"nested-calls", "", 4},
|
||||
{"param", "", 3},
|
||||
{"param-multi", "", 21},
|
||||
{"reuse", "", 3},
|
||||
{"return", "", 6},
|
||||
{"reassign", "", 2},
|
||||
{"branch", "", 0},
|
||||
{"branch-and", "", 0},
|
||||
{"branch-or", "", 0},
|
||||
{"branch-both", "", 0},
|
||||
{"jump-near", "", 0},
|
||||
{"loop", "", 0},
|
||||
{"loop-lifetime", "", 0},
|
||||
{"empty", "", "", 0},
|
||||
{"math", "", "", 10},
|
||||
{"precedence", "", "", 10},
|
||||
{"square-sum", "", "", 25},
|
||||
{"chained-calls", "", "", 9},
|
||||
{"nested-calls", "", "", 4},
|
||||
{"param", "", "", 3},
|
||||
{"param-multi", "", "", 21},
|
||||
{"reuse", "", "", 3},
|
||||
{"return", "", "", 6},
|
||||
{"reassign", "", "", 2},
|
||||
{"branch", "", "", 0},
|
||||
{"branch-and", "", "", 0},
|
||||
{"branch-or", "", "", 0},
|
||||
{"branch-both", "", "", 0},
|
||||
{"jump-near", "", "", 0},
|
||||
{"loop", "", "", 0},
|
||||
{"loop-lifetime", "", "", 0},
|
||||
}
|
||||
|
||||
func TestPrograms(t *testing.T) {
|
||||
for _, test := range programs {
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
run(t, filepath.Join("programs", test.Name+".q"), test.ExpectedOutput, test.ExpectedExitCode)
|
||||
run(t, filepath.Join("programs", test.Name+".q"), test.Input, test.Output, test.ExitCode)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -57,7 +59,7 @@ 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, expectedOutput string, expectedExitCode int) {
|
||||
func run(t *testing.T, name string, input string, expectedOutput string, expectedExitCode int) {
|
||||
b := build.New(name)
|
||||
assert.True(t, len(b.Executable()) > 0)
|
||||
|
||||
@ -72,6 +74,7 @@ func run(t *testing.T, name string, expectedOutput string, expectedExitCode int)
|
||||
assert.True(t, stat.Size() > 0)
|
||||
|
||||
cmd := exec.Command(b.Executable())
|
||||
cmd.Stdin = strings.NewReader(input)
|
||||
output, err := cmd.Output()
|
||||
exitCode := 0
|
||||
|
||||
|
Reference in New Issue
Block a user