Skip to content

Commit 330ddf4

Browse files
committed
Cosmetic fixes for testing debug logs
- fix timeout showing 0s instead of default when no explicit timeout is provided - add actual execution time - fix long logs (stdout, stderr) that were showing only the beginning to also show the end - fix formatting issue for "..." - marginally better output for command contextual information Signed-off-by: apostasie <[email protected]>
1 parent 88c6393 commit 330ddf4

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
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: 13 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
@@ -193,12 +197,18 @@ func (gc *GenericCommand) Run(expect *Expected) {
193197
}
194198

195199
if result.Signal != nil {
196-
debug = append(debug, []any{"Signal", result.Signal.String()})
200+
debug = append(debug, []any{"", sigDecorator + " " + result.Signal.String()})
201+
}
202+
203+
duration := result.Duration.String()
204+
if result.Duration < time.Second {
205+
duration = "<1s"
197206
}
198207

199208
debug = append(debug,
200-
[]any{"Limit", gc.cmd.Timeout},
201-
[]any{"Environ", strings.Join(result.Environ, "\n")},
209+
[]any{envDecorator, strings.Join(result.Environ, "\n")},
210+
[]any{timeoutDecorator, duration + " (limit: " + gc.cmd.Timeout.String() + ")"},
211+
[]any{cwdDecorator, gc.cmd.WorkingDir},
202212
)
203213
}
204214

0 commit comments

Comments
 (0)