Skip to content

Commit

Permalink
Respect --censor-stats flag (#1241)
Browse files Browse the repository at this point in the history
  • Loading branch information
f-f authored Jul 2, 2024
1 parent b491a79 commit c3b33d3
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 34 deletions.
6 changes: 2 additions & 4 deletions bin/src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ mkBuildEnv buildArgs dependencies = do
newWorkspace = workspace
{ buildOptions
{ output = buildArgs.output <|> workspace.buildOptions.output
, statVerbosity = buildArgs.statVerbosity <|> workspace.buildOptions.statVerbosity
}
-- Override the backend args from the config if they are passed in through a flag
, backend = map
Expand All @@ -876,10 +877,7 @@ mkBuildEnv buildArgs dependencies = do
, git
, dependencies
, workspace: newWorkspace
, psaCliFlags:
{ statVerbosity: buildArgs.statVerbosity
, strict: buildArgs.strict
}
, strictWarnings: buildArgs.strict
, pedanticPackages: buildArgs.pedanticPackages
}

Expand Down
7 changes: 3 additions & 4 deletions src/Spago/Command/Build.purs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Spago.Config as Config
import Spago.Git (Git)
import Spago.Log (prepareToDie)
import Spago.Psa as Psa
import Spago.Psa.Types as PsaTypes
import Spago.Purs (Purs)
import Spago.Purs.Graph as Graph

Expand All @@ -32,7 +31,7 @@ type BuildEnv a =
, dependencies :: Fetch.PackageTransitiveDeps
, logOptions :: LogOptions
, workspace :: Workspace
, psaCliFlags :: PsaTypes.PsaOutputOptions
, strictWarnings :: Maybe Boolean
, pedanticPackages :: Boolean
| a
}
Expand All @@ -49,7 +48,7 @@ run opts = do
{ dependencies
, workspace
, logOptions
, psaCliFlags
, strictWarnings
, pedanticPackages
} <- ask

Expand Down Expand Up @@ -113,7 +112,7 @@ run opts = do
pathDecisions <- liftEffect $ sequence $ Psa.toPathDecisions
{ allDependencies
, selectedPackages: NEA.toArray selectedPackages
, psaCliFlags
, psaCliFlags: { strict: strictWarnings, statVerbosity: workspace.buildOptions.statVerbosity }
, censorLibWarnings: workspace.buildOptions.censorLibWarnings
}
let
Expand Down
6 changes: 1 addition & 5 deletions src/Spago/Command/Publish.purs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import Spago.Command.Build as Build
import Spago.Command.Fetch as Fetch
import Spago.Config (Package(..), Workspace, WorkspacePackage)
import Spago.Config as Config
import Spago.Config as Core
import Spago.Db (Db)
import Spago.Git (Git)
import Spago.Git as Git
Expand Down Expand Up @@ -382,10 +381,7 @@ publish _args = do
, dependencies: dependencies
, logOptions: env.logOptions
, workspace: env.workspace { selected = Just selected }
, psaCliFlags:
{ statVerbosity: (Nothing :: Maybe Core.StatVerbosity)
, strict: (Nothing :: Maybe Boolean)
}
, strictWarnings: (Nothing :: Maybe Boolean)
, pedanticPackages: false
}
action
Expand Down
10 changes: 5 additions & 5 deletions src/Spago/Config.purs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Spago.Config
( BuildOptions
, BuildType(..)
( BuildType(..)
, Package(..)
, PackageSet(..)
, PackageMap
, WithTestGlobs(..)
, Workspace
, WorkspaceBuildOptions
, WorkspacePackage
, addPackagesToConfig
, addRangesToConfig
Expand Down Expand Up @@ -72,13 +72,13 @@ type Workspace =
, packageSet :: PackageSet
, compatibleCompiler :: Range
, backend :: Maybe Core.BackendConfig
, buildOptions :: BuildOptions
, buildOptions :: WorkspaceBuildOptions
, doc :: YamlDoc Core.Config
, workspaceConfig :: Core.WorkspaceConfig
, rootPackage :: Maybe Core.PackageConfig
}

type BuildOptions =
type WorkspaceBuildOptions =
{ output :: Maybe FilePath
, censorLibWarnings :: Maybe Core.CensorBuildWarnings
, statVerbosity :: Maybe Core.StatVerbosity
Expand Down Expand Up @@ -414,7 +414,7 @@ readWorkspace { maybeSelectedPackage, pureBuild, migrateConfig } = do
]

let
buildOptions :: BuildOptions
buildOptions :: WorkspaceBuildOptions
buildOptions =
{ output: _.output =<< workspace.buildOpts
, censorLibWarnings: _.censorLibraryWarnings =<< workspace.buildOpts
Expand Down
9 changes: 9 additions & 0 deletions test-fixtures/censor-stats-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Reading Spago workspace configuration...

✅ Selecting package to build: aaa

Downloading dependencies...
Building...


✅ Build succeeded.
38 changes: 22 additions & 16 deletions test/Spago/Build.purs
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,30 @@ spec = Spec.around withTempDir do
, dst: spagoYaml
}
spago [ "build" ] >>= shouldBeFailure


Spec.it "should censor warnings with given errorcode and prefix messsage" \{spago, fixture} -> do
Spec.itOnly "respects the --censor-stats flag" \{ spago, fixture } -> do
spago [ "init", "--name", "aaa" ] >>= shouldBeSuccess
spago [ "build" ] >>= shouldBeSuccess
spago [ "build", "--censor-stats" ] >>= shouldBeSuccessErr (fixture "censor-stats-output.txt")

Spec.it "should censor warnings with given errorcode and prefix messsage" \{ spago, fixture } -> do
FS.copyTree { src: fixture "build/censor-warnings", dst: "." }

let remainingWarningPath = [ escapePathInErrMsg [ "src", "Main.purs:5:1" ] ]
filteredWarningPath = [ escapePathInErrMsg [ "src", "Main.purs:3:1" ]
, escapePathInErrMsg [ "src", "Main.purs:10:6" ]
]

shouldHaveWarning = assertWarning remainingWarningPath true
shouldNotHaveWarning = assertWarning filteredWarningPath false

spago [ "build" ] >>= check { stdout: mempty
, stderr: fold <<< flap [shouldHaveWarning, shouldNotHaveWarning]
, result: isRight
}

let
remainingWarningPath = [ escapePathInErrMsg [ "src", "Main.purs:5:1" ] ]
filteredWarningPath =
[ escapePathInErrMsg [ "src", "Main.purs:3:1" ]
, escapePathInErrMsg [ "src", "Main.purs:10:6" ]
]

shouldHaveWarning = assertWarning remainingWarningPath true
shouldNotHaveWarning = assertWarning filteredWarningPath false

spago [ "build" ] >>= check
{ stdout: mempty
, stderr: fold <<< flap [ shouldHaveWarning, shouldNotHaveWarning ]
, result: isRight
}

Spec.describe "lockfile" do
Spec.it "building with a lockfile doesn't need the Registry repo" \{ spago, fixture } -> do
Expand All @@ -132,7 +139,6 @@ spec = Spec.around withTempDir do
-- And that we still don't have the registry
FS.exists Paths.registryPath `Assert.shouldReturn` false


Spec.it "using the --pure flag does not refresh the lockfile" \{ spago, fixture } -> do
spago [ "init", "--name", "aaa", "--package-set", "33.0.0" ] >>= shouldBeSuccess
spago [ "build" ] >>= shouldBeSuccess
Expand Down

0 comments on commit c3b33d3

Please sign in to comment.