From 641641f5a6a192b044a99cf928476bd1e08a454f Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Mon, 16 Sep 2024 12:21:42 -0500 Subject: [PATCH 01/15] fix: bail if purs exits non-ok --- src/Spago/Cmd.purs | 8 ++++++++ src/Spago/Psa.purs | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Spago/Cmd.purs b/src/Spago/Cmd.purs index c7ce8a7be..b122bca75 100644 --- a/src/Spago/Cmd.purs +++ b/src/Spago/Cmd.purs @@ -39,6 +39,14 @@ type ExecResult = , timedOut :: Boolean } +exitedOk :: Either ExecResult ExecResult -> Boolean +exitedOk = either identity identity >>> case _ of + {exit: Normally 0} -> true + _ -> false + +exit :: Either ExecResult ExecResult -> Exit +exit = either identity identity >>> _.exit + printExecResult :: ExecResult -> String printExecResult r = Array.intercalate "\n" [ "escapedCommand: " <> show r.escapedCommand diff --git a/src/Spago/Psa.purs b/src/Spago/Psa.purs index 5ac0b5c18..db2810b5d 100644 --- a/src/Spago/Psa.purs +++ b/src/Spago/Psa.purs @@ -60,9 +60,12 @@ psaCompile globs pursArgs psaArgs = do pure $ FO.isEmpty out'.stats.allErrors - if Array.all identity arrErrorsIsEmpty then do + if Array.all identity arrErrorsIsEmpty && Cmd.exitedOk result then do logSuccess "Build succeeded." pure true + else if not $ Cmd.exitedOk result then do + prepareToDie [ "purs exited with non-ok status code: " <> show (Cmd.exit result) ] + pure false else do case result of Left r -> logDebug $ Cmd.printExecResult r From 2ce7e9f2e3a11bb49ac860517c1e1fd9bd37d91e Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Mon, 16 Sep 2024 13:10:25 -0500 Subject: [PATCH 02/15] oops :) --- src/Spago/Psa.purs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Spago/Psa.purs b/src/Spago/Psa.purs index db2810b5d..a6f8b5015 100644 --- a/src/Spago/Psa.purs +++ b/src/Spago/Psa.purs @@ -63,7 +63,7 @@ psaCompile globs pursArgs psaArgs = do if Array.all identity arrErrorsIsEmpty && Cmd.exitedOk result then do logSuccess "Build succeeded." pure true - else if not $ Cmd.exitedOk result then do + else if Array.all identity arrErrorsIsEmpty && not (Cmd.exitedOk result) then do prepareToDie [ "purs exited with non-ok status code: " <> show (Cmd.exit result) ] pure false else do From 51615fbbb5a64c8ec340bc72e999e1c13caf0685 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Tue, 17 Sep 2024 11:08:08 -0500 Subject: [PATCH 03/15] refactor --- src/Spago/Cmd.purs | 2 +- src/Spago/Psa.purs | 74 ++++++++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/Spago/Cmd.purs b/src/Spago/Cmd.purs index b122bca75..5359adfb0 100644 --- a/src/Spago/Cmd.purs +++ b/src/Spago/Cmd.purs @@ -41,7 +41,7 @@ type ExecResult = exitedOk :: Either ExecResult ExecResult -> Boolean exitedOk = either identity identity >>> case _ of - {exit: Normally 0} -> true + { exit: Normally 0 } -> true _ -> false exit :: Either ExecResult ExecResult -> Exit diff --git a/src/Spago/Psa.purs b/src/Spago/Psa.purs index a6f8b5015..e4059e301 100644 --- a/src/Spago/Psa.purs +++ b/src/Spago/Psa.purs @@ -10,9 +10,12 @@ import Spago.Prelude import Codec.JSON.DecodeError as CJ.DecodeError import Control.Alternative as Alternative +import Control.Monad.Except.Trans (ExceptT(..), runExceptT) +import Control.Monad.Trans.Class (lift) import Data.Array as Array import Data.Array.NonEmpty as NonEmptyArray import Data.Codec.JSON as CJ +import Data.Either (blush) import Data.Map as Map import Data.Set as Set import Data.String as Str @@ -21,6 +24,7 @@ import Data.Tuple as Tuple import Effect.Ref as Ref import Foreign.Object as FO import JSON as JSON +import Node.ChildProcess.Types (Exit(..)) import Node.Encoding as Encoding import Node.FS.Aff as FSA import Node.Path as Path @@ -38,40 +42,46 @@ import Spago.Purs as Purs defaultStatVerbosity :: Core.StatVerbosity defaultStatVerbosity = Core.CompactStats +-- Left decodeErrMsg -> do +-- logWarn $ Array.intercalate "\n" +-- [ "Failed to decode PsaResult at index '" <> show idx <> "': " <> decodeErrMsg +-- , "Json was: " <> err +-- ] +-- -- If we can't decode the error, then there's likely a codec issue on Spago's side. +-- -- So, this shouldn't fail the build. +-- pure true + psaCompile :: forall a. Set.Set FilePath -> Array String -> PsaArgs -> Spago (Purs.PursEnv a) Boolean psaCompile globs pursArgs psaArgs = do - result <- Purs.compile globs (Array.snoc pursArgs "--json-errors") - let resultStdout = Cmd.getStdout result - arrErrorsIsEmpty <- forWithIndex (Str.split (Str.Pattern "\n") resultStdout) \idx err -> - case JSON.parse err >>= CJ.decode psaResultCodec >>> lmap CJ.DecodeError.print of - Left decodeErrMsg -> do - logWarn $ Array.intercalate "\n" - [ "Failed to decode PsaResult at index '" <> show idx <> "': " <> decodeErrMsg - , "Json was: " <> err - ] - -- If we can't decode the error, then there's likely a codec issue on Spago's side. - -- So, this shouldn't fail the build. - pure true - Right out -> do - files <- liftEffect $ Ref.new FO.empty - out' <- buildOutput (loadLines files) psaArgs out - - liftEffect $ if psaArgs.jsonErrors then printJsonOutputToOut out' else printDefaultOutputToErr psaArgs out' - - pure $ FO.isEmpty out'.stats.allErrors - - if Array.all identity arrErrorsIsEmpty && Cmd.exitedOk result then do - logSuccess "Build succeeded." - pure true - else if Array.all identity arrErrorsIsEmpty && not (Cmd.exitedOk result) then do - prepareToDie [ "purs exited with non-ok status code: " <> show (Cmd.exit result) ] - pure false - else do - case result of - Left r -> logDebug $ Cmd.printExecResult r - _ -> pure unit - prepareToDie [ "Failed to build." ] - pure false + purs <- Purs.compile globs (Array.snoc pursArgs "--json-errors") + let + resultStdout = Cmd.getStdout purs + print' = if psaArgs.jsonErrors then printJsonOutputToOut else printDefaultOutputToErr psaArgs + + errors <- for (Str.split (Str.Pattern "\n") resultStdout) \err -> runExceptT do + out <- ExceptT $ pure $ JSON.parse err >>= CJ.decode psaResultCodec >>> lmap CJ.DecodeError.print + files <- liftEffect $ Ref.new FO.empty + out' <- lift $ buildOutput (loadLines files) psaArgs out + liftEffect (print' out') $> FO.isEmpty out'.stats.allErrors + + let + noErrors = Array.all (either (const true) identity) errors + failedToDecodeMsg (idx /\ err) = + Array.intercalate "\n" + [ "Failed to decode PsaResult at index '" <> show idx <> "': " <> err + , "Json was: " <> err + ] + failedToDecode = failedToDecodeMsg <$> Array.catMaybes (Array.mapWithIndex (\idx e -> (idx /\ _) <$> blush e) errors) + + case Cmd.exit purs, noErrors of + Normally 0, true -> for failedToDecode logWarn *> logSuccess "Build succeeded." $> true + _, true -> prepareToDie [ "purs exited with non-ok status code: " <> show (Cmd.exit purs) ] $> false + _, _ -> do + case purs of + Left r -> logDebug $ Cmd.printExecResult r + _ -> pure unit + prepareToDie [ "Failed to build." ] + pure false where isEmptySpan filename pos = From 87383a36e9ccf6586fd5fb2684b8ec6e5200ce58 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Tue, 17 Sep 2024 11:08:54 -0500 Subject: [PATCH 04/15] rm comment --- src/Spago/Psa.purs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Spago/Psa.purs b/src/Spago/Psa.purs index e4059e301..ee9c7ea2b 100644 --- a/src/Spago/Psa.purs +++ b/src/Spago/Psa.purs @@ -42,15 +42,6 @@ import Spago.Purs as Purs defaultStatVerbosity :: Core.StatVerbosity defaultStatVerbosity = Core.CompactStats --- Left decodeErrMsg -> do --- logWarn $ Array.intercalate "\n" --- [ "Failed to decode PsaResult at index '" <> show idx <> "': " <> decodeErrMsg --- , "Json was: " <> err --- ] --- -- If we can't decode the error, then there's likely a codec issue on Spago's side. --- -- So, this shouldn't fail the build. --- pure true - psaCompile :: forall a. Set.Set FilePath -> Array String -> PsaArgs -> Spago (Purs.PursEnv a) Boolean psaCompile globs pursArgs psaArgs = do purs <- Purs.compile globs (Array.snoc pursArgs "--json-errors") From 1ed35600380f7867e0154484f069c119fd7c1ed8 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Tue, 17 Sep 2024 11:09:24 -0500 Subject: [PATCH 05/15] re-add comment --- src/Spago/Psa.purs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Spago/Psa.purs b/src/Spago/Psa.purs index ee9c7ea2b..322581cf0 100644 --- a/src/Spago/Psa.purs +++ b/src/Spago/Psa.purs @@ -50,6 +50,8 @@ psaCompile globs pursArgs psaArgs = do print' = if psaArgs.jsonErrors then printJsonOutputToOut else printDefaultOutputToErr psaArgs errors <- for (Str.split (Str.Pattern "\n") resultStdout) \err -> runExceptT do + -- If we can't decode the error, then there's likely a codec issue on Spago's side. + -- So, this shouldn't fail the build. out <- ExceptT $ pure $ JSON.parse err >>= CJ.decode psaResultCodec >>> lmap CJ.DecodeError.print files <- liftEffect $ Ref.new FO.empty out' <- lift $ buildOutput (loadLines files) psaArgs out From 127d3e3d52b6075c29f023901c134859e01bf37b Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Tue, 17 Sep 2024 11:14:29 -0500 Subject: [PATCH 06/15] the last branch could be point-free as well --- src/Spago/Psa.purs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Spago/Psa.purs b/src/Spago/Psa.purs index 322581cf0..1a41bc259 100644 --- a/src/Spago/Psa.purs +++ b/src/Spago/Psa.purs @@ -67,14 +67,17 @@ psaCompile globs pursArgs psaArgs = do failedToDecode = failedToDecodeMsg <$> Array.catMaybes (Array.mapWithIndex (\idx e -> (idx /\ _) <$> blush e) errors) case Cmd.exit purs, noErrors of - Normally 0, true -> for failedToDecode logWarn *> logSuccess "Build succeeded." $> true - _, true -> prepareToDie [ "purs exited with non-ok status code: " <> show (Cmd.exit purs) ] $> false - _, _ -> do - case purs of - Left r -> logDebug $ Cmd.printExecResult r - _ -> pure unit - prepareToDie [ "Failed to build." ] - pure false + Normally 0, true -> + for failedToDecode logWarn + *> logSuccess "Build succeeded." + $> true + _, true -> + prepareToDie [ "purs exited with non-ok status code: " <> show (Cmd.exit purs) ] + $> false + _, _ -> + for (blush purs) (logDebug <<< Cmd.printExecResult) + *> prepareToDie [ "Failed to build." ] + $> false where isEmptySpan filename pos = From 59b746d5151aa8040cf8b986ef445d28a5867409 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Tue, 17 Sep 2024 11:34:05 -0500 Subject: [PATCH 07/15] format --- src/Spago/Psa.purs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Spago/Psa.purs b/src/Spago/Psa.purs index 1a41bc259..ef2b08b52 100644 --- a/src/Spago/Psa.purs +++ b/src/Spago/Psa.purs @@ -69,15 +69,15 @@ psaCompile globs pursArgs psaArgs = do case Cmd.exit purs, noErrors of Normally 0, true -> for failedToDecode logWarn - *> logSuccess "Build succeeded." - $> true + *> logSuccess "Build succeeded." + $> true _, true -> prepareToDie [ "purs exited with non-ok status code: " <> show (Cmd.exit purs) ] - $> false + $> false _, _ -> for (blush purs) (logDebug <<< Cmd.printExecResult) - *> prepareToDie [ "Failed to build." ] - $> false + *> prepareToDie [ "Failed to build." ] + $> false where isEmptySpan filename pos = From 7b47e885903158c18e49e29b2a230ce2a18f625d Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Thu, 31 Oct 2024 11:07:14 -0500 Subject: [PATCH 08/15] test: add test for bad purs exit --- test-fixtures/purs-not-ok.txt | 11 +++++++++++ test/Spago/Build.purs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 test-fixtures/purs-not-ok.txt diff --git a/test-fixtures/purs-not-ok.txt b/test-fixtures/purs-not-ok.txt new file mode 100644 index 000000000..2c9a14c19 --- /dev/null +++ b/test-fixtures/purs-not-ok.txt @@ -0,0 +1,11 @@ +Reading Spago workspace configuration... + +✓ Selecting package to build: aaa + +Downloading dependencies... +No lockfile found, generating it... +Lockfile written to spago.lock. Please commit this file. +Building... +IF YOURE SEEING THIS IT MEANS THAT THE TEST THAT OVERRIDES purs WAS NOT CLEANED UP PROPERLY!!1 + +✘ purs exited with non-ok status code: Normally 1 diff --git a/test/Spago/Build.purs b/test/Spago/Build.purs index fd47bb0ed..85f4c96a4 100644 --- a/test/Spago/Build.purs +++ b/test/Spago/Build.purs @@ -2,9 +2,11 @@ module Test.Spago.Build where import Test.Prelude +import Data.Array (intercalate) import Data.Foldable (fold) import Data.String as String import Node.FS.Aff as FSA +import Node.FS.Perms as FS.Perms import Node.Path as Path import Node.Platform as Platform import Node.Process as Process @@ -32,6 +34,38 @@ spec = Spec.around withTempDir do spago [ "init", "--name", "aaa", "--use-solver" ] >>= shouldBeSuccess spago [ "build" ] >>= shouldBeSuccess + Spec.after (rmRf <<< _.testCwd) + $ Spec.it "exits when purs exits non-ok" + $ \{ spago, testCwd, fixture } -> do + let + prependToPath a = testCwd <> ":" <> a + + -- NOTE: this is reset in `Spec.after` + -- by removing the tmp dir, rather than + -- storing and restoring the PATH variable + liftEffect + $ Process.lookupEnv "PATH" + <#> fromMaybe "" + <#> prependToPath + >>= Process.setEnv "PATH" + + spago [ "init", "--name", "aaa" ] >>= shouldBeSuccess + + let + pursShimPath = testCwd <> "/purs" + pursShim = + intercalate "\n" + [ "#!/bin/bash" + , "if [[ $1 = '--version' ]];" + , " then echo '0.15.15';" + , " else echo 'IF YOURE SEEING THIS IT MEANS THAT THE TEST THAT OVERRIDES purs WAS NOT CLEANED UP PROPERLY!!1' 1>&2; exit 1;" + , "fi;" + ] + + FS.writeTextFile pursShimPath pursShim + FS.chmod pursShimPath FS.Perms.permsAll + spago [ "build" ] >>= shouldBeFailureErr (fixture "purs-not-ok.txt") + Spec.it "passes options to purs" \{ spago } -> do spago [ "init" ] >>= shouldBeSuccess spago [ "build", "--purs-args", "--verbose-errors", "--purs-args", "--comments" ] >>= shouldBeSuccess From 4f16b32650e549b1cadbabdbd6487682ac44cb3d Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Fri, 1 Nov 2024 15:00:00 -0500 Subject: [PATCH 09/15] windows makes me sad :( --- test-fixtures/purs-not-ok.txt | 6 +++++- test/Spago/Build.purs | 32 ++------------------------------ 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/test-fixtures/purs-not-ok.txt b/test-fixtures/purs-not-ok.txt index 2c9a14c19..e274264e1 100644 --- a/test-fixtures/purs-not-ok.txt +++ b/test-fixtures/purs-not-ok.txt @@ -6,6 +6,10 @@ Downloading dependencies... No lockfile found, generating it... Lockfile written to spago.lock. Please commit this file. Building... -IF YOURE SEEING THIS IT MEANS THAT THE TEST THAT OVERRIDES purs WAS NOT CLEANED UP PROPERLY!!1 +Invalid option `--non-existent' + +Usage: purs COMMAND + + The PureScript compiler and tools ✘ purs exited with non-ok status code: Normally 1 diff --git a/test/Spago/Build.purs b/test/Spago/Build.purs index 85f4c96a4..3d90094e3 100644 --- a/test/Spago/Build.purs +++ b/test/Spago/Build.purs @@ -2,11 +2,9 @@ module Test.Spago.Build where import Test.Prelude -import Data.Array (intercalate) import Data.Foldable (fold) import Data.String as String import Node.FS.Aff as FSA -import Node.FS.Perms as FS.Perms import Node.Path as Path import Node.Platform as Platform import Node.Process as Process @@ -36,35 +34,9 @@ spec = Spec.around withTempDir do Spec.after (rmRf <<< _.testCwd) $ Spec.it "exits when purs exits non-ok" - $ \{ spago, testCwd, fixture } -> do - let - prependToPath a = testCwd <> ":" <> a - - -- NOTE: this is reset in `Spec.after` - -- by removing the tmp dir, rather than - -- storing and restoring the PATH variable - liftEffect - $ Process.lookupEnv "PATH" - <#> fromMaybe "" - <#> prependToPath - >>= Process.setEnv "PATH" - + $ \{ spago, fixture } -> do spago [ "init", "--name", "aaa" ] >>= shouldBeSuccess - - let - pursShimPath = testCwd <> "/purs" - pursShim = - intercalate "\n" - [ "#!/bin/bash" - , "if [[ $1 = '--version' ]];" - , " then echo '0.15.15';" - , " else echo 'IF YOURE SEEING THIS IT MEANS THAT THE TEST THAT OVERRIDES purs WAS NOT CLEANED UP PROPERLY!!1' 1>&2; exit 1;" - , "fi;" - ] - - FS.writeTextFile pursShimPath pursShim - FS.chmod pursShimPath FS.Perms.permsAll - spago [ "build" ] >>= shouldBeFailureErr (fixture "purs-not-ok.txt") + spago [ "build", "--purs-args", "--non-existent" ] >>= shouldBeFailureErr (fixture "purs-not-ok.txt") Spec.it "passes options to purs" \{ spago } -> do spago [ "init" ] >>= shouldBeSuccess From cbb29d2bf0971e0838f25d9c11764034a42d3b5c Mon Sep 17 00:00:00 2001 From: Fabrizio Ferrai Date: Sat, 2 Nov 2024 00:24:38 +0200 Subject: [PATCH 10/15] Update test/Spago/Build.purs --- test/Spago/Build.purs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/Spago/Build.purs b/test/Spago/Build.purs index 3d90094e3..a05ba41aa 100644 --- a/test/Spago/Build.purs +++ b/test/Spago/Build.purs @@ -32,11 +32,15 @@ spec = Spec.around withTempDir do spago [ "init", "--name", "aaa", "--use-solver" ] >>= shouldBeSuccess spago [ "build" ] >>= shouldBeSuccess - Spec.after (rmRf <<< _.testCwd) - $ Spec.it "exits when purs exits non-ok" - $ \{ spago, fixture } -> do - spago [ "init", "--name", "aaa" ] >>= shouldBeSuccess - spago [ "build", "--purs-args", "--non-existent" ] >>= shouldBeFailureErr (fixture "purs-not-ok.txt") + Spec.it "exits when purs exits non-ok" \{ spago, fixture } -> do + spago [ "init", "--name", "aaa" ] >>= shouldBeSuccess + spago [ "build", "--purs-args", "--non-existent" ] >>= + checkOutputs' + { stdoutFile: Nothing + , stderrFile: Just (fixture "purs-not-ok.txt") + , result: isLeft + , sanitize: String.trim >>> String.replace (String.Pattern "Usage: purs.bin") (String.Replacement "Usage: purs") + } Spec.it "passes options to purs" \{ spago } -> do spago [ "init" ] >>= shouldBeSuccess From bab00b5608d495d957373970a0e147375ad11b4a Mon Sep 17 00:00:00 2001 From: Fabrizio Ferrai Date: Sat, 2 Nov 2024 01:03:16 +0200 Subject: [PATCH 11/15] I love you windows --- test/Spago/Build.purs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/Spago/Build.purs b/test/Spago/Build.purs index a05ba41aa..bfbe4c258 100644 --- a/test/Spago/Build.purs +++ b/test/Spago/Build.purs @@ -39,7 +39,9 @@ spec = Spec.around withTempDir do { stdoutFile: Nothing , stderrFile: Just (fixture "purs-not-ok.txt") , result: isLeft - , sanitize: String.trim >>> String.replace (String.Pattern "Usage: purs.bin") (String.Replacement "Usage: purs") + , sanitize: String.trim + >>> String.replace (String.Pattern "Usage: purs.bin") (String.Replacement "Usage: purs") + >>> String.replace (String.Pattern "\r\n") (String.Replacement "\n") } Spec.it "passes options to purs" \{ spago } -> do From 9561f44072c95f99f44285d3c759313cccc1ceb7 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Sat, 2 Nov 2024 16:57:08 -0500 Subject: [PATCH 12/15] fix: test accounts for stderr being separated by crlf on windows. add contrarian newlines to the long list of problems bill gates is responsible for cursing us with on this godforsaken hellscape we call Earth. --- test-fixtures/purs-not-ok.win.txt | 15 +++++++++++++++ test/Spago/Build.purs | 18 +++++++++--------- 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 test-fixtures/purs-not-ok.win.txt diff --git a/test-fixtures/purs-not-ok.win.txt b/test-fixtures/purs-not-ok.win.txt new file mode 100644 index 000000000..505f15937 --- /dev/null +++ b/test-fixtures/purs-not-ok.win.txt @@ -0,0 +1,15 @@ +Reading Spago workspace configuration... + +✓ Selecting package to build: aaa + +Downloading dependencies... +No lockfile found, generating it... +Lockfile written to spago.lock. Please commit this file. +Building... +Invalid option `--non-existent' + +Usage: purs COMMAND + + The PureScript compiler and tools + +✘ purs exited with non-ok status code: Normally 1 diff --git a/test/Spago/Build.purs b/test/Spago/Build.purs index bfbe4c258..5d91b1986 100644 --- a/test/Spago/Build.purs +++ b/test/Spago/Build.purs @@ -2,8 +2,10 @@ module Test.Spago.Build where import Test.Prelude +import Control.Monad.Error.Class (liftMaybe) import Data.Foldable (fold) import Data.String as String +import Effect.Exception (error) import Node.FS.Aff as FSA import Node.Path as Path import Node.Platform as Platform @@ -34,15 +36,13 @@ spec = Spec.around withTempDir do Spec.it "exits when purs exits non-ok" \{ spago, fixture } -> do spago [ "init", "--name", "aaa" ] >>= shouldBeSuccess - spago [ "build", "--purs-args", "--non-existent" ] >>= - checkOutputs' - { stdoutFile: Nothing - , stderrFile: Just (fixture "purs-not-ok.txt") - , result: isLeft - , sanitize: String.trim - >>> String.replace (String.Pattern "Usage: purs.bin") (String.Replacement "Usage: purs") - >>> String.replace (String.Pattern "\r\n") (String.Replacement "\n") - } + fixture' <- + Process.platform + <#> case _ of + Platform.Win32 -> fixture "purs-not-ok.win.txt" + _ -> fixture "purs-not-ok.txt" + # liftMaybe (error "unreachable") + spago [ "build", "--purs-args", "--non-existent" ] >>= shouldBeFailureErr fixture' Spec.it "passes options to purs" \{ spago } -> do spago [ "init" ] >>= shouldBeSuccess From 7b5a704860b09897560a5eff774ec8408d1f0a48 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Mon, 4 Nov 2024 09:38:50 -0600 Subject: [PATCH 13/15] revert "fix: test accounts for stderr being separated by crlf on windows." This reverts commit 9561f44072c95f99f44285d3c759313cccc1ceb7. --- test-fixtures/purs-not-ok.win.txt | 15 --------------- test/Spago/Build.purs | 18 +++++++++--------- 2 files changed, 9 insertions(+), 24 deletions(-) delete mode 100644 test-fixtures/purs-not-ok.win.txt diff --git a/test-fixtures/purs-not-ok.win.txt b/test-fixtures/purs-not-ok.win.txt deleted file mode 100644 index 505f15937..000000000 --- a/test-fixtures/purs-not-ok.win.txt +++ /dev/null @@ -1,15 +0,0 @@ -Reading Spago workspace configuration... - -✓ Selecting package to build: aaa - -Downloading dependencies... -No lockfile found, generating it... -Lockfile written to spago.lock. Please commit this file. -Building... -Invalid option `--non-existent' - -Usage: purs COMMAND - - The PureScript compiler and tools - -✘ purs exited with non-ok status code: Normally 1 diff --git a/test/Spago/Build.purs b/test/Spago/Build.purs index 5d91b1986..bfbe4c258 100644 --- a/test/Spago/Build.purs +++ b/test/Spago/Build.purs @@ -2,10 +2,8 @@ module Test.Spago.Build where import Test.Prelude -import Control.Monad.Error.Class (liftMaybe) import Data.Foldable (fold) import Data.String as String -import Effect.Exception (error) import Node.FS.Aff as FSA import Node.Path as Path import Node.Platform as Platform @@ -36,13 +34,15 @@ spec = Spec.around withTempDir do Spec.it "exits when purs exits non-ok" \{ spago, fixture } -> do spago [ "init", "--name", "aaa" ] >>= shouldBeSuccess - fixture' <- - Process.platform - <#> case _ of - Platform.Win32 -> fixture "purs-not-ok.win.txt" - _ -> fixture "purs-not-ok.txt" - # liftMaybe (error "unreachable") - spago [ "build", "--purs-args", "--non-existent" ] >>= shouldBeFailureErr fixture' + spago [ "build", "--purs-args", "--non-existent" ] >>= + checkOutputs' + { stdoutFile: Nothing + , stderrFile: Just (fixture "purs-not-ok.txt") + , result: isLeft + , sanitize: String.trim + >>> String.replace (String.Pattern "Usage: purs.bin") (String.Replacement "Usage: purs") + >>> String.replace (String.Pattern "\r\n") (String.Replacement "\n") + } Spec.it "passes options to purs" \{ spago } -> do spago [ "init" ] >>= shouldBeSuccess From bf117b8b2e67c8f9998d95105a4e556521a23639 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Mon, 4 Nov 2024 10:23:08 -0600 Subject: [PATCH 14/15] fix: replaceAll, render non-printing when strings not equal --- test/Prelude.purs | 9 +++++++-- test/Spago/Build.purs | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/test/Prelude.purs b/test/Prelude.purs index 9477ac586..9ef083142 100644 --- a/test/Prelude.purs +++ b/test/Prelude.purs @@ -98,15 +98,20 @@ shouldEqualStr -> String -> m Unit shouldEqualStr v1 v2 = + let + renderNonPrinting = + String.replaceAll (String.Pattern "\r") (String.Replacement "␍") + >>> String.replaceAll (String.Pattern "\t") (String.Replacement "␉-->") + in when (v1 /= v2) do fail $ Array.intercalate "\n" [ "" , "===== (Actual)" - , v1 + , renderNonPrinting v1 , "=====" , " ≠" , "===== (Expected)" - , v2 + , renderNonPrinting v2 , "=====" , "" ] diff --git a/test/Spago/Build.purs b/test/Spago/Build.purs index bfbe4c258..9d91e68c0 100644 --- a/test/Spago/Build.purs +++ b/test/Spago/Build.purs @@ -39,9 +39,10 @@ spec = Spec.around withTempDir do { stdoutFile: Nothing , stderrFile: Just (fixture "purs-not-ok.txt") , result: isLeft - , sanitize: String.trim - >>> String.replace (String.Pattern "Usage: purs.bin") (String.Replacement "Usage: purs") - >>> String.replace (String.Pattern "\r\n") (String.Replacement "\n") + , sanitize: + String.trim + >>> String.replaceAll (String.Pattern "Usage: purs.bin") (String.Replacement "Usage: purs") + >>> String.replaceAll (String.Pattern "\r\n") (String.Replacement "\n") } Spec.it "passes options to purs" \{ spago } -> do From 3ac5d9076d1ae21f5673eeb7d5e862190fc6bb39 Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Mon, 4 Nov 2024 11:32:17 -0600 Subject: [PATCH 15/15] rerun macos job (apparently module build order can be nondeterministic?)