-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always output all packages in build info (#1126)
- Loading branch information
1 parent
c49c161
commit e0013d6
Showing
4 changed files
with
163 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
module Test.Spago.Build.BuildInfo where | ||
|
||
import Test.Prelude | ||
|
||
import Control.Monad.Error.Class as MonadError | ||
import Data.Array as Array | ||
import Data.DateTime.Instant as Instant | ||
import Effect.Exception as Exception | ||
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 Spago.Log (LogVerbosity(..)) | ||
import Spago.Purs (getPurs) | ||
import Test.Spec (SpecT) | ||
import Test.Spec as Spec | ||
|
||
spec :: SpecT Aff TestDirs Identity Unit | ||
spec = | ||
Spec.describe "BuildInfo.purs" do | ||
|
||
let | ||
mkExpectedStdout { spago, rest } = do | ||
let logOptions = { logOptions: { color: false, verbosity: LogQuiet, startingTime: Instant.fromDateTime bottom } } | ||
purs <- runSpago logOptions getPurs | ||
spagoResult <- spago [ "--version" ] | ||
sVersion <- case spagoResult of | ||
Left e -> MonadError.throwError $ Exception.error e.message | ||
Right a -> pure a.stderr | ||
pure | ||
$ Array.intercalate "\n" | ||
$ | ||
[ "pursVersion: " <> Version.print purs.version | ||
, "spagoVersion: " <> sVersion | ||
] | ||
<> rest | ||
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 } -> do | ||
setupSinglePackage spago | ||
expected <- mkExpectedStdout { spago, rest: [ "foo: 0.0.0" ] } | ||
spago command >>= checkOutputsStr { stderrStr: Nothing, stdoutStr: Just expected, result: isRight } | ||
|
||
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 | ||
|
||
let packagesWithVersion = (\p -> p <> ": 0.0.0") <$> packages | ||
|
||
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 } -> do | ||
expected <- mkExpectedStdout { spago, rest: packagesWithVersion } | ||
spago [ "run", "-p", package, "--main", srcMain ] >>= checkOutputsStr { stderrStr: Nothing, stdoutStr: Just expected, result: isRight } | ||
|
||
Spec.it ("'spago test -p " <> package <> "' works") \{ spago } -> do | ||
expected <- mkExpectedStdout { spago, rest: packagesWithVersion } | ||
spago [ "test", "-p", package ] >>= checkOutputsStr { stderrStr: Nothing, stdoutStr: Just expected, result: isRight } | ||
|