Skip to content

Commit

Permalink
test: add test for bad purs exit
Browse files Browse the repository at this point in the history
  • Loading branch information
cakekindel committed Oct 31, 2024
1 parent 59b746d commit 7b47e88
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test-fixtures/purs-not-ok.txt
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions test/Spago/Build.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7b47e88

Please sign in to comment.