Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions mod/tigron/internal/com/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Result struct {
Stderr string
ExitCode int
Signal os.Signal
Duration time.Duration
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store command execution time.

}

type execution struct {
Expand Down Expand Up @@ -102,9 +103,10 @@ type Command struct {
ptyStderr bool
ptyStdin bool

exec *execution
mutex sync.Mutex
result *Result
exec *execution
mutex sync.Mutex
result *Result
startTime time.Time
}

// Clone does just duplicate a command, resetting its execution.
Expand Down Expand Up @@ -184,12 +186,12 @@ func (gc *Command) Run(parentCtx context.Context) error {
)

// Get a timing-out context
timeout := gc.Timeout
if timeout == 0 {
timeout = defaultTimeout
if gc.Timeout == 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix 0s being displayed (instead of displaying defaultTimeout) when no explicit timeout has been passed.

gc.Timeout = defaultTimeout
}

ctx, ctxCancel = context.WithTimeout(parentCtx, timeout)
ctx, ctxCancel = context.WithTimeout(parentCtx, gc.Timeout)
gc.startTime = time.Now()

// Create a contextual command, set the logger
cmd = gc.buildCommand(ctx)
Expand Down Expand Up @@ -366,6 +368,7 @@ func (gc *Command) wrap() error {
Stderr: pipes.fromStderr,
Environ: cmd.Environ(),
Signal: signal,
Duration: time.Since(gc.startTime),
}

if gc.exec.err == nil {
Expand Down
5 changes: 4 additions & 1 deletion mod/tigron/internal/formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ func chunk(s string, maxLength, maxLines int) []string {
}

if len(chunks) > maxLines {
chunks = append(chunks[0:maxLines], "...")
abbreviator := "..."
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of stripping anything after line maxLines, we now keep maxLines/2 from the start and from the end.

chunks = append(
append(chunks[0:maxLines/2], abbreviator+strings.Repeat(spacer, maxLength-len(abbreviator))),
chunks[len(chunks)-maxLines/2:]...)
} else if len(chunks) == 0 {
chunks = []string{strings.Repeat(spacer, maxLength)}
}
Expand Down
2 changes: 1 addition & 1 deletion mod/tigron/test/case.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (test *Case) Run(t *testing.T) {
"\n\n" + formatter.Table(
[][]any{
{startDecorator, fmt.Sprintf("%q: starting test!", test.t.Name())},
{"cwd", test.Data.TempDir()},
{"temp", test.Data.TempDir()},
{"config", string(debugConfig)},
{"data", string(debugData)},
},
Expand Down
20 changes: 17 additions & 3 deletions mod/tigron/test/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const (
exitDecorator = "⚠️"
stdoutDecorator = "🟢"
stderrDecorator = "🟠"
timeoutDecorator = "⏰"
cwdDecorator = "📁"
envDecorator = "🌱"
sigDecorator = "⚡"
)

// CustomizableCommand is an interface meant for people who want to heavily customize the base
Expand Down Expand Up @@ -138,6 +142,10 @@ func (gc *GenericCommand) WithBlacklist(env []string) {
gc.cmd.EnvBlackList = env
}

func (gc *GenericCommand) WithWhitelist(env []string) {
gc.cmd.EnvWhiteList = env
}

func (gc *GenericCommand) WithTimeout(timeout time.Duration) {
gc.cmd.Timeout = timeout
}
Expand Down Expand Up @@ -193,12 +201,18 @@ func (gc *GenericCommand) Run(expect *Expected) {
}

if result.Signal != nil {
debug = append(debug, []any{"Signal", result.Signal.String()})
debug = append(debug, []any{"", sigDecorator + " " + result.Signal.String()})
}

duration := result.Duration.String()
if result.Duration < time.Second {
duration = "<1s"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not want to see 123.456789ms

}

debug = append(debug,
[]any{"Limit", gc.cmd.Timeout},
[]any{"Environ", strings.Join(result.Environ, "\n")},
[]any{envDecorator, strings.Join(result.Environ, "\n")},
[]any{timeoutDecorator, duration + " (limit: " + gc.cmd.Timeout.String() + ")"},
[]any{cwdDecorator, gc.cmd.WorkingDir},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show cwd and better duration info.

)
}

Expand Down
19 changes: 8 additions & 11 deletions pkg/testutil/nerdtest/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,14 @@ func newNerdCommand(conf test.Config, t *testing.T) *nerdCommand {
}

ret.WithBinary(binary)
// Not interested in these - and insulate us from parent environment side effects
ret.WithBlacklist([]string{
"LS_COLORS",
"DOCKER_CONFIG",
"CONTAINERD_SNAPSHOTTER",
"NERDCTL_TOML",
"CONTAINERD_ADDRESS",
"CNI_PATH",
"NETCONFPATH",
"NERDCTL_EXPERIMENTAL",
"NERDCTL_HOST_GATEWAY_IP",
ret.WithWhitelist([]string{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use whitelist to tame os.Environ on the CI.

"PATH",
"HOME",
"XDG_*",
// Windows needs ProgramData, AppData, etc
"Program*",
"PROGRAM*",
"APPDATA",
})
return ret
}
Expand Down
Loading