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}, {[]string{"build", "examples/hello", "--dry", "--verbose"}, 0}, } for _, test := range tests { t.Log(test.arguments) exitCode := cli.Main(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) } }