Skip to content

Commit 3ac61f5

Browse files
authored
Print compact stats instead of verbose when no errors or warnings (#1254)
1 parent 3c2b1ce commit 3ac61f5

File tree

5 files changed

+43
-11
lines changed

5 files changed

+43
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Other improvements:
1313
- Fix output truncation with `--json-errors`, many warnings and build failure (#1199)
1414
- Update README with info about depending on a freshly added library
1515
- Fixed globbing issue where `/.spago` behaves differently than `.spago` in `.gitignore`
16+
- Fixed empty output for `--verbose-stats` when there are no errors or warnings.
1617

1718
## [0.21.0] - 2023-05-04
1819

src/Spago/Psa/Output.purs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
-- A majority of this code was copied from
22
-- - https://github.com/natefaubion/purescript-psa-utils
3-
--
3+
--
44
-- To fullfil license requirements
55
-- Copyright © Nathan Faubion
66
-- https://opensource.org/license/mit/
77
module Spago.Psa.Output
8-
( buildOutput
9-
, Output
8+
( Output
109
, OutputStats
1110
, annotatedError
12-
, trimPosition
11+
, buildOutput
12+
, initialStats
1313
, trimMessage
14+
, trimPosition
1415
) where
1516

1617
import Prelude

src/Spago/Psa/Printer.purs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- A majority of this code was copied from
22
-- - https://github.com/natefaubion/purescript-psa-utils
3-
--
3+
--
44
-- To fullfil license requirements
55
-- Copyright © Nathan Faubion
66
-- https://opensource.org/license/mit/
@@ -136,12 +136,15 @@ renderStats stats =
136136

137137
renderVerboseStats :: OutputStats -> D.Doc Ansi.GraphicsParam
138138
renderVerboseStats stats =
139-
renderStatCols
140-
{ col1: warningLabels <> errorLabels
141-
, col2: srcWarnings <> srcErrors
142-
, col3: libWarnings <> libErrors
143-
, col4: allWarnings <> allErrors
144-
}
139+
if Array.null warnings && Array.null errors then
140+
renderStats stats
141+
else
142+
renderStatCols
143+
{ col1: warningLabels <> errorLabels
144+
, col2: srcWarnings <> srcErrors
145+
, col3: libWarnings <> libErrors
146+
, col4: allWarnings <> allErrors
147+
}
145148
where
146149
warnings = Array.sort (FO.keys stats.allWarnings)
147150
errors = Array.sort (FO.keys stats.allErrors)

test/Spago/Unit.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ import Prelude
44

55
import Test.Spago.Unit.CheckInjectivity as CheckInjectivity
66
import Test.Spago.Unit.FindFlags as FindFlags
7+
import Test.Spago.Unit.Printer as Printer
78
import Test.Spec (Spec)
89
import Test.Spec as Spec
910

1011
spec :: Spec Unit
1112
spec = Spec.describe "unit" do
1213
FindFlags.spec
1314
CheckInjectivity.spec
15+
Printer.spec

test/Spago/Unit/Printer.purs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module Test.Spago.Unit.Printer where
2+
3+
import Prelude
4+
5+
import Data.String (joinWith)
6+
import Dodo as Dodo
7+
import Spago.Psa.Output (initialStats)
8+
import Spago.Psa.Printer (renderVerboseStats)
9+
import Test.Prelude (shouldEqual)
10+
import Test.Spec (Spec)
11+
import Test.Spec as Spec
12+
13+
spec :: Spec Unit
14+
spec = do
15+
Spec.describe "renderVerboseStats" do
16+
Spec.it "renders regular stats with all zeroes when there are no errors or warnings" do
17+
printDoc (renderVerboseStats initialStats) `shouldEqual`
18+
joinWith "\n"
19+
[ " Src Lib All"
20+
, "Warnings 0 0 0"
21+
, "Errors 0 0 0"
22+
]
23+
24+
where
25+
printDoc = Dodo.print Dodo.plainText Dodo.twoSpaces

0 commit comments

Comments
 (0)