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

Trimming the prefix_by message while censoring warning #1194

Merged
merged 1 commit into from
Mar 15, 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
2 changes: 1 addition & 1 deletion src/Spago/Psa.purs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ shouldPrintWarning = case _ of
let
tests = arr <#> case _ of
ByCode c -> \code _ -> c == code
ByMessagePrefix prefix -> \_ msg -> isJust $ String.stripPrefix (String.Pattern prefix) msg
ByMessagePrefix prefix -> \_ msg -> isJust $ String.stripPrefix (String.Pattern $ String.trim prefix) (String.trim msg)
-- We return `true` to print the warning.
-- If an element was found (i.e. `Just` is returned), then one of the tests succeeded,
-- so we should not print the warning and return false here.
Expand Down
14 changes: 14 additions & 0 deletions test-fixtures/build/censor-warnings/spago.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package:
name: foo
dependencies:
- console
- effect
- prelude
build:
censor_project_warnings:
- by_prefix: "Module Prelude"
- "UnusedName"

workspace:
package_set:
registry: 41.5.0
11 changes: 11 additions & 0 deletions test-fixtures/build/censor-warnings/src/Main.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Main where

import Prelude

import Effect
import Effect.Console (log)

main :: Effect Unit
main = do
let unused_var = 1
pure unit
6 changes: 6 additions & 0 deletions test/Prelude.purs
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,9 @@ escapePathInErrMsg :: Array String -> String
escapePathInErrMsg = case Process.platform of
Just Platform.Win32 -> Array.intercalate "\\"
_ -> Array.intercalate "/"

assertWarning :: forall m. MonadThrow Error m => Array String -> Boolean -> String -> m Unit
assertWarning paths shouldHave stdErr = do
when (not $ Array.all (\exp -> shouldHave == (String.contains (Pattern exp) stdErr)) paths) do
Assert.fail $ "STDERR contained one or more texts:\n" <> show paths <> "\n\nStderr was:\n" <> stdErr

19 changes: 19 additions & 0 deletions test/Spago/Build.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Test.Spago.Build where

import Test.Prelude

import Data.Foldable (fold)
import Node.FS.Aff as FSA
import Node.Path as Path
import Node.Platform as Platform
Expand Down Expand Up @@ -100,6 +101,23 @@ spec = Spec.around withTempDir do
, dst: spagoYaml
}
spago [ "build" ] >>= shouldBeFailure


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
}

Spec.describe "lockfile" do
Spec.it "building with a lockfile doesn't need the Registry repo" \{ spago, fixture } -> do
Expand All @@ -114,6 +132,7 @@ 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
10 changes: 3 additions & 7 deletions test/Spago/Build/Monorepo.purs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,8 @@ spec = Spec.describe "monorepo" do
, escapePathInErrMsg [ "package-b", "src", "Main.purs:6:13" ]
, escapePathInErrMsg [ "package-c", "src", "Main.purs:6:13" ]
]
shouldNotHaveWarning stdErr = do
when (Array.any (\exp -> String.contains (Pattern exp) stdErr) paths) do
Assert.fail $ "STDERR contained one or more texts:\n" <> show paths <> "\n\nStderr was:\n" <> stdErr
spago [ "build" ] >>= check { stdout: mempty, stderr: shouldNotHaveWarning, result: isRight }
shouldNotHaveWarning = assertWarning paths false
spago [ "build" ] >>= check { stdout: mempty, stderr: shouldNotHaveWarning , result: isRight }

Spec.it "build fails when 'strict: true' and warnings were not censored" \{ spago, fixture } -> do
FS.copyTree { src: fixture "monorepo/strict-true-uncensored-warnings", dst: "." }
Expand All @@ -141,9 +139,7 @@ spec = Spec.describe "monorepo" do
[ "[1/2 UnusedName] " <> escapePathInErrMsg [ "package-b", "src", "Main.purs:6:13" ]
, "[2/2 UnusedName] " <> escapePathInErrMsg [ "package-b", "test", "Main.purs:6:13" ]
]
hasUnusedWarningError stdErr = do
unless (Array.any (\exp -> String.contains (Pattern exp) stdErr) errs) do
Assert.fail $ "STDERR did not contain texts:\n" <> show errs <> "\n\nStderr was:\n" <> stdErr
hasUnusedWarningError = assertWarning errs true
spago [ "build" ] >>= check { stdout: mempty, stderr: hasUnusedWarningError, result: isLeft }

Spec.describe "passing --ensure-ranges flag..." do
Expand Down
Loading