49 lines
986 B
Go
49 lines
986 B
Go
package main_test
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"testing"
|
|
|
|
"git.akyoto.dev/cli/q/src/cli"
|
|
"git.akyoto.dev/cli/q/src/log"
|
|
"git.akyoto.dev/go/assert"
|
|
)
|
|
|
|
func TestMain(m *testing.M) {
|
|
log.Info.SetOutput(io.Discard)
|
|
log.Error.SetOutput(io.Discard)
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
func TestCLI(t *testing.T) {
|
|
type cliTest struct {
|
|
arguments []string
|
|
expectedExitCode int
|
|
}
|
|
|
|
tests := []cliTest{
|
|
{[]string{}, 2},
|
|
{[]string{"invalid"}, 2},
|
|
{[]string{"system"}, 0},
|
|
// {[]string{"build", "non-existing-directory"}, 1},
|
|
// {[]string{"build", "examples/hello/hello.q"}, 1},
|
|
// {[]string{"build", "examples/hello", "--invalid"}, 2},
|
|
// {[]string{"build", "examples/hello", "--dry"}, 0},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
exitCode := cli.Main(test.arguments)
|
|
t.Log(test.arguments)
|
|
assert.Equal(t, exitCode, test.expectedExitCode)
|
|
}
|
|
}
|
|
|
|
func BenchmarkBuild(b *testing.B) {
|
|
args := []string{"build", "examples/hello", "--dry"}
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
cli.Main(args)
|
|
}
|
|
}
|