package main_test import ( "io" "os" "testing" "git.akyoto.dev/cli/q/src/cli" "git.akyoto.dev/cli/q/src/log" ) 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 { t.Log(test.arguments) exitCode := cli.Main(test.arguments) if exitCode != test.expectedExitCode { t.Errorf("exit code %d (expected %d)", exitCode, test.expectedExitCode) t.FailNow() } } } func BenchmarkBuild(b *testing.B) { args := []string{"build", "examples/hello", "--dry"} for i := 0; i < b.N; i++ { cli.Main(args) } }