Skip to content

Commit df5fc78

Browse files
authored
Merge pull request #4111 from apostasie/ci-fix-debug
[CI]: quality of life: minor debugging output fixes
2 parents 32c65c6 + d439da9 commit df5fc78

File tree

5 files changed

+40
-23
lines changed

5 files changed

+40
-23
lines changed

mod/tigron/internal/com/command.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type Result struct {
7070
Stderr string
7171
ExitCode int
7272
Signal os.Signal
73+
Duration time.Duration
7374
}
7475

7576
type execution struct {
@@ -102,9 +103,10 @@ type Command struct {
102103
ptyStderr bool
103104
ptyStdin bool
104105

105-
exec *execution
106-
mutex sync.Mutex
107-
result *Result
106+
exec *execution
107+
mutex sync.Mutex
108+
result *Result
109+
startTime time.Time
108110
}
109111

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

186188
// Get a timing-out context
187-
timeout := gc.Timeout
188-
if timeout == 0 {
189-
timeout = defaultTimeout
189+
if gc.Timeout == 0 {
190+
gc.Timeout = defaultTimeout
190191
}
191192

192-
ctx, ctxCancel = context.WithTimeout(parentCtx, timeout)
193+
ctx, ctxCancel = context.WithTimeout(parentCtx, gc.Timeout)
194+
gc.startTime = time.Now()
193195

194196
// Create a contextual command, set the logger
195197
cmd = gc.buildCommand(ctx)
@@ -366,6 +368,7 @@ func (gc *Command) wrap() error {
366368
Stderr: pipes.fromStderr,
367369
Environ: cmd.Environ(),
368370
Signal: signal,
371+
Duration: time.Since(gc.startTime),
369372
}
370373

371374
if gc.exec.err == nil {

mod/tigron/internal/formatter/formatter.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ func chunk(s string, maxLength, maxLines int) []string {
108108
}
109109

110110
if len(chunks) > maxLines {
111-
chunks = append(chunks[0:maxLines], "...")
111+
abbreviator := "..."
112+
chunks = append(
113+
append(chunks[0:maxLines/2], abbreviator+strings.Repeat(spacer, maxLength-len(abbreviator))),
114+
chunks[len(chunks)-maxLines/2:]...)
112115
} else if len(chunks) == 0 {
113116
chunks = []string{strings.Repeat(spacer, maxLength)}
114117
}

mod/tigron/test/case.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func (test *Case) Run(t *testing.T) {
233233
"\n\n" + formatter.Table(
234234
[][]any{
235235
{startDecorator, fmt.Sprintf("%q: starting test!", test.t.Name())},
236-
{"cwd", test.Data.TempDir()},
236+
{"temp", test.Data.TempDir()},
237237
{"config", string(debugConfig)},
238238
{"data", string(debugData)},
239239
},

mod/tigron/test/command.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const (
3939
exitDecorator = "⚠️"
4040
stdoutDecorator = "🟢"
4141
stderrDecorator = "🟠"
42+
timeoutDecorator = "⏰"
43+
cwdDecorator = "📁"
44+
envDecorator = "🌱"
45+
sigDecorator = "⚡"
4246
)
4347

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

145+
func (gc *GenericCommand) WithWhitelist(env []string) {
146+
gc.cmd.EnvWhiteList = env
147+
}
148+
141149
func (gc *GenericCommand) WithTimeout(timeout time.Duration) {
142150
gc.cmd.Timeout = timeout
143151
}
@@ -193,12 +201,18 @@ func (gc *GenericCommand) Run(expect *Expected) {
193201
}
194202

195203
if result.Signal != nil {
196-
debug = append(debug, []any{"Signal", result.Signal.String()})
204+
debug = append(debug, []any{"", sigDecorator + " " + result.Signal.String()})
205+
}
206+
207+
duration := result.Duration.String()
208+
if result.Duration < time.Second {
209+
duration = "<1s"
197210
}
198211

199212
debug = append(debug,
200-
[]any{"Limit", gc.cmd.Timeout},
201-
[]any{"Environ", strings.Join(result.Environ, "\n")},
213+
[]any{envDecorator, strings.Join(result.Environ, "\n")},
214+
[]any{timeoutDecorator, duration + " (limit: " + gc.cmd.Timeout.String() + ")"},
215+
[]any{cwdDecorator, gc.cmd.WorkingDir},
202216
)
203217
}
204218

pkg/testutil/nerdtest/command.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,14 @@ func newNerdCommand(conf test.Config, t *testing.T) *nerdCommand {
8282
}
8383

8484
ret.WithBinary(binary)
85-
// Not interested in these - and insulate us from parent environment side effects
86-
ret.WithBlacklist([]string{
87-
"LS_COLORS",
88-
"DOCKER_CONFIG",
89-
"CONTAINERD_SNAPSHOTTER",
90-
"NERDCTL_TOML",
91-
"CONTAINERD_ADDRESS",
92-
"CNI_PATH",
93-
"NETCONFPATH",
94-
"NERDCTL_EXPERIMENTAL",
95-
"NERDCTL_HOST_GATEWAY_IP",
85+
ret.WithWhitelist([]string{
86+
"PATH",
87+
"HOME",
88+
"XDG_*",
89+
// Windows needs ProgramData, AppData, etc
90+
"Program*",
91+
"PROGRAM*",
92+
"APPDATA",
9693
})
9794
return ret
9895
}

0 commit comments

Comments
 (0)