diff --git a/cmd.go b/cmd.go index 48e0489..c11367f 100644 --- a/cmd.go +++ b/cmd.go @@ -139,19 +139,11 @@ func testCmd() *cobra.Command { Directives: parsed.Directives, } - var onCommand func(Command) - if verbose { - onCommand = func(c Command) { - fmt.Fprintf(os.Stderr, dim(" $ %s\n"), c.Cmd) - } - } - fileResult := runFile(merged, RunOptions{ - CleanEnv: cleanEnv, - PathDirs: pathDirs, - EnvVars: envVars, - Timeout: timeoutDur, - OnCommand: onCommand, + CleanEnv: cleanEnv, + PathDirs: pathDirs, + EnvVars: envVars, + Timeout: timeoutDur, }) // Check setup commands for failures @@ -179,6 +171,12 @@ func testCmd() *cobra.Command { testResult := evaluateFile(parsed.Path, fileOwnResults, fileResult.Error) + if verbose && fileResult.Error == "" { + for _, r := range fileOwnResults { + fmt.Fprintf(os.Stderr, dim(" $ %s\n"), r.Command.Cmd) + } + } + if update && len(fileOwnResults) > 0 { updated := rewriteFile(parsed, fileOwnResults, string(content)) if updated != string(content) { @@ -272,7 +270,7 @@ func testCmd() *cobra.Command { cmd.Flags().BoolVar(&cleanEnv, "clean-env", false, "Start with empty environment") cmd.Flags().StringArrayVar(&pathDirs, "path", nil, "Prepend to PATH (repeatable)") cmd.Flags().StringVar(&timeout, "timeout", "10s", "Per-command timeout") - cmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Print each command as it runs") + cmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Print each command after it runs") cmd.Flags().IntVar(&portFrom, "port-from", 0, "Auto-assign $PORT starting from ") cmd.Flags().BoolVar(¶llel, "parallel", false, "Run files in parallel") diff --git a/match.go b/match.go index e00d996..6f61fd0 100644 --- a/match.go +++ b/match.go @@ -68,12 +68,17 @@ func diff(expected, actual []string) []DiffLine { if !hasNext { result = append(result, DiffLine{Kind: "context", Text: "..."}) + for ai < len(actual) { + result = append(result, DiffLine{Kind: "context", Text: actual[ai]}) + ai++ + } break } result = append(result, DiffLine{Kind: "context", Text: "..."}) ei++ for ai < len(actual) && !matchLine(nextExp, actual[ai]) { + result = append(result, DiffLine{Kind: "context", Text: actual[ai]}) ai++ } continue diff --git a/match_test.go b/match_test.go index 26ae213..ef4a4ce 100644 --- a/match_test.go +++ b/match_test.go @@ -121,7 +121,16 @@ func TestDiffEqual(t *testing.T) { func TestDiffContext(t *testing.T) { d := diff([]string{"..."}, []string{"a", "b"}) - if len(d) != 1 || d[0].Kind != "context" { - t.Errorf("expected context, got %+v", d) + if len(d) != 3 { + t.Fatalf("expected 3 diff lines, got %d: %+v", len(d), d) + } + if d[0].Kind != "context" || d[0].Text != "..." { + t.Errorf("d[0] = %+v", d[0]) + } + if d[1].Kind != "context" || d[1].Text != "a" { + t.Errorf("d[1] = %+v", d[1]) + } + if d[2].Kind != "context" || d[2].Text != "b" { + t.Errorf("d[2] = %+v", d[2]) } } diff --git a/run.go b/run.go index de24f43..3aace4b 100644 --- a/run.go +++ b/run.go @@ -24,7 +24,7 @@ type RunOptions struct { PathDirs []string EnvVars map[string]string Timeout time.Duration - OnCommand func(Command) + } func buildScript(commands []Command, sentinelPrefix string) string { @@ -168,12 +168,6 @@ func runFile(file ShoutFile, opts RunOptions) FileResult { } }() - if opts.OnCommand != nil { - for _, c := range file.Commands { - opts.OnCommand(c) - } - } - // Read stdout with timeout — must start reader BEFORE writing to stdin // to avoid deadlock when pipe buffers fill in both directions. totalTimeout := opts.Timeout * time.Duration(len(file.Commands)) diff --git a/shout b/shout index 10e5c68..35d7112 100755 Binary files a/shout and b/shout differ diff --git a/update.go b/update.go index 8efa624..5628aee 100644 --- a/update.go +++ b/update.go @@ -101,7 +101,7 @@ func rewriteFile(file ShoutFile, results []CommandResult, originalContent string i = j - 1 cmdIdx++ - } else if cmdIdx == 0 || cmdIdx >= len(file.Commands) { + } else { output = append(output, line) } } @@ -118,5 +118,8 @@ func updateExitCodeMarker(cmd Command, actualExitCode int) string { if actualExitCode != 0 { return fmt.Sprintf("[%d]", actualExitCode) } + if cmd.ExitCodeType == ExitCodeWildcard || cmd.ExitCodeType == ExitCodeExact { + return "[0]" + } return "" }