Skip to content

Commit

Permalink
Print compact stats instead of verbose when no errors or warnings (#1254
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fsoikin authored Jul 25, 2024
1 parent 3c2b1ce commit 3ac61f5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Other improvements:
- Fix output truncation with `--json-errors`, many warnings and build failure (#1199)
- Update README with info about depending on a freshly added library
- Fixed globbing issue where `/.spago` behaves differently than `.spago` in `.gitignore`
- Fixed empty output for `--verbose-stats` when there are no errors or warnings.

## [0.21.0] - 2023-05-04

Expand Down
9 changes: 5 additions & 4 deletions src/Spago/Psa/Output.purs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
-- A majority of this code was copied from
-- - https://github.com/natefaubion/purescript-psa-utils
--
--
-- To fullfil license requirements
-- Copyright © Nathan Faubion
-- https://opensource.org/license/mit/
module Spago.Psa.Output
( buildOutput
, Output
( Output
, OutputStats
, annotatedError
, trimPosition
, buildOutput
, initialStats
, trimMessage
, trimPosition
) where

import Prelude
Expand Down
17 changes: 10 additions & 7 deletions src/Spago/Psa/Printer.purs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- A majority of this code was copied from
-- - https://github.com/natefaubion/purescript-psa-utils
--
--
-- To fullfil license requirements
-- Copyright © Nathan Faubion
-- https://opensource.org/license/mit/
Expand Down Expand Up @@ -136,12 +136,15 @@ renderStats stats =

renderVerboseStats :: OutputStats -> D.Doc Ansi.GraphicsParam
renderVerboseStats stats =
renderStatCols
{ col1: warningLabels <> errorLabels
, col2: srcWarnings <> srcErrors
, col3: libWarnings <> libErrors
, col4: allWarnings <> allErrors
}
if Array.null warnings && Array.null errors then
renderStats stats
else
renderStatCols
{ col1: warningLabels <> errorLabels
, col2: srcWarnings <> srcErrors
, col3: libWarnings <> libErrors
, col4: allWarnings <> allErrors
}
where
warnings = Array.sort (FO.keys stats.allWarnings)
errors = Array.sort (FO.keys stats.allErrors)
Expand Down
2 changes: 2 additions & 0 deletions test/Spago/Unit.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import Prelude

import Test.Spago.Unit.CheckInjectivity as CheckInjectivity
import Test.Spago.Unit.FindFlags as FindFlags
import Test.Spago.Unit.Printer as Printer
import Test.Spec (Spec)
import Test.Spec as Spec

spec :: Spec Unit
spec = Spec.describe "unit" do
FindFlags.spec
CheckInjectivity.spec
Printer.spec
25 changes: 25 additions & 0 deletions test/Spago/Unit/Printer.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Test.Spago.Unit.Printer where

import Prelude

import Data.String (joinWith)
import Dodo as Dodo
import Spago.Psa.Output (initialStats)
import Spago.Psa.Printer (renderVerboseStats)
import Test.Prelude (shouldEqual)
import Test.Spec (Spec)
import Test.Spec as Spec

spec :: Spec Unit
spec = do
Spec.describe "renderVerboseStats" do
Spec.it "renders regular stats with all zeroes when there are no errors or warnings" do
printDoc (renderVerboseStats initialStats) `shouldEqual`
joinWith "\n"
[ " Src Lib All"
, "Warnings 0 0 0"
, "Errors 0 0 0"
]

where
printDoc = Dodo.print Dodo.plainText Dodo.twoSpaces

0 comments on commit 3ac61f5

Please sign in to comment.