Skip to content
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
4 changes: 2 additions & 2 deletions src/Spago/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ build BuildOptions{..} maybePostBuild = do
ExitFailure n -> die [ "Backend " <> displayShow backend <> " exited with error:" <> repr n ]

buildAction globs = do
let action = buildBackend globs >> fromMaybe (pure ()) maybePostBuild
runCommands "Before" beforeCommands
onException ( buildBackend globs ) $ runCommands "Else" elseCommands
fromMaybe (pure ()) maybePostBuild
action `onException` (runCommands "Else" elseCommands)
runCommands "Then" thenCommands

case shouldWatch of
Expand Down
18 changes: 17 additions & 1 deletion test/SpagoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ spec = around_ setup $ do
test <- readTextFile dumpFile
test `shouldBe` "before\nthen\n"

it "Spago should run an else command if there is an error" $ do
it "Spago should run an else command if there is an error in the build" $ do

spago ["init"] >>= shouldBeSuccess

Expand All @@ -463,6 +463,22 @@ spec = around_ setup $ do
test <- readTextFile dumpFile
test `shouldBe` "else\n"


it "Spago should run an else command if there is an error in the run file" $ do

spago ["init"] >>= shouldBeSuccess
spago ["install", "exceptions"] >>= shouldBeSuccess

dir <- pwd
let dumpFile = dir </> "testOutput"
rm "src/Main.purs"
writeTextFile "src/Main.purs" "module Main where\nimport Effect.Exception\nmain = throw \"error\""
spago [ "run"
, "--else", "echo else>> " <> ( Text.pack $ encodeString dumpFile )
] >>= shouldBeFailure
test <- readTextFile dumpFile
test `shouldBe` "else\n"

it "Spago should run multiple commands in order" $ do

spago ["init"] >>= shouldBeSuccess
Expand Down