Skip to content

Commit

Permalink
Fix print --with-totals for multiline record summaries
Browse files Browse the repository at this point in the history
There was a bug when printing records with multiline summaries with the
`--with-totals` flag.

It used to print:

```
 8h15m  |  2018-03-26
        |  Line 1
Line 2
 2h45m  |      8:30 - 11:15 asdf
        |          asdf
        |          asdf
        |          asdf
  1h5m  |      11:15 - 12:20
 4h25m  |      13:30 - 17:55`

```

Where it should (and now does) print:

```
 8h15m  |  2018-03-26
        |  Line 1
        |  Line 2
 2h45m  |      8:30 - 11:15 asdf
        |          asdf
        |          asdf
        |          asdf
  1h5m  |      11:15 - 12:20
 4h25m  |      13:30 - 17:55
```
  • Loading branch information
jotaen authored Feb 29, 2024
1 parent ff5e3bf commit 35a44d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions klog/app/cli/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func TestPrintRecordsWithDurations(t *testing.T) {
state, err := NewTestingContext()._SetNow(2018, 02, 07, 19, 00)._SetRecords(`
2018-01-31
Hello #world
Test test test
1h
2018-02-04
Expand All @@ -93,6 +94,7 @@ Hello #world
2018-02-07
35m
Foo
Bar
18:00 - ? I just
started something
`)._Run((&Print{
Expand All @@ -102,6 +104,7 @@ Hello #world
assert.Equal(t, `
1h | 2018-01-31
| Hello #world
| Test test test
1h | 1h
13h17m | 2018-02-04
Expand All @@ -112,6 +115,7 @@ Hello #world
35m | 2018-02-07
35m | 35m
| Foo
| Bar
0m | 18:00 - ? I just
| started something
Expand Down
4 changes: 2 additions & 2 deletions klog/parser/serialiser.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func serialiseRecord(s Serialiser, r klog.Record) []Line {
headline += " (" + s.ShouldTotal(r.ShouldTotal()) + ")"
}
lines = append(lines, Line{headline, r, -1})
if r.Summary() != nil {
lines = append(lines, Line{s.Summary(SummaryText(r.Summary())), r, -1})
for _, l := range r.Summary().Lines() {
lines = append(lines, Line{s.Summary([]string{l}), r, -1})
}
for entryI, e := range r.Entries() {
entryValue := klog.Unbox[string](&e,
Expand Down

0 comments on commit 35a44d2

Please sign in to comment.