func TestDownloadCommand(t *testing.T) { var dl cli.Command = newTestDownloadCommand() args := []string{} res := dl.Run(args) if res != 1 { t.Fatal("should fail with missing args") } args = []string{ "abc, foo", } res = dl.Run(args) if res != 1 { t.Fatal("should fail with invalid program ids") } }
// TestHelperProcessCLI can be called to implement TestHelperProcess // for TestProcess that just executes a CLI command. func TestHelperProcessCLI(t *testing.T, cmd cli.Command) { args := os.Args for len(args) > 0 { if args[0] == "--" { args = args[1:] break } args = args[1:] } if len(args) == 0 || args[0] != "GO_WANT_HELPER_PROCESS" { return } args = args[1:] os.Exit(cmd.Run(args)) }
func (c *KodingContext) run(cmd cli.Command, content io.Reader, destroy bool, argsFunc ArgsFunc) (*paths, error) { // copy all contents from remote to local for operating if err := c.RemoteStorage.Clone(c.ContentID, c.LocalStorage); err != nil { return nil, err } // populate paths paths, err := c.paths() if err != nil { return nil, err } if !destroy && content != nil { // override the current main file if err := c.LocalStorage.Write(paths.mainRelativePath, content); err != nil { return nil, err } } exitCode := cmd.Run(argsFunc(paths, destroy)) if exitCode != 0 { err = fmt.Errorf("apply failed with code: %d, output: %s", exitCode, c.Buffer) } // copy all contents from local to remote for later operating e := c.LocalStorage.Clone(c.ContentID, c.RemoteStorage) if e != nil && err == nil { err = e } if err != nil { return nil, err } return paths, nil }
func assertNoTabs(t *testing.T, c cli.Command) { if strings.ContainsRune(c.Help(), '\t') { t.Errorf("%#v help output contains tabs", c) } }