Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print compact stats instead of verbose when no errors or warnings #1254

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines -8 to +14
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got sorted alphabetically by the IDE support. The only real change is exporting initialStats to use it in the test.

) 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
Loading