Skip to content

Commit

Permalink
Add a test for all content in build info
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMartinez committed Nov 30, 2023
1 parent eec8cc3 commit 575e73f
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test-fixtures/build-info/multi-package-stdout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pursVersion: 0.15.14
spagoVersion: 0.93.18
foo: 0.0.0
bar: 0.0.0
baz: 0.0.0
3 changes: 3 additions & 0 deletions test-fixtures/build-info/single-package-stdout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pursVersion: 0.15.14
spagoVersion: 0.93.18
foo: 0.0.0
3 changes: 3 additions & 0 deletions test/Spago/Build.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Spago.Core.Config as Config
import Spago.FS as FS
import Test.Spago.Build.Pedantic as Pedantic
import Test.Spago.Build.Polyrepo as BuildPolyrepo
import Test.Spago.Build.BuildInfo as BuildBuildInfo
import Test.Spec (Spec)
import Test.Spec as Spec
import Test.Spec.Assertions as Assert
Expand Down Expand Up @@ -140,6 +141,8 @@ spec = Spec.around withTempDir do

BuildPolyrepo.spec

BuildBuildInfo.spec

-- Spec.it "runs a --before command" \{ spago } -> do
-- spago [ "init" ] >>= shouldBeSuccess
-- let dumpFile = "testOutput"
Expand Down
118 changes: 118 additions & 0 deletions test/Spago/Build/BuildInfo.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
module Test.Spago.Build.BuildInfo where

import Test.Prelude

import Data.Array as Array
import Node.Path as Path
import Registry.Version as Version
import Spago.Command.Init (DefaultConfigOptions(..))
import Spago.Command.Init as Init
import Spago.Core.Config as Config
import Spago.FS as FS
import Test.Spec (SpecT)
import Test.Spec as Spec

spec :: SpecT Aff TestDirs Identity Unit
spec =
Spec.describe "BuildInfo.purs" do

let
pursModuleUsingBuildInfo packages =
[ "import Prelude"
, ""
, "import Spago.Generated.BuildInfo as BI"
, "import Effect.Console as Console"
, "import Effect (Effect)"
, ""
, "main :: Effect Unit"
, "main = do"
, " Console.log $ \"pursVersion: \" <> BI.buildInfo.pursVersion"
, " Console.log $ \"spagoVersion: \" <> BI.buildInfo.spagoVersion"
]
<> -- ensure all packages within the workspace are reference-able
( packages <#> \packageName ->
" Console.log $ \"" <> packageName <> ": \" <> BI.buildInfo.packages." <> packageName
)

Spec.describe "using generated 'BuildInfo.purs' file in single-package context" do

let
packageName = "foo"
srcAndTestContent = pursModuleUsingBuildInfo [ packageName ]

setupSinglePackage spago = do
spago [ "init", "--name", packageName ] >>= shouldBeSuccess
FS.writeTextFile (Path.concat [ "src", "Main.purs" ]) $ writeMain srcAndTestContent
FS.writeTextFile (Path.concat [ "test", "Test", "Main.purs" ]) $ writeTestMain srcAndTestContent

Spec.it ("'spago build' works") \{ spago } -> do
setupSinglePackage spago

spago [ "build" ] >>= shouldBeSuccess

Spec.it ("'spago build -p' works") \{ spago } -> do
setupSinglePackage spago

spago [ "build", "-p", packageName ] >>= shouldBeSuccess

let
runAndTestCommands = do
command <- [ "run", "test" ]
selected <- [ false, true ]
pure case selected of
false -> [ command ]
true -> [ command, "-p", packageName ]

for_ runAndTestCommands \command -> do
Spec.it ("'spago " <> Array.intercalate " " command <> " works") \{ spago, fixture } -> do
setupSinglePackage spago

spago command >>= shouldBeSuccessOutput (fixture "build-info/single-package-stdout.txt")

Spec.describe "using generated 'BuildInfo.purs' file in multi-package context" do

let
packages = [ "foo", "bar", "baz" ]
setupPolyrepo = do
FS.writeYamlFile Config.configCodec "spago.yaml"
$ Init.defaultConfig'
$ WorkspaceOnly { setVersion: Just $ unsafeFromRight $ Version.parse "0.0.1" }
for_ packages \packageName -> do
FS.mkdirp packageName
FS.writeYamlFile Config.configCodec (Path.concat [ packageName, "spago.yaml" ])
$ mkPackageOnlyConfig { packageName, srcDependencies: [ "prelude", "effect", "console" ] }
[ configAddTestMain ]
let
src = Path.concat [ packageName, "src" ]
test = Path.concat [ packageName, "test", "Test" ]
fileContent = pursModuleUsingBuildInfo packages

FS.mkdirp src
FS.mkdirp test
FS.writeTextFile (Path.concat [ src, "Main.purs" ]) $ writePursFile
{ moduleName: mkSrcModuleName packageName
, rest: fileContent
}
FS.writeTextFile (Path.concat [ test, "Main.purs" ]) $ writePursFile
{ moduleName: mkTestModuleName packageName
, rest: fileContent
}

Spec.it ("'spago build' works") \{ spago } -> do
setupPolyrepo
spago [ "build" ] >>= shouldBeSuccess

Spec.before_ setupPolyrepo do

for_ packages \package -> do
let
srcMain = mkSrcModuleName package
Spec.it ("'spago build -p " <> package <> "' works") \{ spago } -> do
spago [ "build", "-p", package ] >>= shouldBeSuccess

Spec.it ("'spago run -p " <> package <> " --main " <> srcMain <> "' works") \{ spago, fixture } -> do
spago [ "run", "-p", package, "--main", srcMain ] >>= shouldBeSuccessOutput (fixture "build-info/multi-package-stdout.txt")

Spec.it ("'spago test -p " <> package <> "' works") \{ spago, fixture } -> do
spago [ "test", "-p", package ] >>= shouldBeSuccessOutput (fixture "build-info/multi-package-stdout.txt")

0 comments on commit 575e73f

Please sign in to comment.