52 lines
1.0 KiB
Go
Raw Normal View History

2023-10-23 10:37:20 +00:00
package main_test
2023-10-17 12:01:01 +00:00
import (
2023-10-20 11:22:06 +00:00
"io"
"os"
2023-10-17 12:01:01 +00:00
"testing"
2023-10-20 15:07:44 +00:00
"git.akyoto.dev/cli/q/src/cli"
"git.akyoto.dev/cli/q/src/log"
2023-10-17 12:01:01 +00:00
)
2023-10-20 11:22:06 +00:00
func TestMain(m *testing.M) {
log.Info.SetOutput(io.Discard)
log.Error.SetOutput(io.Discard)
os.Exit(m.Run())
}
2023-10-17 12:01:01 +00:00
func TestCLI(t *testing.T) {
type cliTest struct {
arguments []string
expectedExitCode int
}
tests := []cliTest{
2023-10-17 13:10:35 +00:00
{[]string{}, 2},
{[]string{"invalid"}, 2},
2023-10-17 12:01:01 +00:00
{[]string{"system"}, 0},
2023-10-28 10:50:56 +00:00
{[]string{"build", "non-existing-directory"}, 1},
{[]string{"build", "examples/hello/hello.q"}, 1},
{[]string{"build", "examples/hello", "--invalid"}, 2},
2023-10-29 15:16:36 +00:00
{[]string{"build", "examples/hello", "--dry"}, 0},
2023-10-17 12:01:01 +00:00
}
for _, test := range tests {
t.Log(test.arguments)
2023-10-29 15:16:36 +00:00
exitCode := cli.Main(test.arguments)
if exitCode != test.expectedExitCode {
t.Errorf("exit code %d (expected %d)", exitCode, test.expectedExitCode)
t.FailNow()
}
2023-10-17 12:01:01 +00:00
}
}
2023-10-20 11:22:06 +00:00
func BenchmarkBuild(b *testing.B) {
args := []string{"build", "examples/hello", "--dry"}
for i := 0; i < b.N; i++ {
cli.Main(args)
}
}