func _main() int { if envvar := os.Getenv("GOMAXPROCS"); envvar == "" { runtime.GOMAXPROCS(runtime.NumCPU()) } ctx := context.Background() cli := peco.New() if err := cli.Run(ctx); err != nil { switch { case util.IsCollectResultsError(err): selection := cli.Selection() if selection.Len() == 0 { if l, err := cli.CurrentLineBuffer().LineAt(cli.Location().LineNumber()); err == nil { selection.Add(l) } } cli.SetResultCh(make(chan peco.Line)) go cli.CollectResults() case util.IsIgnorableError(err): return 0 default: fmt.Fprintf(os.Stderr, "Error: %s\n", err) return 1 } } buf := bytes.Buffer{} for line := range cli.ResultCh() { buf.WriteString(line.Output()) buf.WriteByte('\n') } os.Stdout.Write(buf.Bytes()) return 0 }
func TestPecoHelp(t *testing.T) { p := newPeco() p.Argv = []string{"peco", "-h"} p.Stdout = &bytes.Buffer{} ctx, cancel := context.WithCancel(context.Background()) time.AfterFunc(time.Second, cancel) err := p.Run(ctx) if !assert.True(t, util.IsIgnorableError(err), "p.Run() should return error with Ignorable() method, and it should return true") { return } }