Skip to content

Commit

Permalink
When the slash is forward, every forest friend will notice
Browse files Browse the repository at this point in the history
  • Loading branch information
fsoikin committed Jan 20, 2025
1 parent fbab1c3 commit ebba9da
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions test/Spago/Config.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Test.Spago.Config where
import Test.Prelude

import Codec.JSON.DecodeError as CJ
import Data.String as String
import Registry.License as License
import Registry.Location (Location(..))
import Registry.PackageName as PackageName
Expand Down Expand Up @@ -72,24 +73,24 @@ spec =
Spec.it "discovers config up the directory tree" \{ testCwd, fixture, spago } -> do
FS.copyTree { src: fixture "config/discovery", dst: testCwd }
spago [ "build" ] >>= shouldBeSuccess
spago [ "build" ] >>= shouldBeSuccessErr (fixture "config/discovery/from-root.txt")
spago [ "build" ] >>= shouldBeSuccessErr' (fixture "config/discovery/from-root.txt")

-- Running from `./a`, Spago should discover the workspace root at
-- './' and select package 'a'
Paths.chdir $ testCwd </> "a"
spago [ "build" ] >>= shouldBeSuccessErr (fixture "config/discovery/from-a.txt")
spago [ "build" ] >>= shouldBeSuccessErr' (fixture "config/discovery/from-a.txt")

-- Running from `./nested-workspace`, Spago should use the workspace
-- root at './nested-workspace' and not the one at './'
Paths.chdir $ testCwd </> "nested-workspace"
spago [ "build" ] >>= shouldBeSuccess
spago [ "build" ] >>= shouldBeSuccessErr (fixture "config/discovery/from-nested.txt")
spago [ "build" ] >>= shouldBeSuccessErr' (fixture "config/discovery/from-nested.txt")

-- Running from `./nested-workspace/d`, Spago should use the workspace
-- root at './nested-workspace', because that's the closest one, and
-- select package 'd'
Paths.chdir $ testCwd </> "nested-workspace" </> "d"
spago [ "build" ] >>= shouldBeSuccessErr (fixture "config/discovery/from-d.txt")
spago [ "build" ] >>= shouldBeSuccessErr' (fixture "config/discovery/from-d.txt")

-- At workspace roots, a ".spago" directory should be created for
-- local cache, but not in subdirs
Expand All @@ -99,30 +100,43 @@ spec =
FS.exists (testCwd </> "nested-workspace" </> "d" </> ".spago") `Assert.shouldReturn` false

Spec.it "reports no config in any parent directories" \{ spago, fixture } ->
spago [ "build" ] >>= shouldBeFailureErr (fixture "config/no-workspace-anywhere.txt")
spago [ "build" ] >>= shouldBeFailureErr' (fixture "config/no-workspace-anywhere.txt")

Spec.it "reports possible misnamed configs up the directory tree" \{ testCwd, spago, fixture } -> do
FS.copyTree { src: fixture "config/misnamed-configs", dst: testCwd }
spago [ "build" ] >>= shouldBeFailureErr (fixture "config/misnamed-configs/from-root.txt")
spago [ "build" ] >>= shouldBeFailureErr' (fixture "config/misnamed-configs/from-root.txt")

Paths.chdir $ testCwd </> "a"
spago [ "build" ] >>= shouldBeFailureErr (fixture "config/misnamed-configs/from-a.txt")
spago [ "build" ] >>= shouldBeFailureErr' (fixture "config/misnamed-configs/from-a.txt")

Paths.chdir $ testCwd </> "a" </> "b"
spago [ "build" ] >>= shouldBeFailureErr (fixture "config/misnamed-configs/from-b.txt")
spago [ "build" ] >>= shouldBeFailureErr' (fixture "config/misnamed-configs/from-b.txt")

Paths.chdir $ testCwd </> "a" </> "b" </> "c"
spago [ "build" ] >>= shouldBeFailureErr (fixture "config/misnamed-configs/from-c.txt")
spago [ "build" ] >>= shouldBeFailureErr' (fixture "config/misnamed-configs/from-c.txt")

Paths.chdir $ testCwd </> "a" </> "b" </> "d"
spago [ "build" ] >>= shouldBeFailureErr (fixture "config/misnamed-configs/from-d.txt")
spago [ "build" ] >>= shouldBeFailureErr' (fixture "config/misnamed-configs/from-d.txt")

where
shouldFailWith result expectedError =
case result of
Right _ -> Assert.fail "Expected an error, but parsed successfully"
Left err -> CJ.print err `shouldEqual` expectedError

shouldBeSuccessErr' = shouldBeErr isRight
shouldBeFailureErr' = shouldBeErr isLeft

shouldBeErr result file = checkOutputs'
{ stdoutFile: Nothing
, stderrFile: Just file
, result
, sanitize:
String.trim
>>> String.replaceAll (String.Pattern "\\") (String.Replacement "/")
>>> String.replaceAll (String.Pattern "\r\n") (String.Replacement "\n")
}

validSpagoYaml :: { serialized :: String, parsed :: C.Config }
validSpagoYaml =
{ serialized:
Expand Down

0 comments on commit ebba9da

Please sign in to comment.