package cli_test import ( "runtime" "testing" "git.urbach.dev/cli/q/src/cli" "git.urbach.dev/cli/q/src/global" "git.urbach.dev/go/assert" ) func TestExec(t *testing.T) { assert.Equal(t, cli.Exec([]string{"asm", "../../examples/hello"}), 0) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-dry"}), 0) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello/hello.q", "-dry"}), 0) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-dry", "-os", "linux", "-arch", "arm"}), 0) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-dry", "-os", "linux", "-arch", "x86"}), 0) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-dry", "-os", "mac", "-arch", "arm"}), 0) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-dry", "-os", "mac", "-arch", "x86"}), 0) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-dry", "-os", "windows", "-arch", "arm"}), 0) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-dry", "-os", "windows", "-arch", "x86"}), 0) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-dry", "-no-lint"}), 0) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-dry", "-no-optimize"}), 0) assert.Equal(t, cli.Exec([]string{"files", "../../examples/hello"}), 0) assert.Equal(t, cli.Exec([]string{"functions", "../../examples/hello"}), 0) assert.Equal(t, cli.Exec([]string{"format", "../../examples/hello/hello.q"}), 0) assert.Equal(t, cli.Exec([]string{"help"}), 0) assert.Equal(t, cli.Exec([]string{"keywords"}), 0) assert.Equal(t, cli.Exec([]string{"operators"}), 0) assert.Equal(t, cli.Exec([]string{"run", "../../examples/hello"}), 0) assert.Equal(t, cli.Exec([]string{"ssa", "../../examples/hello"}), 0) assert.Equal(t, cli.Exec([]string{"ssa", "../../examples/hello", "-func", "main"}), 0) assert.Equal(t, cli.Exec([]string{"asm", "../../examples/hello", "-func", "main"}), 0) assert.Equal(t, cli.Exec([]string{"version"}), 0) assert.Equal(t, cli.Exec([]string{"../../tests/script.q"}), 0) } func TestExecErrors(t *testing.T) { assert.Equal(t, cli.Exec([]string{"build"}), 1) assert.Equal(t, cli.Exec([]string{"build", "../../src/core/testdata/TypeMismatch.q", "-dry"}), 1) assert.Equal(t, cli.Exec([]string{"run"}), 1) assert.Equal(t, cli.Exec([]string{"_"}), 1) } func TestExecWrongParameters(t *testing.T) { assert.Equal(t, cli.Exec(nil), 2) assert.Equal(t, cli.Exec([]string{"build", "-invalid-parameter"}), 2) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-invalid-parameter"}), 2) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-os"}), 2) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-os", "invalid-os"}), 2) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-arch"}), 2) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-arch", "invalid-arch"}), 2) assert.Equal(t, cli.Exec([]string{"build", "../../examples/hello", "-func", "main"}), 2) assert.Equal(t, cli.Exec([]string{"run", "../../examples/hello", "-func", "main"}), 2) } func TestUnknownArch(t *testing.T) { global.Arch = "unknown" assert.Equal(t, cli.Exec([]string{"build"}), 2) global.Arch = runtime.GOARCH } func TestUnknownOS(t *testing.T) { global.OS = "unknown" assert.Equal(t, cli.Exec([]string{"build"}), 2) global.OS = runtime.GOOS }