From f8cdd1c85c52b709a115be572d28772d615dd5bf Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Fri, 11 Mar 2022 18:23:04 +0000 Subject: [PATCH 01/82] Undo removal of run.js Removal of run.js interfered with cli programs. Generate run.mjs for projects >= 0.15 Relax es modules version constraint to 0.15.0-alpha-01 --- CHANGELOG.md | 3 +++ src/Spago/Build.hs | 24 +++++++++++++++--------- test/fixtures/spago-run-args.purs | 4 ++-- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c1ed7e3a..56f557b33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ Features: - Make `spago run` use es modules for projects >= v0.15 - Support Glibc versions >= `2.24` +Bugfixes +- Undo removing `run.js` as this does not work for cli programs. Generate `run.mjs` for projects >= 0.15 + ## [0.20.7] - 2022-02-12 Bugfixes diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 3bab378bf..3065011ec 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -323,11 +323,14 @@ runBackend runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybeSuccessMessage failureMessage extraArgs = do logDebug $ display $ "Running with backend: " <> fromMaybe "nodejs" maybeBackend BuildOptions{ pursArgs } <- view (the @BuildOptions) - isES <- Purs.hasMinPursVersion "0.15.0" + isES <- Purs.hasMinPursVersion "0.15.0-alpha-01" let postBuild = maybe (nodeAction isES $ Path.getOutputPath pursArgs) backendAction maybeBackend build (Just postBuild) where fromFilePath = Text.pack . Turtle.encodeString + runJsSource isES = + let file = if isES then "run.mjs" else "run.js" + in fromFilePath (sourceDir Turtle. ".spago" Turtle. file) nodeArgs = Text.intercalate " " $ map unBackendArg extraArgs esContents outputPath' = fold @@ -352,19 +355,22 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe , unModuleName moduleName , "').main()" ] - nodeCmd isES outputPath'= - if isES then - "node --input-type=module -e \"" <> esContents outputPath' <> "\" -- " <> nodeArgs - else - "node -e \"" <> cjsContents outputPath' <> "\" -- " <> nodeArgs + nodeContents isES outputPath' = + if isES then esContents outputPath' + else cjsContents outputPath' + + nodeCmd isES = "node " <> runJsSource isES <> " " <> nodeArgs nodeAction isES outputPath' = do + logDebug $ "Writing " <> displayShow @Text (runJsSource isES) + writeTextFile (runJsSource isES) (nodeContents isES outputPath') + void $ chmod executable $ pathFromText $ runJsSource isES -- cd to executeDir in case it isn't the same as sourceDir logDebug $ "Executing from: " <> displayShow @FilePath executeDir Turtle.cd executeDir -- We build a process by hand here because we need to forward the stdin to the backend process - logDebug $ "Running node command: `" <> display (nodeCmd isES outputPath') <> "`" - let processWithStdin = (Process.shell (Text.unpack $ nodeCmd isES outputPath')) { Process.std_in = Process.Inherit } + logDebug $ "Running node command: `" <> display (nodeCmd isES) <> "`" + let processWithStdin = (Process.shell (Text.unpack $ nodeCmd isES)) { Process.std_in = Process.Inherit } Turtle.system processWithStdin empty >>= \case ExitSuccess -> maybe (pure ()) (logInfo . display) maybeSuccessMessage ExitFailure n -> die [ display failureMessage <> "exit code: " <> repr n ] @@ -414,7 +420,7 @@ bundleModule -> UsePsa -> RIO env () bundleModule withMain BundleOptions { maybeModuleName, maybeTargetPath, maybePlatform, minify, noBuild } buildOpts usePsa = do - isES <- Purs.hasMinPursVersion "0.15.0" + isES <- Purs.hasMinPursVersion "0.15.0-alpha-01" let (moduleName, targetPath, platform) = prepareBundleDefaults maybeModuleName maybeTargetPath maybePlatform bundleAction = diff --git a/test/fixtures/spago-run-args.purs b/test/fixtures/spago-run-args.purs index aaa57155b..447a70bc6 100644 --- a/test/fixtures/spago-run-args.purs +++ b/test/fixtures/spago-run-args.purs @@ -10,5 +10,5 @@ import Data.Show (show) main :: Effect Unit main = do args <- argv - -- dropping the first arg, node path to make test stable - log $ show $ drop 1 args + -- dropping the first two args, node path and script name, to make test stable + log $ show $ drop 2 args From 9ef1f563c272d027275ad8f16a9a4e5df1004b8d Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Sat, 12 Mar 2022 11:33:01 +0000 Subject: [PATCH 02/82] Get node version and use experimental flag if necessary --- spago.cabal | 1 + src/Spago/Build.hs | 38 ++++++++++++++++++++++++++++++++------ src/Spago/Cmd.hs | 26 ++++++++++++++++++++++++++ src/Spago/Purs.hs | 17 ++--------------- 4 files changed, 61 insertions(+), 21 deletions(-) create mode 100644 src/Spago/Cmd.hs diff --git a/spago.cabal b/spago.cabal index 54cc29255..d3a73144e 100644 --- a/spago.cabal +++ b/spago.cabal @@ -87,6 +87,7 @@ library Spago.Bower Spago.Build Spago.CLI + Spago.Cmd Spago.Command.Init Spago.Command.Ls Spago.Command.Path diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 3065011ec..3df90ff38 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -17,6 +17,7 @@ import qualified Data.List.NonEmpty as NonEmpty import qualified Data.Map as Map import qualified Data.Set as Set import qualified Data.Text as Text +import qualified Data.Versions as Version import System.Directory (getCurrentDirectory) import System.FilePath (splitDirectories) import qualified System.FilePath.Glob as Glob @@ -36,6 +37,7 @@ import qualified Spago.Packages as Packages import qualified Spago.Purs as Purs import qualified Spago.Templates as Templates import qualified Spago.Watch as Watch +import qualified Spago.Cmd as Cmd prepareBundleDefaults @@ -309,6 +311,24 @@ script modulePath tag packageDeps opts = do data RunDirectories = RunDirectories { sourceDir :: FilePath, executeDir :: FilePath } +data NodeEsSupport = Unsupported Version.SemVer | Experimental | Supported + +hasNodeEsSupport :: (HasLogFunc env) => RIO env NodeEsSupport +hasNodeEsSupport = do + let + esVersions :: Either Version.ParsingError (Version.SemVer, Version.SemVer) + esVersions = bisequence (Version.semver "12.0.0", Version.semver "13.0.0") + nodeVersion <- Cmd.getCmdVersion "node" + case (nodeVersion, esVersions) of + (Left err, _) -> do + logDebug $ display $ "Unable to parse min version: " <> displayShow err + pure Supported + (Right nv, Right (expVersion, _)) | nv < expVersion -> + pure $ Unsupported nv + (Right nv, Right (expVersion, supVersion)) | nv >= expVersion && nv < supVersion -> pure Experimental + (Right _, _) -> pure Supported + + -- | Run the project with node (or the chosen alternate backend): -- compile and run the provided ModuleName runBackend @@ -324,8 +344,13 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe logDebug $ display $ "Running with backend: " <> fromMaybe "nodejs" maybeBackend BuildOptions{ pursArgs } <- view (the @BuildOptions) isES <- Purs.hasMinPursVersion "0.15.0-alpha-01" - let postBuild = maybe (nodeAction isES $ Path.getOutputPath pursArgs) backendAction maybeBackend - build (Just postBuild) + nodeEsSupport <- hasNodeEsSupport + case (isES, nodeEsSupport) of + (True, Unsupported nv) -> die [ "Unsupported node version: ", display $ Version.prettySemVer nv, "Required Node.js version >=12." ] + _ -> + let + postBuild = maybe (nodeAction isES nodeEsSupport $ Path.getOutputPath pursArgs) backendAction maybeBackend + in build (Just postBuild) where fromFilePath = Text.pack . Turtle.encodeString runJsSource isES = @@ -359,9 +384,10 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe if isES then esContents outputPath' else cjsContents outputPath' - nodeCmd isES = "node " <> runJsSource isES <> " " <> nodeArgs + nodeCmd isES Experimental | isES = "node --experimental-modules " <> runJsSource isES <> " " <> nodeArgs + nodeCmd isES _ = "node " <> runJsSource isES <> " " <> nodeArgs - nodeAction isES outputPath' = do + nodeAction isES nodeVersion outputPath' = do logDebug $ "Writing " <> displayShow @Text (runJsSource isES) writeTextFile (runJsSource isES) (nodeContents isES outputPath') void $ chmod executable $ pathFromText $ runJsSource isES @@ -369,8 +395,8 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe logDebug $ "Executing from: " <> displayShow @FilePath executeDir Turtle.cd executeDir -- We build a process by hand here because we need to forward the stdin to the backend process - logDebug $ "Running node command: `" <> display (nodeCmd isES) <> "`" - let processWithStdin = (Process.shell (Text.unpack $ nodeCmd isES)) { Process.std_in = Process.Inherit } + logDebug $ "Running node command: `" <> display (nodeCmd isES nodeVersion) <> "`" + let processWithStdin = (Process.shell (Text.unpack $ nodeCmd isES nodeVersion)) { Process.std_in = Process.Inherit } Turtle.system processWithStdin empty >>= \case ExitSuccess -> maybe (pure ()) (logInfo . display) maybeSuccessMessage ExitFailure n -> die [ display failureMessage <> "exit code: " <> repr n ] diff --git a/src/Spago/Cmd.hs b/src/Spago/Cmd.hs new file mode 100644 index 000000000..8ecc4e712 --- /dev/null +++ b/src/Spago/Cmd.hs @@ -0,0 +1,26 @@ +module Spago.Cmd (getCmdVersion) where + +import qualified Spago.Messages as Messages +import qualified Turtle.Bytes +import Spago.Prelude +import qualified Data.Text as Text +import qualified Data.Text.Encoding as Text.Encoding +import qualified Data.Text.Encoding.Error as Text.Encoding +import qualified Data.Versions as Version + +-- | Get the semantic version of a command, e.g. purs --version +getCmdVersion :: Text -> RIO env (Either Text Version.SemVer) +getCmdVersion cmd = + Turtle.Bytes.shellStrictWithErr (cmd <> " --version") empty >>= \case + (ExitSuccess, out, _err) -> do + let versionText = headMay $ Text.split (== ' ') (Text.strip $ Text.Encoding.decodeUtf8With lenientDecode out) + parsed = versionText >>= (\vt -> Text.stripPrefix "v" vt <|> Just vt) >>= (hush . Version.semver) + + pure $ case parsed of + Nothing -> + Left $ + Messages.failedToParseCommandOutput + (cmd <> " --version") + (Text.Encoding.decodeUtf8With Text.Encoding.lenientDecode out) + Just p -> Right p + (_, _out, _err) -> pure $ Left $ "Failed to run '" <> cmd <> " --version'" diff --git a/src/Spago/Purs.hs b/src/Spago/Purs.hs index 2dbe8a3b6..0d98ba9b5 100644 --- a/src/Spago/Purs.hs +++ b/src/Spago/Purs.hs @@ -19,12 +19,11 @@ import Spago.Env import qualified Data.ByteString.Lazy as BSL import qualified Data.Text as Text import qualified Data.Text.Encoding as Text.Encoding -import qualified Data.Text.Encoding.Error as Text.Encoding import qualified Data.Versions as Version import qualified Spago.Messages as Messages import qualified Turtle.Bytes - +import qualified Spago.Cmd as Cmd compile :: (HasPurs env, HasLogFunc env) @@ -130,19 +129,7 @@ docs format sourcePaths = do "Docs generation failed." pursVersion :: RIO env (Either Text Version.SemVer) -pursVersion = Turtle.Bytes.shellStrictWithErr (purs <> " --version") empty >>= \case - (ExitSuccess, out, _err) -> do - let versionText = headMay $ Text.split (== ' ') (Text.strip $ Text.Encoding.decodeUtf8With lenientDecode out) - parsed = versionText >>= (hush . Version.semver) - - pure $ case parsed of - Nothing -> Left $ Messages.failedToParseCommandOutput - (purs <> " --version") - (Text.Encoding.decodeUtf8With Text.Encoding.lenientDecode out) - Just p -> Right p - (_, _out, _err) -> pure $ Left $ "Failed to run '" <> purs <> " --version'" - where - purs = "purs" +pursVersion = Cmd.getCmdVersion "purs" hasMinPursVersion :: (HasLogFunc env, HasPurs env) => Text -> RIO env Bool hasMinPursVersion maybeMinVersion = do From 94dfb5b0f5400239b5511305645747033a123f50 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Sat, 12 Mar 2022 11:33:28 +0000 Subject: [PATCH 03/82] Remove bundle and src map test as the will fail on purs v0.15 --- test/SpagoSpec.hs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 43fe17418..037037e3f 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -747,14 +747,6 @@ spec = around_ setup $ do spago ["init"] >>= shouldBeSuccess spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess - checkFixture "bundle-app.js" - - it "Spago should bundle successfully with source map" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-app-src-map.js" - checkFileExist "bundle-app-src-map.js.map" describe "spago make-module" $ do From 4c6609e803a26343b70587cf13e303f854307d72 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Sat, 12 Mar 2022 11:41:09 +0000 Subject: [PATCH 04/82] Remove nl from error message --- src/Spago/Build.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 3df90ff38..64901213e 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -346,7 +346,7 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe isES <- Purs.hasMinPursVersion "0.15.0-alpha-01" nodeEsSupport <- hasNodeEsSupport case (isES, nodeEsSupport) of - (True, Unsupported nv) -> die [ "Unsupported node version: ", display $ Version.prettySemVer nv, "Required Node.js version >=12." ] + (True, Unsupported nv) -> die [ "Unsupported node version: " <> display (Version.prettySemVer nv), "Required Node.js version >=12." ] _ -> let postBuild = maybe (nodeAction isES nodeEsSupport $ Path.getOutputPath pursArgs) backendAction maybeBackend From 7c84eebfb8c95521ee0cb1d407b99ca4a8569bbe Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Sun, 13 Mar 2022 19:06:55 +0000 Subject: [PATCH 05/82] Add package.json creation instead of run.mjs --- src/Spago/Build.hs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 64901213e..efa6d5784 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -323,11 +323,11 @@ hasNodeEsSupport = do (Left err, _) -> do logDebug $ display $ "Unable to parse min version: " <> displayShow err pure Supported - (Right nv, Right (expVersion, _)) | nv < expVersion -> + (Right nv, Right (expVersion, _)) | nv < expVersion -> pure $ Unsupported nv (Right nv, Right (expVersion, supVersion)) | nv >= expVersion && nv < supVersion -> pure Experimental (Right _, _) -> pure Supported - + -- | Run the project with node (or the chosen alternate backend): -- compile and run the provided ModuleName @@ -347,15 +347,14 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe nodeEsSupport <- hasNodeEsSupport case (isES, nodeEsSupport) of (True, Unsupported nv) -> die [ "Unsupported node version: " <> display (Version.prettySemVer nv), "Required Node.js version >=12." ] - _ -> - let + _ -> + let postBuild = maybe (nodeAction isES nodeEsSupport $ Path.getOutputPath pursArgs) backendAction maybeBackend in build (Just postBuild) where fromFilePath = Text.pack . Turtle.encodeString - runJsSource isES = - let file = if isES then "run.mjs" else "run.js" - in fromFilePath (sourceDir Turtle. ".spago" Turtle. file) + runJsSource = fromFilePath (sourceDir Turtle. ".spago/run.js") + packageJson = fromFilePath (sourceDir Turtle. ".spago/package.json") nodeArgs = Text.intercalate " " $ map unBackendArg extraArgs esContents outputPath' = fold @@ -384,13 +383,19 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe if isES then esContents outputPath' else cjsContents outputPath' - nodeCmd isES Experimental | isES = "node --experimental-modules " <> runJsSource isES <> " " <> nodeArgs - nodeCmd isES _ = "node " <> runJsSource isES <> " " <> nodeArgs + packageJsonContents = "{\"type\":\"module\" }" + + nodeCmd isES Experimental | isES = "node --experimental-modules " <> runJsSource <> " " <> nodeArgs + nodeCmd _ _ = "node " <> runJsSource <> " " <> nodeArgs nodeAction isES nodeVersion outputPath' = do - logDebug $ "Writing " <> displayShow @Text (runJsSource isES) - writeTextFile (runJsSource isES) (nodeContents isES outputPath') - void $ chmod executable $ pathFromText $ runJsSource isES + logDebug $ "Writing " <> displayShow @Text runJsSource + writeTextFile runJsSource (nodeContents isES outputPath') + void $ chmod executable $ pathFromText runJsSource + if isES then do + logDebug $ "Writing " <> displayShow @Text packageJson + writeTextFile packageJson packageJsonContents + else pure () -- cd to executeDir in case it isn't the same as sourceDir logDebug $ "Executing from: " <> displayShow @FilePath executeDir Turtle.cd executeDir From 4daa5b255e42be3d676c1acb6ac6b026ac10c0ab Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Sun, 20 Mar 2022 12:14:19 +0000 Subject: [PATCH 06/82] Fix format flag for node --- src/Spago/Build.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index efa6d5784..fd28f5415 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -418,18 +418,18 @@ bundleWithEsbuild withMain (ModuleName moduleName) (TargetPath targetPath) platf esbuild <- getESBuild let platformOpt = case platform of - Browser -> "browser" - Node -> "node" + Browser -> " --platform=browser" + Node -> " --platform=node --format=esm" minifyOpt = case minify of NoMinify -> "" Minify -> " --minify" cmd = case withMain of WithMain -> "echo \"import { main } from './output/" <> moduleName <> "/index.js'\nmain()\" | " - <> esbuild <> " --platform=" <> platformOpt <> minifyOpt <> " --bundle " + <> esbuild <> platformOpt <> minifyOpt <> " --bundle " <> " --outfile=" <> targetPath WithoutMain -> - esbuild <> " --platform=" <> platformOpt <> minifyOpt <> " --bundle " + esbuild <> platformOpt <> minifyOpt <> " --bundle " <> "output/" <> moduleName <> "/index.js" <> " --outfile=" <> targetPath runWithOutput cmd From 580c52a8a964493254f31ba8f1815297e319670a Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Sun, 20 Mar 2022 12:24:20 +0000 Subject: [PATCH 07/82] Fix sourcemap flag for esbuild --- src/Spago/Build.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index fd28f5415..72fbd0931 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -413,8 +413,8 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe ExitFailure n -> die [ display failureMessage <> "Backend " <> displayShow backend <> " exited with error:" <> repr n ] -bundleWithEsbuild :: HasLogFunc env => WithMain -> ModuleName -> TargetPath -> Platform -> Minify -> RIO env () -bundleWithEsbuild withMain (ModuleName moduleName) (TargetPath targetPath) platform minify = do +bundleWithEsbuild :: HasLogFunc env => WithMain -> WithSrcMap -> ModuleName -> TargetPath -> Platform -> Minify -> RIO env () +bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath) platform minify = do esbuild <- getESBuild let platformOpt = case platform of @@ -423,13 +423,16 @@ bundleWithEsbuild withMain (ModuleName moduleName) (TargetPath targetPath) platf minifyOpt = case minify of NoMinify -> "" Minify -> " --minify" + srcMapOpt = case srcMap of + WithSrcMap -> " --sourcemap" + WithoutSrcMap -> "" cmd = case withMain of WithMain -> "echo \"import { main } from './output/" <> moduleName <> "/index.js'\nmain()\" | " - <> esbuild <> platformOpt <> minifyOpt <> " --bundle " + <> esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --bundle " <> " --outfile=" <> targetPath WithoutMain -> - esbuild <> platformOpt <> minifyOpt <> " --bundle " + esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --bundle " <> "output/" <> moduleName <> "/index.js" <> " --outfile=" <> targetPath runWithOutput cmd @@ -456,7 +459,7 @@ bundleModule withMain BundleOptions { maybeModuleName, maybeTargetPath, maybePla (moduleName, targetPath, platform) = prepareBundleDefaults maybeModuleName maybeTargetPath maybePlatform bundleAction = if isES then - bundleWithEsbuild withMain moduleName targetPath platform minify + bundleWithEsbuild withMain (withSourceMap buildOpts) moduleName targetPath platform minify else case withMain of WithMain -> Purs.bundle WithMain (withSourceMap buildOpts) moduleName targetPath WithoutMain -> From 1b1d7a097e4a7ed1860e55b90e6460bd5dfbee6f Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Sun, 20 Mar 2022 12:32:15 +0000 Subject: [PATCH 08/82] Fix space in folder bug --- src/Spago/Build.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 72fbd0931..8b35c1dea 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -385,8 +385,8 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe packageJsonContents = "{\"type\":\"module\" }" - nodeCmd isES Experimental | isES = "node --experimental-modules " <> runJsSource <> " " <> nodeArgs - nodeCmd _ _ = "node " <> runJsSource <> " " <> nodeArgs + nodeCmd isES Experimental | isES = "node --experimental-modules \"" <> runJsSource <> "\" " <> nodeArgs + nodeCmd _ _ = "node \"" <> runJsSource <> "\" " <> nodeArgs nodeAction isES nodeVersion outputPath' = do logDebug $ "Writing " <> displayShow @Text runJsSource From afa1bae00e9c20ed0a64246105764fdb2cc4a6b1 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Sun, 20 Mar 2022 12:38:30 +0000 Subject: [PATCH 09/82] Readd bundle test --- test/SpagoSpec.hs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 037037e3f..43fe17418 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -747,6 +747,14 @@ spec = around_ setup $ do spago ["init"] >>= shouldBeSuccess spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess + checkFixture "bundle-app.js" + + it "Spago should bundle successfully with source map" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-app-src-map.js" + checkFileExist "bundle-app-src-map.js.map" describe "spago make-module" $ do From 9f79ff9e2f9d2a207157a7f36bb9862315b772d4 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Mon, 21 Mar 2022 16:37:29 +0000 Subject: [PATCH 10/82] Update changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56f557b33..9f7707342 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,10 @@ Features: - Support Glibc versions >= `2.24` Bugfixes -- Undo removing `run.js` as this does not work for cli programs. Generate `run.mjs` for projects >= 0.15 +- Undo removing `run.js` as this does not work for cli programs. +- Make spago escape filepaths so that spaces in paths are allowed +- Fix adding experimental flag for node version 12 +- Remove support for node versions < 12 because they do not work with es modules ## [0.20.7] - 2022-02-12 From cff884252cf35912be886eeca92fb790ccc98e78 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Mon, 21 Mar 2022 16:38:05 +0000 Subject: [PATCH 11/82] Fix pr comments --- src/Spago/Build.hs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 8b35c1dea..6b3a523b0 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -315,18 +315,16 @@ data NodeEsSupport = Unsupported Version.SemVer | Experimental | Supported hasNodeEsSupport :: (HasLogFunc env) => RIO env NodeEsSupport hasNodeEsSupport = do - let - esVersions :: Either Version.ParsingError (Version.SemVer, Version.SemVer) - esVersions = bisequence (Version.semver "12.0.0", Version.semver "13.0.0") nodeVersion <- Cmd.getCmdVersion "node" - case (nodeVersion, esVersions) of - (Left err, _) -> do - logDebug $ display $ "Unable to parse min version: " <> displayShow err + case nodeVersion of + Left err -> do + logDebug $ display $ "Unable to get Node.js version: " <> displayShow err pure Supported - (Right nv, Right (expVersion, _)) | nv < expVersion -> + Right nv@Version.SemVer{} | Version._svMajor nv < 12 -> pure $ Unsupported nv - (Right nv, Right (expVersion, supVersion)) | nv >= expVersion && nv < supVersion -> pure Experimental - (Right _, _) -> pure Supported + Right nv@Version.SemVer{} | Version._svMajor nv >= 12 && Version._svMajor nv < 13 -> + pure Experimental + _ -> pure Supported -- | Run the project with node (or the chosen alternate backend): @@ -346,7 +344,7 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe isES <- Purs.hasMinPursVersion "0.15.0-alpha-01" nodeEsSupport <- hasNodeEsSupport case (isES, nodeEsSupport) of - (True, Unsupported nv) -> die [ "Unsupported node version: " <> display (Version.prettySemVer nv), "Required Node.js version >=12." ] + (True, Unsupported nv) -> die [ "Unsupported Node.js version: " <> display (Version.prettySemVer nv), "Required Node.js version >=12." ] _ -> let postBuild = maybe (nodeAction isES nodeEsSupport $ Path.getOutputPath pursArgs) backendAction maybeBackend From 137fe6c41632acc85b384a2d6ab94616fbdbf8a5 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Wed, 23 Mar 2022 10:21:36 +0000 Subject: [PATCH 12/82] Update CHANGELOG.md Co-authored-by: Fabrizio Ferrai --- CHANGELOG.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f7707342..8805dccbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,10 +13,8 @@ Features: - Support Glibc versions >= `2.24` Bugfixes -- Undo removing `run.js` as this does not work for cli programs. -- Make spago escape filepaths so that spaces in paths are allowed -- Fix adding experimental flag for node version 12 -- Remove support for node versions < 12 because they do not work with es modules +- Fix `spago run` and `spago test` to accept command line arguments correctly, by writing a JS file to run (#865, #866) +- Remove support for node versions older than 12.0.0 as they do not work with es modules (#866) ## [0.20.7] - 2022-02-12 From a990a4de7f519b9aa89300bd714377ffb678976a Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Thu, 24 Mar 2022 21:01:32 +0000 Subject: [PATCH 13/82] Fix esm format flag --- src/Spago/Build.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 6b3a523b0..23b117a36 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -417,7 +417,7 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath let platformOpt = case platform of Browser -> " --platform=browser" - Node -> " --platform=node --format=esm" + Node -> " --platform=node" minifyOpt = case minify of NoMinify -> "" Minify -> " --minify" @@ -430,7 +430,7 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath <> esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --bundle " <> " --outfile=" <> targetPath WithoutMain -> - esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --bundle " + esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --format=esm --bundle " <> "output/" <> moduleName <> "/index.js" <> " --outfile=" <> targetPath runWithOutput cmd From 25186fd5b0ea5a5930af1dbfb6e72e69c74acce1 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Thu, 24 Mar 2022 21:02:39 +0000 Subject: [PATCH 14/82] Add tests for space in folder and bundling on v0.15 --- src/Spago/Cmd.hs | 2 +- test/SpagoSpec.hs | 58 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/Spago/Cmd.hs b/src/Spago/Cmd.hs index 8ecc4e712..620508a18 100644 --- a/src/Spago/Cmd.hs +++ b/src/Spago/Cmd.hs @@ -9,7 +9,7 @@ import qualified Data.Text.Encoding.Error as Text.Encoding import qualified Data.Versions as Version -- | Get the semantic version of a command, e.g. purs --version -getCmdVersion :: Text -> RIO env (Either Text Version.SemVer) +getCmdVersion :: forall io. MonadIO io => Text -> io (Either Text Version.SemVer) getCmdVersion cmd = Turtle.Bytes.shellStrictWithErr (cmd <> " --version") empty >>= \case (ExitSuccess, out, _err) -> do diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 43fe17418..49040322b 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -8,17 +8,19 @@ import Test.Hspec (Spec, around_, describe, it, shouldBe, shou shouldNotBe, shouldReturn, shouldSatisfy) import Turtle (ExitCode (..), cd, cp, decodeString, empty, encodeString, mkdir, mktree, mv, pwd, readTextFile, rm, shell, - shellStrictWithErr, testdir, writeTextFile, ()) + shellStrictWithErr, testdir, writeTextFile, (), die) import Utils (checkFileHasInfix, checkFixture, checkFileExist, outputShouldEqual, readFixture, runFor, shouldBeFailure, shouldBeFailureInfix, shouldBeFailureStderr, shouldBeSuccess, shouldBeSuccessOutput, shouldBeSuccessOutputWithErr, shouldBeSuccessStderr, spago, withCwd, withEnvVar) +import qualified Data.Versions as Version +import qualified Spago.Cmd as Cmd setup :: IO () -> IO () setup cmd = do - Temp.withTempDirectory "test/" "spago-test" $ \temp -> do + Temp.withTempDirectory "test/" "spago test" $ \temp -> do -- print ("Running in " <> temp) withCwd (decodeString temp) cmd @@ -168,7 +170,7 @@ spec = around_ setup $ do spago ["init"] >>= shouldBeSuccess mv "packages.dhall" "packagesBase.dhall" - writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { metadata_ = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/purescript-metadata.git\", version = \"spago-test/branch-with-slash\" }}" + writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { metadata_ = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/purescript-metadata.git\", version = \"spago test/branch-with-slash\" }}" spago ["install", "metadata_"] >>= shouldBeSuccess it "Spago should be able to install a package not in the set from a commit hash" $ do @@ -740,21 +742,36 @@ spec = around_ setup $ do spago ["bundle", "--to", "bundle.js"] >>= shouldBeFailureStderr "bundle-stderr.txt" + let + getPursVersion = Cmd.getCmdVersion "purs" >>= either die pure + esmVersion = either (const $ die "Failed to parse purs version") pure $ Version.semver "0.15.0-alpha-02" describe "spago bundle-app" $ do - it "Spago should bundle successfully" $ do + pursVersion :: Version.SemVer <- getPursVersion + purs0_15_0 :: Version.SemVer <- esmVersion spago ["init"] >>= shouldBeSuccess - spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess - checkFixture "bundle-app.js" + if pursVersion >= purs0_15_0 then do + spago ["bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess + checkFixture "bundle-app-esm.js" + else do + spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess + checkFixture "bundle-app.js" it "Spago should bundle successfully with source map" $ do + pursVersion :: Version.SemVer <- getPursVersion + purs0_15_0 :: Version.SemVer <- esmVersion spago ["init"] >>= shouldBeSuccess - spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-app-src-map.js" - checkFileExist "bundle-app-src-map.js.map" + if pursVersion >= purs0_15_0 then do + spago ["bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-app-src-map-esm.js" + checkFileExist "bundle-app-src-map-esm.js.map" + else do + spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-app-src-map.js" + checkFileExist "bundle-app-src-map.js.map" describe "spago make-module" $ do @@ -766,23 +783,36 @@ spec = around_ setup $ do describe "spago bundle-module" $ do it "Spago should successfully make a module" $ do + pursVersion :: Version.SemVer <- getPursVersion + purs0_15_0 :: Version.SemVer <- esmVersion spago ["init"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess -- Now we don't remove the output folder, but we pass the `--no-build` -- flag to skip rebuilding (i.e. we are counting on the previous command -- to have built stuff for us) - spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess - checkFixture "bundle-module.js" + if pursVersion >= purs0_15_0 then do + spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess + checkFixture "bundle-module-esm.js" + else do + spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess + checkFixture "bundle-module.js" it "Spago should successfully make a module with source map" $ do + pursVersion :: Version.SemVer <- getPursVersion + purs0_15_0 :: Version.SemVer <- esmVersion spago ["init"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess - spago ["bundle-module", "--to", "bundle-module-src-map.js", "--no-build", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-module-src-map.js" - checkFileExist "bundle-module-src-map.js.map" + if pursVersion >= purs0_15_0 then do + spago ["bundle-module", "--to", "bundle-module-src-map-esm.js", "--no-build", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-module-src-map-esm.js" + checkFileExist "bundle-module-src-map-esm.js.map" + else do + spago ["bundle-module", "--to", "bundle-module-src-map.js", "--no-build", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-module-src-map.js" + checkFileExist "bundle-module-src-map.js.map" describe "spago ls packages" $ do From c2632aaab43f4fbd336c7a4e2083ab04047f0470 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Thu, 24 Mar 2022 21:26:59 +0000 Subject: [PATCH 15/82] Undo rename test directory with space --- test/SpagoSpec.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 49040322b..5c56245a6 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -20,7 +20,7 @@ import qualified Spago.Cmd as Cmd setup :: IO () -> IO () setup cmd = do - Temp.withTempDirectory "test/" "spago test" $ \temp -> do + Temp.withTempDirectory "test/" "spago-test" $ \temp -> do -- print ("Running in " <> temp) withCwd (decodeString temp) cmd @@ -170,7 +170,7 @@ spec = around_ setup $ do spago ["init"] >>= shouldBeSuccess mv "packages.dhall" "packagesBase.dhall" - writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { metadata_ = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/purescript-metadata.git\", version = \"spago test/branch-with-slash\" }}" + writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { metadata_ = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/purescript-metadata.git\", version = \"spago-test/branch-with-slash\" }}" spago ["install", "metadata_"] >>= shouldBeSuccess it "Spago should be able to install a package not in the set from a commit hash" $ do From 8699359ef8b6b27f86ba06ec8537c709bab4ffc9 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Thu, 24 Mar 2022 22:05:03 +0000 Subject: [PATCH 16/82] Fix bundle-module test --- test/SpagoSpec.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 5c56245a6..34d7dc671 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -792,7 +792,7 @@ spec = around_ setup $ do -- flag to skip rebuilding (i.e. we are counting on the previous command -- to have built stuff for us) if pursVersion >= purs0_15_0 then do - spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess + spago ["bundle-module", "--to", "bundle-module-esm.js", "--no-build"] >>= shouldBeSuccess checkFixture "bundle-module-esm.js" else do spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess From 1b31e3d86deff7d91e711cec5890123f1194a403 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Mon, 28 Mar 2022 07:53:59 +0100 Subject: [PATCH 17/82] Fix space test and add missing fixtures --- test/SpagoSpec.hs | 22 +++++++++++----------- test/Utils.hs | 10 +++++++++- test/fixtures/bundle-app-esm.js | 14 ++++++++++++++ test/fixtures/bundle-app-src-map-esm.js | 15 +++++++++++++++ test/fixtures/bundle-module-esm.js | 12 ++++++++++++ test/fixtures/bundle-module-src-map-esm.js | 13 +++++++++++++ 6 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 test/fixtures/bundle-app-esm.js create mode 100644 test/fixtures/bundle-app-src-map-esm.js create mode 100644 test/fixtures/bundle-module-esm.js create mode 100644 test/fixtures/bundle-module-src-map-esm.js diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 34d7dc671..ac94e51ef 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -13,14 +13,14 @@ import Utils (checkFileHasInfix, checkFixture, checkFileE readFixture, runFor, shouldBeFailure, shouldBeFailureInfix, shouldBeFailureStderr, shouldBeSuccess, shouldBeSuccessOutput, shouldBeSuccessOutputWithErr, shouldBeSuccessStderr, spago, - withCwd, withEnvVar) + withCwd, withEnvVar, escapeFilePath) import qualified Data.Versions as Version import qualified Spago.Cmd as Cmd setup :: IO () -> IO () setup cmd = do - Temp.withTempDirectory "test/" "spago-test" $ \temp -> do + Temp.withTempDirectory "test/" "spago test" $ \temp -> do -- print ("Running in " <> temp) withCwd (decodeString temp) cmd @@ -170,7 +170,7 @@ spec = around_ setup $ do spago ["init"] >>= shouldBeSuccess mv "packages.dhall" "packagesBase.dhall" - writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { metadata_ = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/purescript-metadata.git\", version = \"spago-test/branch-with-slash\" }}" + writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { metadata_ = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/purescript-metadata.git\", version = \"spago test/branch-with-slash\" }}" spago ["install", "metadata_"] >>= shouldBeSuccess it "Spago should be able to install a package not in the set from a commit hash" $ do @@ -483,7 +483,7 @@ spec = around_ setup $ do dir <- pwd let dumpFile = dir "testOutput" - spago ["build", "--before", "echo before>> " <> ( Text.pack $ encodeString dumpFile )] >>= shouldBeSuccess + spago ["build", "--before", "echo before>> " <> Text.pack (escapeFilePath $ encodeString dumpFile)] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "before\n" @@ -507,8 +507,8 @@ spec = around_ setup $ do dir <- pwd let dumpFile = dir "testOutput" spago [ "build" - , "--before", "echo before>> " <> ( Text.pack $ encodeString dumpFile ) - , "--then", "echo then>> " <> ( Text.pack $ encodeString dumpFile ) + , "--before", "echo before>> " <> Text.pack (encodeString dumpFile) + , "--then", "echo then>> " <> Text.pack (encodeString dumpFile) ] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "before\nthen\n" @@ -539,7 +539,7 @@ spec = around_ setup $ do 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 ) + , "--else", "echo else>> " <> Text.pack (encodeString dumpFile) ] >>= shouldBeFailure test <- readTextFile dumpFile test `shouldBe` "else\n" @@ -754,10 +754,10 @@ spec = around_ setup $ do spago ["init"] >>= shouldBeSuccess if pursVersion >= purs0_15_0 then do spago ["bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess - checkFixture "bundle-app-esm.js" + checkFixture "bundle-app-esm.js" else do spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess - checkFixture "bundle-app.js" + checkFixture "bundle-app.js" it "Spago should bundle successfully with source map" $ do pursVersion :: Version.SemVer <- getPursVersion @@ -766,7 +766,7 @@ spec = around_ setup $ do spago ["init"] >>= shouldBeSuccess if pursVersion >= purs0_15_0 then do spago ["bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-app-src-map-esm.js" + checkFixture "bundle-app-src-map-esm.js" checkFileExist "bundle-app-src-map-esm.js.map" else do spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess @@ -808,7 +808,7 @@ spec = around_ setup $ do if pursVersion >= purs0_15_0 then do spago ["bundle-module", "--to", "bundle-module-src-map-esm.js", "--no-build", "--source-maps"] >>= shouldBeSuccess checkFixture "bundle-module-src-map-esm.js" - checkFileExist "bundle-module-src-map-esm.js.map" + checkFileExist "bundle-module-src-map-esm.js.map" else do spago ["bundle-module", "--to", "bundle-module-src-map.js", "--no-build", "--source-maps"] >>= shouldBeSuccess checkFixture "bundle-module-src-map.js" diff --git a/test/Utils.hs b/test/Utils.hs index 6dba28a12..901d0d7d7 100644 --- a/test/Utils.hs +++ b/test/Utils.hs @@ -21,11 +21,12 @@ module Utils , spago , withCwd , withEnvVar - ) where + , escapeFilePath) where import qualified Control.Concurrent as Concurrent import qualified Control.Exception as Exception import Data.Maybe (fromMaybe) +import Data.Foldable (foldl') import qualified Data.Text as Text import qualified Data.Text.Encoding as Text.Encoding import Data.Text.Encoding.Error (lenientDecode) @@ -161,3 +162,10 @@ getHighestTag = do pure $ case Text.strip tag of "" -> Nothing tag' -> Just tag' + +escapeFilePath :: String -> String +escapeFilePath = reverse . foldl' escSpace "" + where + escSpace acc x + | x == ' ' = x : '\\' : acc + | otherwise = x : acc diff --git a/test/fixtures/bundle-app-esm.js b/test/fixtures/bundle-app-esm.js new file mode 100644 index 000000000..54a5c7b6f --- /dev/null +++ b/test/fixtures/bundle-app-esm.js @@ -0,0 +1,14 @@ +(() => { + // output/Effect.Console/foreign.js + var log = function(s) { + return function() { + console.log(s); + }; + }; + + // output/Main/index.js + var main = /* @__PURE__ */ log("\u{1F35D}"); + + // index.js + main(); +})(); diff --git a/test/fixtures/bundle-app-src-map-esm.js b/test/fixtures/bundle-app-src-map-esm.js new file mode 100644 index 000000000..663b8f14c --- /dev/null +++ b/test/fixtures/bundle-app-src-map-esm.js @@ -0,0 +1,15 @@ +(() => { + // output/Effect.Console/foreign.js + var log = function(s) { + return function() { + console.log(s); + }; + }; + + // output/Main/index.js + var main = /* @__PURE__ */ log("\u{1F35D}"); + + // index.js + main(); +})(); +//# sourceMappingURL=bundle-app-src-map-esm.js.map diff --git a/test/fixtures/bundle-module-esm.js b/test/fixtures/bundle-module-esm.js new file mode 100644 index 000000000..3319b6f83 --- /dev/null +++ b/test/fixtures/bundle-module-esm.js @@ -0,0 +1,12 @@ +// output/Effect.Console/foreign.js +var log = function(s) { + return function() { + console.log(s); + }; +}; + +// output/Main/index.js +var main = /* @__PURE__ */ log("\u{1F35D}"); +export { + main +}; diff --git a/test/fixtures/bundle-module-src-map-esm.js b/test/fixtures/bundle-module-src-map-esm.js new file mode 100644 index 000000000..cca2194c7 --- /dev/null +++ b/test/fixtures/bundle-module-src-map-esm.js @@ -0,0 +1,13 @@ +// output/Effect.Console/foreign.js +var log = function(s) { + return function() { + console.log(s); + }; +}; + +// output/Main/index.js +var main = /* @__PURE__ */ log("\u{1F35D}"); +export { + main +}; +//# sourceMappingURL=bundle-module-src-map-esm.js.map From 675ddc4bcaf4000cfe7203af6096725264da6ecf Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Mon, 28 Mar 2022 08:03:55 +0100 Subject: [PATCH 18/82] Add esbuild dependency --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6c7c4cac0..7297c35db 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -95,7 +95,7 @@ jobs: $HOME\AppData\Local\Programs\stack\x86_64-windows key: ${{ runner.os }}-${{ hashFiles('stack.yaml') }}-1 - - run: npm install -g purescript@0.14.0 psc-package@3.0.1 bower@1.8.8 + - run: npm install -g purescript@0.14.0 psc-package@3.0.1 bower@1.8.8 esbuild@0.14.28 - name: Install dependencies run: | From 17d1db2ee3b7b358a9c517f73bf6ca624d341ad9 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Mon, 28 Mar 2022 08:14:00 +0100 Subject: [PATCH 19/82] Undo rename test directory with space --- test/SpagoSpec.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index ac94e51ef..49032b537 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -20,7 +20,7 @@ import qualified Spago.Cmd as Cmd setup :: IO () -> IO () setup cmd = do - Temp.withTempDirectory "test/" "spago test" $ \temp -> do + Temp.withTempDirectory "test/" "spago-test" $ \temp -> do -- print ("Running in " <> temp) withCwd (decodeString temp) cmd @@ -170,7 +170,7 @@ spec = around_ setup $ do spago ["init"] >>= shouldBeSuccess mv "packages.dhall" "packagesBase.dhall" - writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { metadata_ = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/purescript-metadata.git\", version = \"spago test/branch-with-slash\" }}" + writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { metadata_ = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/purescript-metadata.git\", version = \"spago-test/branch-with-slash\" }}" spago ["install", "metadata_"] >>= shouldBeSuccess it "Spago should be able to install a package not in the set from a commit hash" $ do From b45f84cbaf6d093fb83e86678c7e2b728bb021ae Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 28 Mar 2022 08:34:11 -0500 Subject: [PATCH 20/82] Apply escapeFilePath to more 'encodeString' usages --- test/SpagoSpec.hs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 49032b537..c47512b19 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -494,8 +494,8 @@ spec = around_ setup $ do dir <- pwd let dumpFile = dir "testOutput" spago [ "build" - , "--then", "echo then>> " <> ( Text.pack $ encodeString dumpFile ) - , "--else", "echo else>> " <> ( Text.pack $ encodeString dumpFile ) + , "--then", "echo then>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) + , "--else", "echo else>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) ] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "then\n" @@ -507,8 +507,8 @@ spec = around_ setup $ do dir <- pwd let dumpFile = dir "testOutput" spago [ "build" - , "--before", "echo before>> " <> Text.pack (encodeString dumpFile) - , "--then", "echo then>> " <> Text.pack (encodeString dumpFile) + , "--before", "echo before>> " <> Text.pack (escapeFilePath $ encodeString dumpFile) + , "--then", "echo then>> " <> Text.pack (escapeFilePath $ encodeString dumpFile) ] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "before\nthen\n" @@ -522,8 +522,8 @@ spec = around_ setup $ do rm "src/Main.purs" writeTextFile "src/Main.purs" "Invalid Purescript code" spago [ "build" - , "--then", "echo then>> " <> ( Text.pack $ encodeString dumpFile ) - , "--else", "echo else>> " <> ( Text.pack $ encodeString dumpFile ) + , "--then", "echo then>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) + , "--else", "echo else>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) ] >>= shouldBeFailure test <- readTextFile dumpFile test `shouldBe` "else\n" @@ -539,7 +539,7 @@ spec = around_ setup $ do 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) + , "--else", "echo else>> " <> Text.pack (escapeFilePath $ encodeString dumpFile) ] >>= shouldBeFailure test <- readTextFile dumpFile test `shouldBe` "else\n" @@ -551,10 +551,10 @@ spec = around_ setup $ do dir <- pwd let dumpFile = dir "testOutput" spago [ "build" - , "--before", "echo before1>> " <> ( Text.pack $ encodeString dumpFile ) - , "--before", "echo before2>> " <> ( Text.pack $ encodeString dumpFile ) - , "--then", "echo then1>> " <> ( Text.pack $ encodeString dumpFile ) - , "--then", "echo then2>> " <> ( Text.pack $ encodeString dumpFile ) + , "--before", "echo before1>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) + , "--before", "echo before2>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) + , "--then", "echo then1>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) + , "--then", "echo then2>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) ] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "before1\nbefore2\nthen1\nthen2\n" From 5dc37823d50f767792fdabf9102c5e8a7042664f Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 28 Mar 2022 08:34:29 -0500 Subject: [PATCH 21/82] Rerun tests with space in parent folder name --- test/SpagoSpec.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index c47512b19..49b988497 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -20,7 +20,7 @@ import qualified Spago.Cmd as Cmd setup :: IO () -> IO () setup cmd = do - Temp.withTempDirectory "test/" "spago-test" $ \temp -> do + Temp.withTempDirectory "test/" "spago test" $ \temp -> do -- print ("Running in " <> temp) withCwd (decodeString temp) cmd From dc5e45f46e003c59498c7637a9011a4437042e27 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 28 Mar 2022 08:57:39 -0500 Subject: [PATCH 22/82] Don't escape space on windows --- test/Utils.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/Utils.hs b/test/Utils.hs index 901d0d7d7..55474826b 100644 --- a/test/Utils.hs +++ b/test/Utils.hs @@ -32,6 +32,7 @@ import qualified Data.Text.Encoding as Text.Encoding import Data.Text.Encoding.Error (lenientDecode) import Prelude hiding (FilePath) import System.Directory (removePathForcibly, doesFileExist) +import qualified System.Info.Extra as SysInfoExtra import qualified System.Process as Process import Test.Hspec (HasCallStack, shouldBe, shouldSatisfy) import Turtle (ExitCode (..), FilePath, Text, cd, empty, encodeString, export, @@ -164,7 +165,9 @@ getHighestTag = do tag' -> Just tag' escapeFilePath :: String -> String -escapeFilePath = reverse . foldl' escSpace "" +escapeFilePath + | SysInfoExtra.isWindows = id + | otherwise = reverse . foldl' escSpace "" where escSpace acc x | x == ' ' = x : '\\' : acc From c326e0219f76fff8af028a845fa8315e677bded2 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 28 Mar 2022 08:59:18 -0500 Subject: [PATCH 23/82] Rename escapeFilePath to escapeSpace --- test/SpagoSpec.hs | 26 +++++++++++++------------- test/Utils.hs | 6 +++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 49b988497..51a27f71a 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -13,7 +13,7 @@ import Utils (checkFileHasInfix, checkFixture, checkFileE readFixture, runFor, shouldBeFailure, shouldBeFailureInfix, shouldBeFailureStderr, shouldBeSuccess, shouldBeSuccessOutput, shouldBeSuccessOutputWithErr, shouldBeSuccessStderr, spago, - withCwd, withEnvVar, escapeFilePath) + withCwd, withEnvVar, escapeSpace) import qualified Data.Versions as Version import qualified Spago.Cmd as Cmd @@ -483,7 +483,7 @@ spec = around_ setup $ do dir <- pwd let dumpFile = dir "testOutput" - spago ["build", "--before", "echo before>> " <> Text.pack (escapeFilePath $ encodeString dumpFile)] >>= shouldBeSuccess + spago ["build", "--before", "echo before>> " <> Text.pack (escapeSpace $ encodeString dumpFile)] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "before\n" @@ -494,8 +494,8 @@ spec = around_ setup $ do dir <- pwd let dumpFile = dir "testOutput" spago [ "build" - , "--then", "echo then>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) - , "--else", "echo else>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) + , "--then", "echo then>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + , "--else", "echo else>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) ] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "then\n" @@ -507,8 +507,8 @@ spec = around_ setup $ do dir <- pwd let dumpFile = dir "testOutput" spago [ "build" - , "--before", "echo before>> " <> Text.pack (escapeFilePath $ encodeString dumpFile) - , "--then", "echo then>> " <> Text.pack (escapeFilePath $ encodeString dumpFile) + , "--before", "echo before>> " <> Text.pack (escapeSpace $ encodeString dumpFile) + , "--then", "echo then>> " <> Text.pack (escapeSpace $ encodeString dumpFile) ] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "before\nthen\n" @@ -522,8 +522,8 @@ spec = around_ setup $ do rm "src/Main.purs" writeTextFile "src/Main.purs" "Invalid Purescript code" spago [ "build" - , "--then", "echo then>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) - , "--else", "echo else>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) + , "--then", "echo then>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + , "--else", "echo else>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) ] >>= shouldBeFailure test <- readTextFile dumpFile test `shouldBe` "else\n" @@ -539,7 +539,7 @@ spec = around_ setup $ do rm "src/Main.purs" writeTextFile "src/Main.purs" "module Main where\nimport Effect.Exception\nmain = throw \"error\"" spago [ "run" - , "--else", "echo else>> " <> Text.pack (escapeFilePath $ encodeString dumpFile) + , "--else", "echo else>> " <> Text.pack (escapeSpace $ encodeString dumpFile) ] >>= shouldBeFailure test <- readTextFile dumpFile test `shouldBe` "else\n" @@ -551,10 +551,10 @@ spec = around_ setup $ do dir <- pwd let dumpFile = dir "testOutput" spago [ "build" - , "--before", "echo before1>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) - , "--before", "echo before2>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) - , "--then", "echo then1>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) - , "--then", "echo then2>> " <> ( Text.pack $ escapeFilePath $ encodeString dumpFile ) + , "--before", "echo before1>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + , "--before", "echo before2>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + , "--then", "echo then1>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + , "--then", "echo then2>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) ] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "before1\nbefore2\nthen1\nthen2\n" diff --git a/test/Utils.hs b/test/Utils.hs index 55474826b..31603fa43 100644 --- a/test/Utils.hs +++ b/test/Utils.hs @@ -21,7 +21,7 @@ module Utils , spago , withCwd , withEnvVar - , escapeFilePath) where + , escapeSpace) where import qualified Control.Concurrent as Concurrent import qualified Control.Exception as Exception @@ -164,8 +164,8 @@ getHighestTag = do "" -> Nothing tag' -> Just tag' -escapeFilePath :: String -> String -escapeFilePath +escapeSpace :: String -> String +escapeSpace | SysInfoExtra.isWindows = id | otherwise = reverse . foldl' escSpace "" where From 0253667f55d060263e75cd0b5c3e519731d59b64 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 28 Mar 2022 10:26:13 -0500 Subject: [PATCH 24/82] Run all tests in folder name w/o space --- test/SpagoSpec.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 51a27f71a..24461e113 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -20,7 +20,7 @@ import qualified Spago.Cmd as Cmd setup :: IO () -> IO () setup cmd = do - Temp.withTempDirectory "test/" "spago test" $ \temp -> do + Temp.withTempDirectory "test/" "spago-test" $ \temp -> do -- print ("Running in " <> temp) withCwd (decodeString temp) cmd From b014d28ec4691df6136e37636d7d89599e521e17 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 28 Mar 2022 10:36:17 -0500 Subject: [PATCH 25/82] Indent all tests one level --- test/SpagoSpec.hs | 1402 ++++++++++++++++++++++----------------------- 1 file changed, 701 insertions(+), 701 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 24461e113..268445427 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -27,839 +27,839 @@ setup cmd = do spec :: Spec spec = around_ setup $ do - describe "spago init" $ do + describe "spago init" $ do - it "Spago should have set up a project" $ do + it "Spago should have set up a project" $ do - spago ["init"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess - it "Spago should refuse to overwrite an existing project without -f" $ do + it "Spago should refuse to overwrite an existing project without -f" $ do - spago ["init"] >>= shouldBeSuccess - spago ["init"] >>= shouldBeFailure + spago ["init"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeFailure - it "Spago should not overwrite files when initing a project" $ do + it "Spago should not overwrite files when initing a project" $ do - mktree "src" - writeTextFile "src/Main.purs" "Something" - spago ["init"] >>= shouldBeSuccess - readTextFile "src/Main.purs" `shouldReturn` "Something" + mktree "src" + writeTextFile "src/Main.purs" "Something" + spago ["init"] >>= shouldBeSuccess + readTextFile "src/Main.purs" `shouldReturn` "Something" - it "Spago should always succeed in doing init with force" $ do + it "Spago should always succeed in doing init with force" $ do - spago ["init"] >>= shouldBeSuccess - spago ["init", "-f"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + spago ["init", "-f"] >>= shouldBeSuccess - it "Spago should import config from psc-package" $ do + it "Spago should import config from psc-package" $ do - writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" - spago ["init"] >>= shouldBeSuccess - cp "spago.dhall" "spago-psc-success.dhall" - checkFixture "spago-psc-success.dhall" + writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" + spago ["init"] >>= shouldBeSuccess + cp "spago.dhall" "spago-psc-success.dhall" + checkFixture "spago-psc-success.dhall" - it "Spago should not import dependencies that are not in the package-set" $ do + it "Spago should not import dependencies that are not in the package-set" $ do - writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\", \"foo\", \"bar\" ], \"set\": \"foo\", \"source\": \"bar\" }" - spago ["init", "-f"] >>= shouldBeSuccess - cp "spago.dhall" "spago-psc-failure.dhall" - checkFixture "spago-psc-failure.dhall" + writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\", \"foo\", \"bar\" ], \"set\": \"foo\", \"source\": \"bar\" }" + spago ["init", "-f"] >>= shouldBeSuccess + cp "spago.dhall" "spago-psc-failure.dhall" + checkFixture "spago-psc-failure.dhall" - it "Spago should import configs from Bower" $ do + it "Spago should import configs from Bower" $ do - shellStrictWithErr "git clone https://github.com/justinwoo/purescript-simple-json.git ." empty - shellStrictWithErr "git checkout v8.0.0" empty - spago ["init"] >>= shouldBeSuccess - mv "spago.dhall" "spago-bower-import.dhall" - checkFixture "spago-bower-import.dhall" + shellStrictWithErr "git clone https://github.com/justinwoo/purescript-simple-json.git ." empty + shellStrictWithErr "git checkout v8.0.0" empty + spago ["init"] >>= shouldBeSuccess + mv "spago.dhall" "spago-bower-import.dhall" + checkFixture "spago-bower-import.dhall" - it "Spago should strip comments from spago.dhall and packages.dhall" $ do + it "Spago should strip comments from spago.dhall and packages.dhall" $ do - spago ["init", "--no-comments"] >>= shouldBeSuccess + spago ["init", "--no-comments"] >>= shouldBeSuccess - cp "spago.dhall" "spago-no-comments.dhall" - checkFixture "spago-no-comments.dhall" + cp "spago.dhall" "spago-no-comments.dhall" + checkFixture "spago-no-comments.dhall" - -- We don't want fixture for packages.dhall to avoid having to maintain upstream package-set URL in fixture - dhallSource <- readTextFile "packages.dhall" - dhallSource `shouldNotSatisfy` (Text.isInfixOf "{-") -- comments not present - dhallSource `shouldSatisfy` (Text.isInfixOf "let upstream") -- some dhall stuff is present + -- We don't want fixture for packages.dhall to avoid having to maintain upstream package-set URL in fixture + dhallSource <- readTextFile "packages.dhall" + dhallSource `shouldNotSatisfy` (Text.isInfixOf "{-") -- comments not present + dhallSource `shouldSatisfy` (Text.isInfixOf "let upstream") -- some dhall stuff is present - it "Spago should use user-specified tag if it exists instead of latest release" $ do - spago ["init", "--tag", "psc-0.13.4-20191025"] >>= shouldBeSuccess + it "Spago should use user-specified tag if it exists instead of latest release" $ do + spago ["init", "--tag", "psc-0.13.4-20191025"] >>= shouldBeSuccess - mv "packages.dhall" "packages-older-tag.dhall" - checkFixture "packages-older-tag.dhall" + mv "packages.dhall" "packages-older-tag.dhall" + checkFixture "packages-older-tag.dhall" - it "Spago should use template/packages.dhall file if user-specified tag does not exist" $ do - spago ["init", "--tag", "does-not-exist"] >>= shouldBeSuccess + it "Spago should use template/packages.dhall file if user-specified tag does not exist" $ do + spago ["init", "--tag", "does-not-exist"] >>= shouldBeSuccess - originalPackage <- readTextFile "packages.dhall" - let [originalPackageSetUrl] - = map Text.strip - $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") - $ Text.lines originalPackage + originalPackage <- readTextFile "packages.dhall" + let [originalPackageSetUrl] + = map Text.strip + $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") + $ Text.lines originalPackage - mv "packages.dhall" "original-packages.dhall" + mv "packages.dhall" "original-packages.dhall" - spago ["init", "--force"] >>= shouldBeSuccess + spago ["init", "--force"] >>= shouldBeSuccess - templatePackages <- readTextFile "../../templates/packages.dhall" - let [templatePackageSetUrl] - = map Text.strip - $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") - $ Text.lines templatePackages + templatePackages <- readTextFile "../../templates/packages.dhall" + let [templatePackageSetUrl] + = map Text.strip + $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") + $ Text.lines templatePackages - originalPackageSetUrl `shouldBe` templatePackageSetUrl + originalPackageSetUrl `shouldBe` templatePackageSetUrl - describe "spago install" $ do + describe "spago install" $ do - it "Subsequent installs should succeed after failed install" $ do + it "Subsequent installs should succeed after failed install" $ do - spago ["init"] >>= shouldBeSuccess - -- Run `install` once and kill it soon to simulate failure - runFor 5000 "spago" ["install", "-j", "3"] - -- Sleep for some time, as the above might take time to cleanup old processes - threadDelay 1000000 - spago ["install", "-j", "10"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + -- Run `install` once and kill it soon to simulate failure + runFor 5000 "spago" ["install", "-j", "3"] + -- Sleep for some time, as the above might take time to cleanup old processes + threadDelay 1000000 + spago ["install", "-j", "10"] >>= shouldBeSuccess - it "Spago should warn that config was not changed, when trying to install package already present in project dependencies" $ do + it "Spago should warn that config was not changed, when trying to install package already present in project dependencies" $ do - spago ["init"] >>= shouldBeSuccess - spago ["install"] >>= shouldBeSuccess - spago ["install", "effect"] >>= shouldBeSuccessStderr "spago-install-existing-dep-stderr.txt" + spago ["init"] >>= shouldBeSuccess + spago ["install"] >>= shouldBeSuccess + spago ["install", "effect"] >>= shouldBeSuccessStderr "spago-install-existing-dep-stderr.txt" - it "Spago should strip 'purescript-' prefix and give warning if package without prefix is present in package set" $ do + it "Spago should strip 'purescript-' prefix and give warning if package without prefix is present in package set" $ do - spago ["init"] >>= shouldBeSuccess - spago ["install", "safe-coerce"] >>= shouldBeSuccess - spago ["install", "purescript-newtype"] >>= shouldBeSuccessStderr "spago-install-purescript-prefix-stderr.txt" - -- dep added without "purescript-" prefix - checkFileHasInfix "spago.dhall" "\"newtype\"" + spago ["init"] >>= shouldBeSuccess + spago ["install", "safe-coerce"] >>= shouldBeSuccess + spago ["install", "purescript-newtype"] >>= shouldBeSuccessStderr "spago-install-purescript-prefix-stderr.txt" + -- dep added without "purescript-" prefix + checkFileHasInfix "spago.dhall" "\"newtype\"" - it "Spago should be able to add dependencies" $ do + it "Spago should be able to add dependencies" $ do - writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" - spago ["init"] >>= shouldBeSuccess - spago ["-j 10", "install", "simple-json", "foreign"] >>= shouldBeSuccess - mv "spago.dhall" "spago-install-success.dhall" - checkFixture "spago-install-success.dhall" + writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" + spago ["init"] >>= shouldBeSuccess + spago ["-j 10", "install", "simple-json", "foreign"] >>= shouldBeSuccess + mv "spago.dhall" "spago-install-success.dhall" + checkFixture "spago-install-success.dhall" - it "Spago should not add dependencies that are not in the package set" $ do + it "Spago should not add dependencies that are not in the package set" $ do - writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" - spago ["init"] >>= shouldBeSuccess - spago ["install", "foo", "bar"] >>= shouldBeFailureStderr "missing-dependencies.txt" - mv "spago.dhall" "spago-install-failure.dhall" - checkFixture "spago-install-failure.dhall" + writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" + spago ["init"] >>= shouldBeSuccess + spago ["install", "foo", "bar"] >>= shouldBeFailureStderr "missing-dependencies.txt" + mv "spago.dhall" "spago-install-failure.dhall" + checkFixture "spago-install-failure.dhall" - it "Spago should not allow circular dependencies" $ do + it "Spago should not allow circular dependencies" $ do - writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" - spago ["init"] >>= shouldBeSuccess - writeTextFile "spago.dhall" "{- Welcome to a Spago project! You can edit this file as you like. -} { name = \"my-project\" , dependencies = [ \"effect\", \"console\", \"a\", \"b\" ] , packages = ./packages.dhall // { a = { version = \"a1\", dependencies = [\"b\"], repo = \"https://github.com/fake/fake.git\" }, b = { version = \"b1\", dependencies = [\"a\"], repo = \"https://github.com/fake/fake.git\" } } }" - spago ["install"] >>= shouldBeFailureStderr "circular-dependencies.txt" + writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" + spago ["init"] >>= shouldBeSuccess + writeTextFile "spago.dhall" "{- Welcome to a Spago project! You can edit this file as you like. -} { name = \"my-project\" , dependencies = [ \"effect\", \"console\", \"a\", \"b\" ] , packages = ./packages.dhall // { a = { version = \"a1\", dependencies = [\"b\"], repo = \"https://github.com/fake/fake.git\" }, b = { version = \"b1\", dependencies = [\"a\"], repo = \"https://github.com/fake/fake.git\" } } }" + spago ["install"] >>= shouldBeFailureStderr "circular-dependencies.txt" - it "Spago should be able to install a package in the set from a commit hash" $ do + it "Spago should be able to install a package in the set from a commit hash" $ do - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packagesBase.dhall" - writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { simple-json = pkgs.simple-json // { version = \"d45590f493d68baae174b2d3062d502c0cc4c265\" } }" - spago ["install", "simple-json"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packagesBase.dhall" + writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { simple-json = pkgs.simple-json // { version = \"d45590f493d68baae174b2d3062d502c0cc4c265\" } }" + spago ["install", "simple-json"] >>= shouldBeSuccess - it "Spago should be able to install a package version by branch name with / in it" $ do + it "Spago should be able to install a package version by branch name with / in it" $ do - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packagesBase.dhall" - writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { metadata_ = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/purescript-metadata.git\", version = \"spago-test/branch-with-slash\" }}" - spago ["install", "metadata_"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packagesBase.dhall" + writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { metadata_ = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/purescript-metadata.git\", version = \"spago-test/branch-with-slash\" }}" + spago ["install", "metadata_"] >>= shouldBeSuccess - it "Spago should be able to install a package not in the set from a commit hash" $ do + it "Spago should be able to install a package not in the set from a commit hash" $ do - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packagesBase.dhall" - writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { spago = { dependencies = [\"prelude\"], repo = \"https://github.com/purescript/spago.git\", version = \"cbdbbf8f8771a7e43f04b18cdefffbcb0f03a990\" }}" - spago ["install", "spago"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packagesBase.dhall" + writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { spago = { dependencies = [\"prelude\"], repo = \"https://github.com/purescript/spago.git\", version = \"cbdbbf8f8771a7e43f04b18cdefffbcb0f03a990\" }}" + spago ["install", "spago"] >>= shouldBeSuccess - it "Spago should not be able to install a package from a not-existing commit hash" $ do + it "Spago should not be able to install a package from a not-existing commit hash" $ do - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packagesBase.dhall" - writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { spago = { dependencies = [\"prelude\"], repo = \"https://github.com/purescript/spago.git\", version = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" }}" - spago ["install", "spago"] >>= shouldBeFailure + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packagesBase.dhall" + writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { spago = { dependencies = [\"prelude\"], repo = \"https://github.com/purescript/spago.git\", version = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" }}" + spago ["install", "spago"] >>= shouldBeFailure - it "Spago should be able to update dependencies in an alternative config" $ do + it "Spago should be able to update dependencies in an alternative config" $ do - spago ["init"] >>= shouldBeSuccess - writeTextFile "alternative1.dhall" "./spago.dhall // {dependencies = [\"prelude\"]}" - spago ["-x", "alternative1.dhall", "install", "simple-json"] >>= shouldBeSuccess - checkFixture "alternative1.dhall" + spago ["init"] >>= shouldBeSuccess + writeTextFile "alternative1.dhall" "./spago.dhall // {dependencies = [\"prelude\"]}" + spago ["-x", "alternative1.dhall", "install", "simple-json"] >>= shouldBeSuccess + checkFixture "alternative1.dhall" - it "Spago should fail when the alternate config file doesn't exist" $ do - spago ["init"] >>= shouldBeSuccess - spago ["install", "-x", "test.dhall"] >>= shouldBeFailureStderr "alternate-config-missing.txt" + it "Spago should fail when the alternate config file doesn't exist" $ do + spago ["init"] >>= shouldBeSuccess + spago ["install", "-x", "test.dhall"] >>= shouldBeFailureStderr "alternate-config-missing.txt" - it "Spago should install successfully when the config file is in another directory" $ do + it "Spago should install successfully when the config file is in another directory" $ do - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - mkdir "nested" - writeTextFile "./nested/spago.dhall" "{ name = \"nested\", sources = [ \"src/**/*.purs\" ], dependencies = [ \"effect\", \"console\", ] , packages = ../packages.dhall }" - spago ["install", "--config", "./nested/spago.dhall"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + mkdir "nested" + writeTextFile "./nested/spago.dhall" "{ name = \"nested\", sources = [ \"src/**/*.purs\" ], dependencies = [ \"effect\", \"console\", ] , packages = ../packages.dhall }" + spago ["install", "--config", "./nested/spago.dhall"] >>= shouldBeSuccess + + it "Spago should not change the alternative config if it does not change dependencies" $ do + + spago ["init"] >>= shouldBeSuccess + writeTextFile "alternative2.dhall" "./spago.dhall // { sources = [ \"src/**/*.purs\" ] }\n" + spago ["-x", "alternative2.dhall", "install", "simple-json"] >>= shouldBeSuccess + spago ["-x", "alternative2.dhall", "install", "simple-json"] >>= shouldBeSuccessStderr "alternative2install-stderr.txt" + checkFixture "alternative2.dhall" + + it "Spago should install successfully when there are local dependencies sharing the same packages.dhall" $ do - it "Spago should not change the alternative config if it does not change dependencies" $ do + -- Create local 'lib-a' package that depends on lib-c + mkdir "lib-a" + cd "lib-a" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-a\", dependencies = [\"console\", \"effect\", \"prelude\", \"lib-c\"], packages = ../packages.dhall }" + cd ".." + + -- Create local 'lib-b' package that has its dependencies in a separate file + mkdir "lib-b" + cd "lib-b" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-b\", dependencies = ./spago-deps.dhall, packages = ../packages.dhall }" + writeTextFile "spago-deps.dhall" "[\"console\", \"effect\", \"prelude\"]" + cd ".." - spago ["init"] >>= shouldBeSuccess - writeTextFile "alternative2.dhall" "./spago.dhall // { sources = [ \"src/**/*.purs\" ] }\n" - spago ["-x", "alternative2.dhall", "install", "simple-json"] >>= shouldBeSuccess - spago ["-x", "alternative2.dhall", "install", "simple-json"] >>= shouldBeSuccessStderr "alternative2install-stderr.txt" - checkFixture "alternative2.dhall" + -- Create local 'lib-c' package + mkdir "lib-c" + cd "lib-c" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-c\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ../packages.dhall }" + cd ".." - it "Spago should install successfully when there are local dependencies sharing the same packages.dhall" $ do + -- Create 'app' package that depends on 'lib-a' and 'lib-b' + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" "{ name = \"app\", dependencies = [\"console\", \"effect\", \"prelude\", \"lib-a\", \"lib-b\"], packages = ./packages.dhall }" + packageDhall <- readTextFile "packages.dhall" + writeTextFile "packages.dhall" $ packageDhall <> " // { lib-a = ./lib-a/spago.dhall as Location, lib-b = ./lib-b/spago.dhall as Location, lib-c = ./lib-c/spago.dhall as Location }" - -- Create local 'lib-a' package that depends on lib-c - mkdir "lib-a" - cd "lib-a" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-a\", dependencies = [\"console\", \"effect\", \"prelude\", \"lib-c\"], packages = ../packages.dhall }" - cd ".." + spago ["install"] >>= shouldBeSuccess - -- Create local 'lib-b' package that has its dependencies in a separate file - mkdir "lib-b" - cd "lib-b" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-b\", dependencies = ./spago-deps.dhall, packages = ../packages.dhall }" - writeTextFile "spago-deps.dhall" "[\"console\", \"effect\", \"prelude\"]" - cd ".." + it "Spago should not warn about freezing remote imports if they can be located from spago.dhall" $ do - -- Create local 'lib-c' package - mkdir "lib-c" - cd "lib-c" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-c\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ../packages.dhall }" - cd ".." + spago ["init"] >>= shouldBeSuccess + -- Do an initial installation so that it's easier to compare subsequent output + spago ["install"] >>= shouldBeSuccess - -- Create 'app' package that depends on 'lib-a' and 'lib-b' - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" "{ name = \"app\", dependencies = [\"console\", \"effect\", \"prelude\", \"lib-a\", \"lib-b\"], packages = ./packages.dhall }" - packageDhall <- readTextFile "packages.dhall" - writeTextFile "packages.dhall" $ packageDhall <> " // { lib-a = ./lib-a/spago.dhall as Location, lib-b = ./lib-b/spago.dhall as Location, lib-c = ./lib-c/spago.dhall as Location }" + mkdir "elsewhere" + writeTextFile "elsewhere/a.dhall" "let p = ./b.dhall in p" + mv "packages.dhall" "elsewhere/b.dhall" + spagoDhall <- readTextFile "spago.dhall" + writeTextFile "spago.dhall" $ Text.replace "./packages.dhall" "./elsewhere/a.dhall" spagoDhall + spago ["install"] >>= shouldBeSuccessStderr "ensure-frozen-success.txt" - spago ["install"] >>= shouldBeSuccess + describe "spago sources" $ do - it "Spago should not warn about freezing remote imports if they can be located from spago.dhall" $ do + it "Spago should print both dependencies and project sources" $ do - spago ["init"] >>= shouldBeSuccess - -- Do an initial installation so that it's easier to compare subsequent output - spago ["install"] >>= shouldBeSuccess - - mkdir "elsewhere" - writeTextFile "elsewhere/a.dhall" "let p = ./b.dhall in p" - mv "packages.dhall" "elsewhere/b.dhall" - spagoDhall <- readTextFile "spago.dhall" - writeTextFile "spago.dhall" $ Text.replace "./packages.dhall" "./elsewhere/a.dhall" spagoDhall - spago ["install"] >>= shouldBeSuccessStderr "ensure-frozen-success.txt" - - describe "spago sources" $ do - - it "Spago should print both dependencies and project sources" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["sources"] >>= shouldBeSuccessOutput "sources-output.txt" - - -- -- This is currently commented because it requires a GitHub token and Travis makes it hard to do it securely - -- describe "spago login" $ do - -- - -- it "Spago should login correctly" $ do - -- - -- spago ["login"] >>= shouldBeSuccessOutput "login-output.txt" - - describe "spago build" $ do - - it "Spago should build successfully" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - - it "Spago should pass options to purs" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["build", "--purs-args", "-o myOutput"] >>= shouldBeSuccess - testdir "myOutput" `shouldReturn` True - - it "Spago should pass multiple options to purs" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["build", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess - testdir "myOutput" `shouldReturn` True - - it "Spago should build successfully with sources included from custom path" $ do - - spago ["init"] >>= shouldBeSuccess - mkdir "another_source_path" - mv "src/Main.purs" "another_source_path/Main.purs" - spago ["build", "--path", "another_source_path/*.purs"] >>= shouldBeSuccess - - it "Spago should not install packages when passing the --no-install flag" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["build", "--no-install"] >>= shouldBeFailure - spago ["install"] >>= shouldBeSuccess - spago ["build", "--no-install"] >>= shouldBeSuccess - - it "Spago should add sources to config when key is missing" $ do - - configV1 <- readFixture "spago-configV1.dhall" - spago ["init"] >>= shouldBeSuccess - -- Replace initial config with the old config format (without 'sources') - mv "spago.dhall" "spago-old.dhall" - writeTextFile "spago.dhall" configV1 - - spago ["install"] >>= shouldBeSuccess - mv "spago.dhall" "spago-configV2.dhall" - checkFixture "spago-configV2.dhall" - - it "Spago should create a local output folder" $ do - - -- Create root-level packages.dhall - mkdir "monorepo" - cd "monorepo" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - - -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) - mkdir "lib-a" - cd "lib-a" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - rm "packages.dhall" - writeTextFile "packages.dhall" $ "../packages.dhall" - spago ["build"] >>= shouldBeSuccess - testdir "output" `shouldReturn` True - - cd ".." - testdir "output" `shouldReturn` False - - it "Spago should use the main packages.dhall even when another packages.dhall is further up the tree" $ do - - -- Create root-level packages.dhall that directs to middle one - mkdir "monorepo-1" - cd "monorepo-1" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - rm "packages.dhall" - writeTextFile "packages.dhall" $ "./monorepo-2/packages.dhall" - - -- Create local 'monorepo-2' package that is the real root - mkdir "monorepo-2" - cd "monorepo-2" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - spago ["build"] >>= shouldBeSuccess - testdir "output" `shouldReturn` True - - -- Create local 'monorepo-3' package that uses packages.dhall on top level - mkdir "monorepo-3" - cd "monorepo-3" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - rm "packages.dhall" - writeTextFile "packages.dhall" $ "../../packages.dhall" - spago ["build"] >>= shouldBeSuccess - testdir "output" `shouldReturn` True - - cd ".." - testdir "output" `shouldReturn` True - - cd ".." - testdir "output" `shouldReturn` False - - it "Spago should find the middle packages.dhall even when another file is further up the tree" $ do - - -- Create root-level module to confuse things - mkdir "monorepo-root" - cd "monorepo-root" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-extra\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - - -- get rid of duplicate Main module - cd "src" - rm "Main.purs" - writeTextFile "Main.purs" $ "module OtherMain where \n import Prelude\n import Effect\n main :: Effect Unit\n main = pure unit" - cd ".." - - -- create real root - mkdir "subfolder" - cd "subfolder" - spago ["init"] >>= shouldBeSuccess - packageDhall <- readTextFile "packages.dhall" - writeTextFile "packages.dhall" $ packageDhall <> " // { lib-extra = ../spago.dhall as Location }" - - -- Create local 'lib-a' package that uses packages.dhall in middle folder - mkdir "lib-a" - cd "lib-a" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"lib-extra\",\"console\", \"effect\", \"prelude\"], packages = ../packages.dhall }" - rm "packages.dhall" - spago ["build"] >>= shouldBeSuccess - - -- don't use nested folder - testdir "output" `shouldReturn` True - - -- use middle one - cd ".." - testdir "output" `shouldReturn` False - - -- not the trick root folder - cd ".." - testdir "output" `shouldReturn` False - - describe "import checking" $ do - - it "Spago should fail on direct project imports from transitive dependencies" $ do + spago ["init"] >>= shouldBeSuccess + spago ["sources"] >>= shouldBeSuccessOutput "sources-output.txt" + + -- -- This is currently commented because it requires a GitHub token and Travis makes it hard to do it securely + -- describe "spago login" $ do + -- + -- it "Spago should login correctly" $ do + -- + -- spago ["login"] >>= shouldBeSuccessOutput "login-output.txt" + + describe "spago build" $ do + + it "Spago should build successfully" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + + it "Spago should pass options to purs" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["build", "--purs-args", "-o myOutput"] >>= shouldBeSuccess + testdir "myOutput" `shouldReturn` True + + it "Spago should pass multiple options to purs" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["build", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess + testdir "myOutput" `shouldReturn` True + + it "Spago should build successfully with sources included from custom path" $ do + + spago ["init"] >>= shouldBeSuccess + mkdir "another_source_path" + mv "src/Main.purs" "another_source_path/Main.purs" + spago ["build", "--path", "another_source_path/*.purs"] >>= shouldBeSuccess + + it "Spago should not install packages when passing the --no-install flag" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["build", "--no-install"] >>= shouldBeFailure + spago ["install"] >>= shouldBeSuccess + spago ["build", "--no-install"] >>= shouldBeSuccess + + it "Spago should add sources to config when key is missing" $ do + + configV1 <- readFixture "spago-configV1.dhall" + spago ["init"] >>= shouldBeSuccess + -- Replace initial config with the old config format (without 'sources') + mv "spago.dhall" "spago-old.dhall" + writeTextFile "spago.dhall" configV1 + + spago ["install"] >>= shouldBeSuccess + mv "spago.dhall" "spago-configV2.dhall" + checkFixture "spago-configV2.dhall" + + it "Spago should create a local output folder" $ do + + -- Create root-level packages.dhall + mkdir "monorepo" + cd "monorepo" spago ["init"] >>= shouldBeSuccess rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"check-imports\", dependencies = [\"effect\", \"lists\"], packages = ./packages.dhall }" - rm "src/Main.purs" - writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nimport Data.Maybe\nimport Data.List\nmain = unit" - rm "test/Main.purs" - spago ["build"] - spago ["--no-psa", "build"] >>= shouldBeFailureStderr "check-direct-import-transitive-dependency.txt" - it "Spago should warn on unused dependencies" $ do + -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) + mkdir "lib-a" + cd "lib-a" spago ["init"] >>= shouldBeSuccess rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"check-imports\", dependencies = [\"effect\", \"prelude\"], packages = ./packages.dhall }" - rm "src/Main.purs" - writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nmain :: Unit\nmain = unit" - rm "test/Main.purs" - spago ["build"] - spago ["--no-psa", "build"] >>= shouldBeSuccessStderr "check-unused-dependency.txt" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["build"] >>= shouldBeSuccess + testdir "output" `shouldReturn` True + + cd ".." + testdir "output" `shouldReturn` False + + it "Spago should use the main packages.dhall even when another packages.dhall is further up the tree" $ do + + -- Create root-level packages.dhall that directs to middle one + mkdir "monorepo-1" + cd "monorepo-1" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "./monorepo-2/packages.dhall" + + -- Create local 'monorepo-2' package that is the real root + mkdir "monorepo-2" + cd "monorepo-2" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + spago ["build"] >>= shouldBeSuccess + testdir "output" `shouldReturn` True + + -- Create local 'monorepo-3' package that uses packages.dhall on top level + mkdir "monorepo-3" + cd "monorepo-3" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../../packages.dhall" + spago ["build"] >>= shouldBeSuccess + testdir "output" `shouldReturn` True + + cd ".." + testdir "output" `shouldReturn` True - it "Spago should not warn on unused dependencies when building deps-only" $ do + cd ".." + testdir "output" `shouldReturn` False + + it "Spago should find the middle packages.dhall even when another file is further up the tree" $ do + + -- Create root-level module to confuse things + mkdir "monorepo-root" + cd "monorepo-root" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-extra\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + + -- get rid of duplicate Main module + cd "src" + rm "Main.purs" + writeTextFile "Main.purs" $ "module OtherMain where \n import Prelude\n import Effect\n main :: Effect Unit\n main = pure unit" + cd ".." + + -- create real root + mkdir "subfolder" + cd "subfolder" + spago ["init"] >>= shouldBeSuccess + packageDhall <- readTextFile "packages.dhall" + writeTextFile "packages.dhall" $ packageDhall <> " // { lib-extra = ../spago.dhall as Location }" + + -- Create local 'lib-a' package that uses packages.dhall in middle folder + mkdir "lib-a" + cd "lib-a" spago ["init"] >>= shouldBeSuccess rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"check-imports\", dependencies = [\"effect\", \"prelude\"], packages = ./packages.dhall }" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"lib-extra\",\"console\", \"effect\", \"prelude\"], packages = ../packages.dhall }" + rm "packages.dhall" + spago ["build"] >>= shouldBeSuccess + + -- don't use nested folder + testdir "output" `shouldReturn` True + + -- use middle one + cd ".." + testdir "output" `shouldReturn` False + + -- not the trick root folder + cd ".." + testdir "output" `shouldReturn` False + + describe "import checking" $ do + + it "Spago should fail on direct project imports from transitive dependencies" $ do + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"check-imports\", dependencies = [\"effect\", \"lists\"], packages = ./packages.dhall }" + rm "src/Main.purs" + writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nimport Data.Maybe\nimport Data.List\nmain = unit" + rm "test/Main.purs" + spago ["build"] + spago ["--no-psa", "build"] >>= shouldBeFailureStderr "check-direct-import-transitive-dependency.txt" + + it "Spago should warn on unused dependencies" $ do + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"check-imports\", dependencies = [\"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "src/Main.purs" + writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nmain :: Unit\nmain = unit" + rm "test/Main.purs" + spago ["build"] + spago ["--no-psa", "build"] >>= shouldBeSuccessStderr "check-unused-dependency.txt" + + it "Spago should not warn on unused dependencies when building deps-only" $ do + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"check-imports\", dependencies = [\"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "src/Main.purs" + writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nmain :: Unit\nmain = unit" + rm "test/Main.purs" + spago ["build"] + spago ["--no-psa", "build", "--deps-only"] >>= shouldBeSuccessStderr "spago-build-succeeded-stderr.txt" + + describe "alternate backend" $ do + + it "Spago should use alternate backend if option is specified" $ do + configWithBackend <- readFixture "spago-configWithBackend.dhall" + spago ["init"] >>= shouldBeSuccess + mv "spago.dhall" "spago-old.dhall" + writeTextFile "spago.dhall" configWithBackend + + -- Blocked by https://github.com/purescript/purescript/issues/3743 + -- spago ["-j", "5", "build"] >>= shouldBeSuccess + -- checkFixture "alternate-backend-output.txt" + + it "Passing `--codegen corefn` with backend option should fail" $ do + configWithBackend <- readFixture "spago-configWithBackend.dhall" + spago ["init"] >>= shouldBeSuccess + mv "spago.dhall" "spago-old.dhall" + writeTextFile "spago.dhall" configWithBackend + + -- Blocked by https://github.com/purescript/purescript/issues/3743 + -- spago ["-j", "5", "build"] >>= shouldBeSuccess + -- spago ["build", "--purs-args", "--codegen", "--purs-args", "corefn"] >>= shouldBeFailureOutput "codegen-opt-with-backend.txt" + -- spago ["build", "--purs-args", "--codegen", "--purs-args", "docs"] >>= shouldBeFailureOutput "codegen-opt-with-backend.txt" + + it "Spago should run a before command" $ do + + spago ["init"] >>= shouldBeSuccess + + dir <- pwd + let dumpFile = dir "testOutput" + spago ["build", "--before", "echo before>> " <> Text.pack (escapeSpace $ encodeString dumpFile)] >>= shouldBeSuccess + test <- readTextFile dumpFile + test `shouldBe` "before\n" + + it "Spago should run a then command" $ do + + spago ["init"] >>= shouldBeSuccess + + dir <- pwd + let dumpFile = dir "testOutput" + spago [ "build" + , "--then", "echo then>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + , "--else", "echo else>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + ] >>= shouldBeSuccess + test <- readTextFile dumpFile + test `shouldBe` "then\n" + + it "Spago should run a before command before a then command" $ do + + spago ["init"] >>= shouldBeSuccess + + dir <- pwd + let dumpFile = dir "testOutput" + spago [ "build" + , "--before", "echo before>> " <> Text.pack (escapeSpace $ encodeString dumpFile) + , "--then", "echo then>> " <> Text.pack (escapeSpace $ encodeString dumpFile) + ] >>= shouldBeSuccess + test <- readTextFile dumpFile + test `shouldBe` "before\nthen\n" + + it "Spago should run an else command if there is an error in the build" $ do + + spago ["init"] >>= shouldBeSuccess + + dir <- pwd + let dumpFile = dir "testOutput" rm "src/Main.purs" - writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nmain :: Unit\nmain = unit" - rm "test/Main.purs" - spago ["build"] - spago ["--no-psa", "build", "--deps-only"] >>= shouldBeSuccessStderr "spago-build-succeeded-stderr.txt" + writeTextFile "src/Main.purs" "Invalid Purescript code" + spago [ "build" + , "--then", "echo then>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + , "--else", "echo else>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + ] >>= shouldBeFailure + test <- readTextFile dumpFile + test `shouldBe` "else\n" + - describe "alternate backend" $ do + it "Spago should run an else command if there is an error in the run file" $ do - it "Spago should use alternate backend if option is specified" $ do - configWithBackend <- readFixture "spago-configWithBackend.dhall" spago ["init"] >>= shouldBeSuccess - mv "spago.dhall" "spago-old.dhall" - writeTextFile "spago.dhall" configWithBackend + 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 (escapeSpace $ encodeString dumpFile) + ] >>= shouldBeFailure + test <- readTextFile dumpFile + test `shouldBe` "else\n" - -- Blocked by https://github.com/purescript/purescript/issues/3743 - -- spago ["-j", "5", "build"] >>= shouldBeSuccess - -- checkFixture "alternate-backend-output.txt" + it "Spago should run multiple commands in order" $ do - it "Passing `--codegen corefn` with backend option should fail" $ do - configWithBackend <- readFixture "spago-configWithBackend.dhall" spago ["init"] >>= shouldBeSuccess - mv "spago.dhall" "spago-old.dhall" - writeTextFile "spago.dhall" configWithBackend - - -- Blocked by https://github.com/purescript/purescript/issues/3743 - -- spago ["-j", "5", "build"] >>= shouldBeSuccess - -- spago ["build", "--purs-args", "--codegen", "--purs-args", "corefn"] >>= shouldBeFailureOutput "codegen-opt-with-backend.txt" - -- spago ["build", "--purs-args", "--codegen", "--purs-args", "docs"] >>= shouldBeFailureOutput "codegen-opt-with-backend.txt" - it "Spago should run a before command" $ do - - spago ["init"] >>= shouldBeSuccess - - dir <- pwd - let dumpFile = dir "testOutput" - spago ["build", "--before", "echo before>> " <> Text.pack (escapeSpace $ encodeString dumpFile)] >>= shouldBeSuccess - test <- readTextFile dumpFile - test `shouldBe` "before\n" + dir <- pwd + let dumpFile = dir "testOutput" + spago [ "build" + , "--before", "echo before1>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + , "--before", "echo before2>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + , "--then", "echo then1>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + , "--then", "echo then2>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + ] >>= shouldBeSuccess + test <- readTextFile dumpFile + test `shouldBe` "before1\nbefore2\nthen1\nthen2\n" - it "Spago should run a then command" $ do + it "Spago should fail the build if a before command fails" $ do - spago ["init"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + spago [ "build" + , "--before", "exit 1" + ] >>= shouldBeFailure - dir <- pwd - let dumpFile = dir "testOutput" - spago [ "build" - , "--then", "echo then>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) - , "--else", "echo else>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) - ] >>= shouldBeSuccess - test <- readTextFile dumpFile - test `shouldBe` "then\n" + it "Spago should fail the build if a then command fails" $ do - it "Spago should run a before command before a then command" $ do + spago ["init"] >>= shouldBeSuccess + spago [ "build" + , "--then", "exit 1" + ] >>= shouldBeFailure - spago ["init"] >>= shouldBeSuccess + it "Spago should still fail the build if an else command fails" $ do - dir <- pwd - let dumpFile = dir "testOutput" - spago [ "build" - , "--before", "echo before>> " <> Text.pack (escapeSpace $ encodeString dumpFile) - , "--then", "echo then>> " <> Text.pack (escapeSpace $ encodeString dumpFile) - ] >>= shouldBeSuccess - test <- readTextFile dumpFile - test `shouldBe` "before\nthen\n" + spago ["init"] >>= shouldBeSuccess + rm "src/Main.purs" + writeTextFile "src/Main.purs" "Invalid Purescript code" + spago [ "build" + , "--else", "exit 1" + ] >>= shouldBeFailure - it "Spago should run an else command if there is an error in the build" $ do + describe "spago test" $ do - spago ["init"] >>= shouldBeSuccess + it "Spago should test successfully" $ do - dir <- pwd - let dumpFile = dir "testOutput" - rm "src/Main.purs" - writeTextFile "src/Main.purs" "Invalid Purescript code" - spago [ "build" - , "--then", "echo then>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) - , "--else", "echo else>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) - ] >>= shouldBeFailure - test <- readTextFile dumpFile - test `shouldBe` "else\n" + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" + it "Spago should fail nicely when the test module is not found" $ do - it "Spago should run an else command if there is an error in the run file" $ do + spago ["init"] >>= shouldBeSuccess + mv "test" "test2" + spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" - spago ["init"] >>= shouldBeSuccess - spago ["install", "exceptions"] >>= shouldBeSuccess + it "Spago should test in custom output folder" $ do - 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 (escapeSpace $ encodeString dumpFile) - ] >>= shouldBeFailure - test <- readTextFile dumpFile - test `shouldBe` "else\n" + spago ["init"] >>= shouldBeSuccess + spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess + testdir "myOutput" `shouldReturn` True - it "Spago should run multiple commands in order" $ do - - spago ["init"] >>= shouldBeSuccess - - dir <- pwd - let dumpFile = dir "testOutput" - spago [ "build" - , "--before", "echo before1>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) - , "--before", "echo before2>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) - , "--then", "echo then1>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) - , "--then", "echo then2>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) - ] >>= shouldBeSuccess - test <- readTextFile dumpFile - test `shouldBe` "before1\nbefore2\nthen1\nthen2\n" - - it "Spago should fail the build if a before command fails" $ do - - spago ["init"] >>= shouldBeSuccess - spago [ "build" - , "--before", "exit 1" - ] >>= shouldBeFailure - - it "Spago should fail the build if a then command fails" $ do - - spago ["init"] >>= shouldBeSuccess - spago [ "build" - , "--then", "exit 1" - ] >>= shouldBeFailure - - it "Spago should still fail the build if an else command fails" $ do - - spago ["init"] >>= shouldBeSuccess - rm "src/Main.purs" - writeTextFile "src/Main.purs" "Invalid Purescript code" - spago [ "build" - , "--else", "exit 1" - ] >>= shouldBeFailure - - describe "spago test" $ do - - it "Spago should test successfully" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" - - it "Spago should fail nicely when the test module is not found" $ do - - spago ["init"] >>= shouldBeSuccess - mv "test" "test2" - spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" + it "Spago should test successfully with a different output folder" $ do - it "Spago should test in custom output folder" $ do + -- Create root-level packages.dhall + mkdir "monorepo" + cd "monorepo" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" - spago ["init"] >>= shouldBeSuccess - spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess - testdir "myOutput" `shouldReturn` True + -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) + mkdir "lib-a" + cd "lib-a" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["test"] >>= shouldBeSuccess + testdir "output" `shouldReturn` True + + cd ".." + testdir "output" `shouldReturn` False + + + describe "spago upgrade-set" $ do + + it "Spago should migrate package-sets from src/packages.dhall to the released one" $ do + + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packages-expected.dhall" + packages <- readTextFile "packages-expected.dhall" + let [packageSetUrl] + = map Text.strip + $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") + $ Text.lines packages + writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" + spago ["-v", "upgrade-set"] >>= shouldBeSuccess + newPackages <- Text.strip . head . Text.lines <$> readTextFile "packages.dhall" + newPackages `shouldBe` packageSetUrl + + it "Spago should migrate a package set from an alternative repository from src/packages.dhall" $ do + + spago ["init"] >>= shouldBeSuccess + writeTextFile "packages.dhall" "https://github.com/purerl/package-sets/releases/download/erl-0.13.6-20200713/packages.dhall sha256:6b1dcfe05ee95229b654462bf5d36864f9a0dfbc2ac120192aaa25f9fceb9967" + spago ["-v", "upgrade-set"] >>= shouldBeSuccess + newPackages <- Text.strip <$> readTextFile "packages.dhall" + newPackages `shouldNotBe` "https://github.com/purerl/package-sets/releases/download/erl-0.13.6-20200713/packages.dhall" + newPackages `shouldSatisfy` Text.isPrefixOf "https://github.com/purerl/package-sets/releases/download" + + it "Spago should migrate package-set from src/packages.dhall to the user-specified one if it exists" $ do + -- initialize the project, so that it uses latest package set release + spago ["init"] >>= shouldBeSuccess + + spago ["-v", "upgrade-set", "--tag", "psc-0.13.4-20191025"] >>= shouldBeSuccess + mv "packages.dhall" "packages-older-tag.dhall" + checkFixture "packages-older-tag.dhall" + + it "Spago should not migrate to the user-specified package-set if does not exist" $ do + -- initialize the project, so that it uses latest package set release + spago ["init"] >>= shouldBeSuccess + + originalPackages <- readTextFile "packages.dhall" + let [originalPackageSetUrl] + = map Text.strip + $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") + $ Text.lines originalPackages + + spago ["-v", "upgrade-set", "--tag", "does-not-exist"] >>= shouldBeSuccess + packages <- readTextFile "packages.dhall" + let [packageSetUrl] + = map Text.strip + $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") + $ Text.lines packages + + packageSetUrl `shouldBe` originalPackageSetUrl + + describe "spago run" $ do - it "Spago should test successfully with a different output folder" $ do + it "Spago should run successfully" $ do - -- Create root-level packages.dhall - mkdir "monorepo" - cd "monorepo" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess - -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) - mkdir "lib-a" - cd "lib-a" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - rm "packages.dhall" - writeTextFile "packages.dhall" $ "../packages.dhall" - spago ["test"] >>= shouldBeSuccess - testdir "output" `shouldReturn` True + shell "psa --version" empty >>= \case + ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" + ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" - cd ".." - testdir "output" `shouldReturn` False + it "Spago should be able to not use `psa`" $ do + spago ["init"] >>= shouldBeSuccess + spago ["--no-psa", "build"] >>= shouldBeSuccess + spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" - describe "spago upgrade-set" $ do + it "Spago should pass stdin to the child process" $ do - it "Spago should migrate package-sets from src/packages.dhall to the released one" $ do + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-stdin.purs" "src/Main.purs" + spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt" - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packages-expected.dhall" - packages <- readTextFile "packages-expected.dhall" - let [packageSetUrl] - = map Text.strip - $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") - $ Text.lines packages - writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" - spago ["-v", "upgrade-set"] >>= shouldBeSuccess - newPackages <- Text.strip . head . Text.lines <$> readTextFile "packages.dhall" - newPackages `shouldBe` packageSetUrl + it "Spago should use exec-args" $ do - it "Spago should migrate a package set from an alternative repository from src/packages.dhall" $ do + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" - spago ["init"] >>= shouldBeSuccess - writeTextFile "packages.dhall" "https://github.com/purerl/package-sets/releases/download/erl-0.13.6-20200713/packages.dhall sha256:6b1dcfe05ee95229b654462bf5d36864f9a0dfbc2ac120192aaa25f9fceb9967" - spago ["-v", "upgrade-set"] >>= shouldBeSuccess - newPackages <- Text.strip <$> readTextFile "packages.dhall" - newPackages `shouldNotBe` "https://github.com/purerl/package-sets/releases/download/erl-0.13.6-20200713/packages.dhall" - newPackages `shouldSatisfy` Text.isPrefixOf "https://github.com/purerl/package-sets/releases/download" + it "Spago should use node-args" $ do - it "Spago should migrate package-set from src/packages.dhall to the user-specified one if it exists" $ do - -- initialize the project, so that it uses latest package set release - spago ["init"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" + spago ["run", "--node-args", "--flagName"] >>= shouldBeSuccess - spago ["-v", "upgrade-set", "--tag", "psc-0.13.4-20191025"] >>= shouldBeSuccess - mv "packages.dhall" "packages-older-tag.dhall" - checkFixture "packages-older-tag.dhall" + it "Spago should prefer exec-args" $ do - it "Spago should not migrate to the user-specified package-set if does not exist" $ do - -- initialize the project, so that it uses latest package set release - spago ["init"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt" + + describe "spago script" $ do - originalPackages <- readTextFile "packages.dhall" - let [originalPackageSetUrl] - = map Text.strip - $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") - $ Text.lines originalPackages + -- At that time, we should add more tests checking the output of the script - spago ["-v", "upgrade-set", "--tag", "does-not-exist"] >>= shouldBeSuccess - packages <- readTextFile "packages.dhall" - let [packageSetUrl] - = map Text.strip - $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") - $ Text.lines packages + it "Spago script should create file in directory where it is executed" $ do - packageSetUrl `shouldBe` originalPackageSetUrl + spago ["script", "../fixtures/spago-script-make-file.purs", "-d", "node-fs", "-d", "node-buffer"] >>= shouldBeSuccess + checkFixture "spago-script-result.txt" - describe "spago run" $ do + describe "spago bundle" $ do - it "Spago should run successfully" $ do + it "Spago should fail but should point to the replacement command" $ do - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess + spago ["bundle", "--to", "bundle.js"] >>= shouldBeFailureStderr "bundle-stderr.txt" - shell "psa --version" empty >>= \case - ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" - ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" + let + getPursVersion = Cmd.getCmdVersion "purs" >>= either die pure + esmVersion = either (const $ die "Failed to parse purs version") pure $ Version.semver "0.15.0-alpha-02" - it "Spago should be able to not use `psa`" $ do + describe "spago bundle-app" $ do + it "Spago should bundle successfully" $ do + pursVersion :: Version.SemVer <- getPursVersion + purs0_15_0 :: Version.SemVer <- esmVersion - spago ["init"] >>= shouldBeSuccess - spago ["--no-psa", "build"] >>= shouldBeSuccess - spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" + spago ["init"] >>= shouldBeSuccess + if pursVersion >= purs0_15_0 then do + spago ["bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess + checkFixture "bundle-app-esm.js" + else do + spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess + checkFixture "bundle-app.js" - it "Spago should pass stdin to the child process" $ do + it "Spago should bundle successfully with source map" $ do + pursVersion :: Version.SemVer <- getPursVersion + purs0_15_0 :: Version.SemVer <- esmVersion - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-stdin.purs" "src/Main.purs" - spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt" + spago ["init"] >>= shouldBeSuccess + if pursVersion >= purs0_15_0 then do + spago ["bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-app-src-map-esm.js" + checkFileExist "bundle-app-src-map-esm.js.map" + else do + spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-app-src-map.js" + checkFileExist "bundle-app-src-map.js.map" - it "Spago should use exec-args" $ do + describe "spago make-module" $ do - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" + it "Spago should fail but should point to the replacement command" $ do - it "Spago should use node-args" $ do - - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" - spago ["run", "--node-args", "--flagName"] >>= shouldBeSuccess + spago ["make-module", "--to", "make-module.js"] >>= shouldBeFailureStderr "make-module-stderr.txt" - it "Spago should prefer exec-args" $ do - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt" + describe "spago bundle-module" $ do - describe "spago script" $ do + it "Spago should successfully make a module" $ do + pursVersion :: Version.SemVer <- getPursVersion + purs0_15_0 :: Version.SemVer <- esmVersion - -- At that time, we should add more tests checking the output of the script + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + -- Now we don't remove the output folder, but we pass the `--no-build` + -- flag to skip rebuilding (i.e. we are counting on the previous command + -- to have built stuff for us) + if pursVersion >= purs0_15_0 then do + spago ["bundle-module", "--to", "bundle-module-esm.js", "--no-build"] >>= shouldBeSuccess + checkFixture "bundle-module-esm.js" + else do + spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess + checkFixture "bundle-module.js" + + it "Spago should successfully make a module with source map" $ do + pursVersion :: Version.SemVer <- getPursVersion + purs0_15_0 :: Version.SemVer <- esmVersion - it "Spago script should create file in directory where it is executed" $ do + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess - spago ["script", "../fixtures/spago-script-make-file.purs", "-d", "node-fs", "-d", "node-buffer"] >>= shouldBeSuccess - checkFixture "spago-script-result.txt" + if pursVersion >= purs0_15_0 then do + spago ["bundle-module", "--to", "bundle-module-src-map-esm.js", "--no-build", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-module-src-map-esm.js" + checkFileExist "bundle-module-src-map-esm.js.map" + else do + spago ["bundle-module", "--to", "bundle-module-src-map.js", "--no-build", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-module-src-map.js" + checkFileExist "bundle-module-src-map.js.map" - describe "spago bundle" $ do + describe "spago ls packages" $ do - it "Spago should fail but should point to the replacement command" $ do + it "Spago should ls packages successfully" $ do - spago ["bundle", "--to", "bundle.js"] >>= shouldBeFailureStderr "bundle-stderr.txt" + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packages-old.dhall" + writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" + spago ["ls", "packages"] >>= shouldBeSuccessOutput "list-packages.txt" - let - getPursVersion = Cmd.getCmdVersion "purs" >>= either die pure - esmVersion = either (const $ die "Failed to parse purs version") pure $ Version.semver "0.15.0-alpha-02" + it "Spago should ls packages in JSON successfully" $ do - describe "spago bundle-app" $ do - it "Spago should bundle successfully" $ do - pursVersion :: Version.SemVer <- getPursVersion - purs0_15_0 :: Version.SemVer <- esmVersion - - spago ["init"] >>= shouldBeSuccess - if pursVersion >= purs0_15_0 then do - spago ["bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess - checkFixture "bundle-app-esm.js" - else do - spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess - checkFixture "bundle-app.js" - - it "Spago should bundle successfully with source map" $ do - pursVersion :: Version.SemVer <- getPursVersion - purs0_15_0 :: Version.SemVer <- esmVersion - - spago ["init"] >>= shouldBeSuccess - if pursVersion >= purs0_15_0 then do - spago ["bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-app-src-map-esm.js" - checkFileExist "bundle-app-src-map-esm.js.map" - else do - spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-app-src-map.js" - checkFileExist "bundle-app-src-map.js.map" + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packages-old.dhall" + writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" + spago ["ls", "packages", "--json"] >>= shouldBeSuccessOutput "list-packages.json" + + describe "spago path output" $ do + it "Spago should output the correct path" $ do + -- Create local 'monorepo-1' package that is the real root + mkdir "monorepo-1" + cd "monorepo-1" + spago ["init"] >>= shouldBeSuccess - describe "spago make-module" $ do + -- Create local 'monorepo-2' package that uses packages.dhall on top level + mkdir "monorepo-2" + cd "monorepo-2" + spago ["init"] >>= shouldBeSuccess + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["path", "output"] >>= outputShouldEqual "output\n" + pure () - it "Spago should fail but should point to the replacement command" $ do + describe "spago verify-set" $ do + it "Spago should fail when there is no spago.dhall or packages.dhall" $ do + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + rm "packages.dhall" + spago ["verify-set"] >>= shouldBeFailureStderr "verify-set-failure-no-files.txt" - spago ["make-module", "--to", "make-module.js"] >>= shouldBeFailureStderr "make-module-stderr.txt" - - - describe "spago bundle-module" $ do - - it "Spago should successfully make a module" $ do - pursVersion :: Version.SemVer <- getPursVersion - purs0_15_0 :: Version.SemVer <- esmVersion - - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - -- Now we don't remove the output folder, but we pass the `--no-build` - -- flag to skip rebuilding (i.e. we are counting on the previous command - -- to have built stuff for us) - if pursVersion >= purs0_15_0 then do - spago ["bundle-module", "--to", "bundle-module-esm.js", "--no-build"] >>= shouldBeSuccess - checkFixture "bundle-module-esm.js" - else do - spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess - checkFixture "bundle-module.js" - - it "Spago should successfully make a module with source map" $ do - pursVersion :: Version.SemVer <- getPursVersion - purs0_15_0 :: Version.SemVer <- esmVersion - - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - - if pursVersion >= purs0_15_0 then do - spago ["bundle-module", "--to", "bundle-module-src-map-esm.js", "--no-build", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-module-src-map-esm.js" - checkFileExist "bundle-module-src-map-esm.js.map" - else do - spago ["bundle-module", "--to", "bundle-module-src-map.js", "--no-build", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-module-src-map.js" - checkFileExist "bundle-module-src-map.js.map" - - describe "spago ls packages" $ do - - it "Spago should ls packages successfully" $ do - - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packages-old.dhall" - writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" - spago ["ls", "packages"] >>= shouldBeSuccessOutput "list-packages.txt" - - it "Spago should ls packages in JSON successfully" $ do - - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packages-old.dhall" - writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" - spago ["ls", "packages", "--json"] >>= shouldBeSuccessOutput "list-packages.json" - - describe "spago path output" $ do - it "Spago should output the correct path" $ do - -- Create local 'monorepo-1' package that is the real root - mkdir "monorepo-1" - cd "monorepo-1" - spago ["init"] >>= shouldBeSuccess - - -- Create local 'monorepo-2' package that uses packages.dhall on top level - mkdir "monorepo-2" - cd "monorepo-2" - spago ["init"] >>= shouldBeSuccess - rm "packages.dhall" - writeTextFile "packages.dhall" $ "../packages.dhall" - spago ["path", "output"] >>= outputShouldEqual "output\n" - pure () - - describe "spago verify-set" $ do - it "Spago should fail when there is no spago.dhall or packages.dhall" $ do - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - rm "packages.dhall" - spago ["verify-set"] >>= shouldBeFailureStderr "verify-set-failure-no-files.txt" - - it "Spago should fail when packages.dhall is malformed" $ do - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packages-old.dhall" - writeTextFile "packages.dhall" $ "abcdef" - spago ["verify-set"] >>= shouldBeFailure - - describe "global cache" $ do - it "Spago should create global cache directory if it does not exist" $ do - withEnvVar "XDG_CACHE_HOME" "./nonexisting-cache" $ - spago ["repl"] >>= shouldBeSuccess + it "Spago should fail when packages.dhall is malformed" $ do + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packages-old.dhall" + writeTextFile "packages.dhall" $ "abcdef" + spago ["verify-set"] >>= shouldBeFailure + + describe "global cache" $ do + it "Spago should create global cache directory if it does not exist" $ do + withEnvVar "XDG_CACHE_HOME" "./nonexisting-cache" $ + spago ["repl"] >>= shouldBeSuccess From ea010a5a010ebc4067d6409419c3db6f7e28297b Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 28 Mar 2022 10:36:42 -0500 Subject: [PATCH 26/82] Move around_ setup to own line --- test/SpagoSpec.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 268445427..110b41541 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -25,7 +25,8 @@ setup cmd = do withCwd (decodeString temp) cmd spec :: Spec -spec = around_ setup $ do +spec = do + around_ setup $ do describe "spago init" $ do From 918ba6b2918069d10161be7ad6d66423467b04f5 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 28 Mar 2022 10:42:40 -0500 Subject: [PATCH 27/82] Move spago run/test tests to bottom of suite --- test/SpagoSpec.hs | 185 +++++++++++++++++++++++----------------------- 1 file changed, 92 insertions(+), 93 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 110b41541..7b529da97 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -583,49 +583,6 @@ spec = do , "--else", "exit 1" ] >>= shouldBeFailure - describe "spago test" $ do - - it "Spago should test successfully" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" - - it "Spago should fail nicely when the test module is not found" $ do - - spago ["init"] >>= shouldBeSuccess - mv "test" "test2" - spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" - - it "Spago should test in custom output folder" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess - testdir "myOutput" `shouldReturn` True - - it "Spago should test successfully with a different output folder" $ do - - -- Create root-level packages.dhall - mkdir "monorepo" - cd "monorepo" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - - -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) - mkdir "lib-a" - cd "lib-a" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - rm "packages.dhall" - writeTextFile "packages.dhall" $ "../packages.dhall" - spago ["test"] >>= shouldBeSuccess - testdir "output" `shouldReturn` True - - cd ".." - testdir "output" `shouldReturn` False - - describe "spago upgrade-set" $ do it "Spago should migrate package-sets from src/packages.dhall to the released one" $ do @@ -678,56 +635,6 @@ spec = do packageSetUrl `shouldBe` originalPackageSetUrl - describe "spago run" $ do - - it "Spago should run successfully" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - - shell "psa --version" empty >>= \case - ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" - ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" - - it "Spago should be able to not use `psa`" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["--no-psa", "build"] >>= shouldBeSuccess - spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" - - it "Spago should pass stdin to the child process" $ do - - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-stdin.purs" "src/Main.purs" - spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt" - - it "Spago should use exec-args" $ do - - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" - - it "Spago should use node-args" $ do - - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" - spago ["run", "--node-args", "--flagName"] >>= shouldBeSuccess - - it "Spago should prefer exec-args" $ do - - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt" - describe "spago script" $ do -- At that time, we should add more tests checking the output of the script @@ -864,3 +771,95 @@ spec = do it "Spago should create global cache directory if it does not exist" $ do withEnvVar "XDG_CACHE_HOME" "./nonexisting-cache" $ spago ["repl"] >>= shouldBeSuccess + + describe "spago run" $ do + + it "Spago should run successfully" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + + shell "psa --version" empty >>= \case + ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" + ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" + + it "Spago should be able to not use `psa`" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["--no-psa", "build"] >>= shouldBeSuccess + spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" + + it "Spago should pass stdin to the child process" $ do + + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-stdin.purs" "src/Main.purs" + spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt" + + it "Spago should use exec-args" $ do + + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" + + it "Spago should use node-args" $ do + + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" + spago ["run", "--node-args", "--flagName"] >>= shouldBeSuccess + + it "Spago should prefer exec-args" $ do + + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt" + + describe "spago test" $ do + + it "Spago should test successfully" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" + + it "Spago should fail nicely when the test module is not found" $ do + + spago ["init"] >>= shouldBeSuccess + mv "test" "test2" + spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" + + it "Spago should test in custom output folder" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess + testdir "myOutput" `shouldReturn` True + + it "Spago should test successfully with a different output folder" $ do + + -- Create root-level packages.dhall + mkdir "monorepo" + cd "monorepo" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + + -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) + mkdir "lib-a" + cd "lib-a" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["test"] >>= shouldBeSuccess + testdir "output" `shouldReturn` True + + cd ".." + testdir "output" `shouldReturn` False From 79766363289149bad13e3f0626df111e4f09225e Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 28 Mar 2022 10:43:47 -0500 Subject: [PATCH 28/82] Run some tests with space, others without --- test/SpagoSpec.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 7b529da97..e1bf55344 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -18,15 +18,15 @@ import qualified Data.Versions as Version import qualified Spago.Cmd as Cmd -setup :: IO () -> IO () -setup cmd = do - Temp.withTempDirectory "test/" "spago-test" $ \temp -> do +setup :: String -> IO () -> IO () +setup dir cmd = do + Temp.withTempDirectory "test/" dir $ \temp -> do -- print ("Running in " <> temp) withCwd (decodeString temp) cmd spec :: Spec spec = do - around_ setup $ do + around_ (setup "spago-test") $ do describe "spago init" $ do @@ -772,6 +772,8 @@ spec = do withEnvVar "XDG_CACHE_HOME" "./nonexisting-cache" $ spago ["repl"] >>= shouldBeSuccess + around_ (setup "spago test") $ do + describe "spago run" $ do it "Spago should run successfully" $ do From 142b61930c4880e432590d765038d0d23ed98bc4 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 28 Mar 2022 11:02:41 -0500 Subject: [PATCH 29/82] Drop escapeSpace workaround --- test/SpagoSpec.hs | 26 +++++++++++++------------- test/Utils.hs | 14 +------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index e1bf55344..0048df99d 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -13,7 +13,7 @@ import Utils (checkFileHasInfix, checkFixture, checkFileE readFixture, runFor, shouldBeFailure, shouldBeFailureInfix, shouldBeFailureStderr, shouldBeSuccess, shouldBeSuccessOutput, shouldBeSuccessOutputWithErr, shouldBeSuccessStderr, spago, - withCwd, withEnvVar, escapeSpace) + withCwd, withEnvVar) import qualified Data.Versions as Version import qualified Spago.Cmd as Cmd @@ -484,7 +484,7 @@ spec = do dir <- pwd let dumpFile = dir "testOutput" - spago ["build", "--before", "echo before>> " <> Text.pack (escapeSpace $ encodeString dumpFile)] >>= shouldBeSuccess + spago ["build", "--before", "echo before>> " <> (Text.pack $ encodeString dumpFile)] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "before\n" @@ -495,8 +495,8 @@ spec = do dir <- pwd let dumpFile = dir "testOutput" spago [ "build" - , "--then", "echo then>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) - , "--else", "echo else>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + , "--then", "echo then>> " <> ( Text.pack $ encodeString dumpFile ) + , "--else", "echo else>> " <> ( Text.pack $ encodeString dumpFile ) ] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "then\n" @@ -508,8 +508,8 @@ spec = do dir <- pwd let dumpFile = dir "testOutput" spago [ "build" - , "--before", "echo before>> " <> Text.pack (escapeSpace $ encodeString dumpFile) - , "--then", "echo then>> " <> Text.pack (escapeSpace $ encodeString dumpFile) + , "--before", "echo before>> " <> Text.pack (encodeString dumpFile) + , "--then", "echo then>> " <> Text.pack (encodeString dumpFile) ] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "before\nthen\n" @@ -523,8 +523,8 @@ spec = do rm "src/Main.purs" writeTextFile "src/Main.purs" "Invalid Purescript code" spago [ "build" - , "--then", "echo then>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) - , "--else", "echo else>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + , "--then", "echo then>> " <> ( Text.pack $ encodeString dumpFile ) + , "--else", "echo else>> " <> ( Text.pack $ encodeString dumpFile ) ] >>= shouldBeFailure test <- readTextFile dumpFile test `shouldBe` "else\n" @@ -540,7 +540,7 @@ spec = do rm "src/Main.purs" writeTextFile "src/Main.purs" "module Main where\nimport Effect.Exception\nmain = throw \"error\"" spago [ "run" - , "--else", "echo else>> " <> Text.pack (escapeSpace $ encodeString dumpFile) + , "--else", "echo else>> " <> Text.pack (encodeString dumpFile) ] >>= shouldBeFailure test <- readTextFile dumpFile test `shouldBe` "else\n" @@ -552,10 +552,10 @@ spec = do dir <- pwd let dumpFile = dir "testOutput" spago [ "build" - , "--before", "echo before1>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) - , "--before", "echo before2>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) - , "--then", "echo then1>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) - , "--then", "echo then2>> " <> ( Text.pack $ escapeSpace $ encodeString dumpFile ) + , "--before", "echo before1>> " <> ( Text.pack $ encodeString dumpFile ) + , "--before", "echo before2>> " <> ( Text.pack $ encodeString dumpFile ) + , "--then", "echo then1>> " <> ( Text.pack $ encodeString dumpFile ) + , "--then", "echo then2>> " <> ( Text.pack $ encodeString dumpFile ) ] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "before1\nbefore2\nthen1\nthen2\n" diff --git a/test/Utils.hs b/test/Utils.hs index 31603fa43..1e2098f61 100644 --- a/test/Utils.hs +++ b/test/Utils.hs @@ -20,19 +20,16 @@ module Utils , shouldBeEmptySuccess , spago , withCwd - , withEnvVar - , escapeSpace) where + , withEnvVar) where import qualified Control.Concurrent as Concurrent import qualified Control.Exception as Exception import Data.Maybe (fromMaybe) -import Data.Foldable (foldl') import qualified Data.Text as Text import qualified Data.Text.Encoding as Text.Encoding import Data.Text.Encoding.Error (lenientDecode) import Prelude hiding (FilePath) import System.Directory (removePathForcibly, doesFileExist) -import qualified System.Info.Extra as SysInfoExtra import qualified System.Process as Process import Test.Hspec (HasCallStack, shouldBe, shouldSatisfy) import Turtle (ExitCode (..), FilePath, Text, cd, empty, encodeString, export, @@ -163,12 +160,3 @@ getHighestTag = do pure $ case Text.strip tag of "" -> Nothing tag' -> Just tag' - -escapeSpace :: String -> String -escapeSpace - | SysInfoExtra.isWindows = id - | otherwise = reverse . foldl' escSpace "" - where - escSpace acc x - | x == ' ' = x : '\\' : acc - | otherwise = x : acc From 754f674e30d6d537652a85a10de26e6da7b7afe5 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 29 Mar 2022 16:34:25 -0500 Subject: [PATCH 30/82] Deduplicate esm purs version checks --- test/SpagoSpec.hs | 51 ++++++----- test/Utils.hs | 4 + test/fixtures/packages-prepare-0-15.dhall | 104 ++++++++++++++++++++++ 3 files changed, 133 insertions(+), 26 deletions(-) create mode 100644 test/fixtures/packages-prepare-0-15.dhall diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 0048df99d..58819606e 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -5,7 +5,7 @@ import qualified Data.Text as Text import Prelude hiding (FilePath) import qualified System.IO.Temp as Temp import Test.Hspec (Spec, around_, describe, it, shouldBe, shouldNotSatisfy, - shouldNotBe, shouldReturn, shouldSatisfy) + shouldNotBe, shouldReturn, shouldSatisfy, runIO) import Turtle (ExitCode (..), cd, cp, decodeString, empty, encodeString, mkdir, mktree, mv, pwd, readTextFile, rm, shell, shellStrictWithErr, testdir, writeTextFile, (), die) @@ -13,7 +13,7 @@ import Utils (checkFileHasInfix, checkFixture, checkFileE readFixture, runFor, shouldBeFailure, shouldBeFailureInfix, shouldBeFailureStderr, shouldBeSuccess, shouldBeSuccessOutput, shouldBeSuccessOutputWithErr, shouldBeSuccessStderr, spago, - withCwd, withEnvVar) + withCwd, withEnvVar, dhall) import qualified Data.Versions as Version import qualified Spago.Cmd as Cmd @@ -26,6 +26,21 @@ setup dir cmd = do spec :: Spec spec = do + usingEsModules <- runIO $ do + pursVersion <- Cmd.getCmdVersion "purs" >>= either die pure + esmVersion <- either (const $ die "Failed to parse `0.15.0` static version") pure $ Version.semver "0.15.0-alpha-02" + pure $ pursVersion >= esmVersion + let + spagoInit + | usingEsModules = do + -- The prepare-0.15 package set's contents can change. + -- So, we copy an unfrozen one into the directory + -- and then freeze it before running `spago init`. + cp "../fixtures/packages-prepare-0-15.dhall" "packages.dhall" + dhall ["freeze", "packages.dhall"] >>= shouldBeSuccess + spago ["init"] + | otherwise = do + spago ["init"] around_ (setup "spago-test") $ do describe "spago init" $ do @@ -650,17 +665,10 @@ spec = do spago ["bundle", "--to", "bundle.js"] >>= shouldBeFailureStderr "bundle-stderr.txt" - let - getPursVersion = Cmd.getCmdVersion "purs" >>= either die pure - esmVersion = either (const $ die "Failed to parse purs version") pure $ Version.semver "0.15.0-alpha-02" - describe "spago bundle-app" $ do it "Spago should bundle successfully" $ do - pursVersion :: Version.SemVer <- getPursVersion - purs0_15_0 :: Version.SemVer <- esmVersion - - spago ["init"] >>= shouldBeSuccess - if pursVersion >= purs0_15_0 then do + spagoInit >>= shouldBeSuccess + if usingEsModules then do spago ["bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess checkFixture "bundle-app-esm.js" else do @@ -668,11 +676,8 @@ spec = do checkFixture "bundle-app.js" it "Spago should bundle successfully with source map" $ do - pursVersion :: Version.SemVer <- getPursVersion - purs0_15_0 :: Version.SemVer <- esmVersion - - spago ["init"] >>= shouldBeSuccess - if pursVersion >= purs0_15_0 then do + spagoInit >>= shouldBeSuccess + if usingEsModules then do spago ["bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess checkFixture "bundle-app-src-map-esm.js" checkFileExist "bundle-app-src-map-esm.js.map" @@ -691,15 +696,12 @@ spec = do describe "spago bundle-module" $ do it "Spago should successfully make a module" $ do - pursVersion :: Version.SemVer <- getPursVersion - purs0_15_0 :: Version.SemVer <- esmVersion - - spago ["init"] >>= shouldBeSuccess + spagoInit >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess -- Now we don't remove the output folder, but we pass the `--no-build` -- flag to skip rebuilding (i.e. we are counting on the previous command -- to have built stuff for us) - if pursVersion >= purs0_15_0 then do + if usingEsModules then do spago ["bundle-module", "--to", "bundle-module-esm.js", "--no-build"] >>= shouldBeSuccess checkFixture "bundle-module-esm.js" else do @@ -707,13 +709,10 @@ spec = do checkFixture "bundle-module.js" it "Spago should successfully make a module with source map" $ do - pursVersion :: Version.SemVer <- getPursVersion - purs0_15_0 :: Version.SemVer <- esmVersion - - spago ["init"] >>= shouldBeSuccess + spagoInit >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess - if pursVersion >= purs0_15_0 then do + if usingEsModules then do spago ["bundle-module", "--to", "bundle-module-src-map-esm.js", "--no-build", "--source-maps"] >>= shouldBeSuccess checkFixture "bundle-module-src-map-esm.js" checkFileExist "bundle-module-src-map-esm.js.map" diff --git a/test/Utils.hs b/test/Utils.hs index 1e2098f61..603f53709 100644 --- a/test/Utils.hs +++ b/test/Utils.hs @@ -19,6 +19,7 @@ module Utils , shouldBeFailureStderr , shouldBeEmptySuccess , spago + , dhall , withCwd , withEnvVar) where @@ -58,6 +59,9 @@ proc cmd args = do (c, out, err) <- Turtle.Bytes.procStrictWithErr cmd args empty pure (c, b2t out, b2t err) +dhall :: [Text] -> IO (ExitCode, Text, Text) +dhall = proc "dhall" + spago :: [Text] -> IO (ExitCode, Text, Text) spago = proc "spago" diff --git a/test/fixtures/packages-prepare-0-15.dhall b/test/fixtures/packages-prepare-0-15.dhall new file mode 100644 index 000000000..a1bedf12b --- /dev/null +++ b/test/fixtures/packages-prepare-0-15.dhall @@ -0,0 +1,104 @@ +{- +Welcome to your new Dhall package-set! + +Below are instructions for how to edit this file for most use +cases, so that you don't need to know Dhall to use it. + +## Use Cases + +Most will want to do one or both of these options: +1. Override/Patch a package's dependency +2. Add a package not already in the default package set + +This file will continue to work whether you use one or both options. +Instructions for each option are explained below. + +### Overriding/Patching a package + +Purpose: +- Change a package's dependency to a newer/older release than the + default package set's release +- Use your own modified version of some dependency that may + include new API, changed API, removed API by + using your custom git repo of the library rather than + the package set's repo + +Syntax: +where `entityName` is one of the following: +- dependencies +- repo +- version +------------------------------- +let upstream = -- +in upstream + with packageName.entityName = "new value" +------------------------------- + +Example: +------------------------------- +let upstream = -- +in upstream + with halogen.version = "master" + with halogen.repo = "https://example.com/path/to/git/repo.git" + + with halogen-vdom.version = "v4.0.0" + with halogen-vdom.dependencies = [ "extra-dependency" ] # halogen-vdom.dependencies +------------------------------- + +### Additions + +Purpose: +- Add packages that aren't already included in the default package set + +Syntax: +where `` is: +- a tag (i.e. "v4.0.0") +- a branch (i.e. "master") +- commit hash (i.e. "701f3e44aafb1a6459281714858fadf2c4c2a977") +------------------------------- +let upstream = -- +in upstream + with new-package-name = + { dependencies = + [ "dependency1" + , "dependency2" + ] + , repo = + "https://example.com/path/to/git/repo.git" + , version = + "" + } +------------------------------- + +Example: +------------------------------- +let upstream = -- +in upstream + with benchotron = + { dependencies = + [ "arrays" + , "exists" + , "profunctor" + , "strings" + , "quickcheck" + , "lcg" + , "transformers" + , "foldable-traversable" + , "exceptions" + , "node-fs" + , "node-buffer" + , "node-readline" + , "datetime" + , "now" + ] + , repo = + "https://github.com/hdgarrood/purescript-benchotron.git" + , version = + "v7.0.0" + } +------------------------------- +-} +let upstream = + https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall + +in upstream \ No newline at end of file From 2da31531c08bd6e70616739d8620ed1e1c8d82ea Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 29 Mar 2022 16:36:45 -0500 Subject: [PATCH 31/82] Move bundle tests to bottom of spec --- test/SpagoSpec.hs | 98 +++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 50 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 58819606e..3d438f889 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -665,62 +665,12 @@ spec = do spago ["bundle", "--to", "bundle.js"] >>= shouldBeFailureStderr "bundle-stderr.txt" - describe "spago bundle-app" $ do - it "Spago should bundle successfully" $ do - spagoInit >>= shouldBeSuccess - if usingEsModules then do - spago ["bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess - checkFixture "bundle-app-esm.js" - else do - spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess - checkFixture "bundle-app.js" - - it "Spago should bundle successfully with source map" $ do - spagoInit >>= shouldBeSuccess - if usingEsModules then do - spago ["bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-app-src-map-esm.js" - checkFileExist "bundle-app-src-map-esm.js.map" - else do - spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-app-src-map.js" - checkFileExist "bundle-app-src-map.js.map" - describe "spago make-module" $ do it "Spago should fail but should point to the replacement command" $ do spago ["make-module", "--to", "make-module.js"] >>= shouldBeFailureStderr "make-module-stderr.txt" - - describe "spago bundle-module" $ do - - it "Spago should successfully make a module" $ do - spagoInit >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - -- Now we don't remove the output folder, but we pass the `--no-build` - -- flag to skip rebuilding (i.e. we are counting on the previous command - -- to have built stuff for us) - if usingEsModules then do - spago ["bundle-module", "--to", "bundle-module-esm.js", "--no-build"] >>= shouldBeSuccess - checkFixture "bundle-module-esm.js" - else do - spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess - checkFixture "bundle-module.js" - - it "Spago should successfully make a module with source map" $ do - spagoInit >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - - if usingEsModules then do - spago ["bundle-module", "--to", "bundle-module-src-map-esm.js", "--no-build", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-module-src-map-esm.js" - checkFileExist "bundle-module-src-map-esm.js.map" - else do - spago ["bundle-module", "--to", "bundle-module-src-map.js", "--no-build", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-module-src-map.js" - checkFileExist "bundle-module-src-map.js.map" - describe "spago ls packages" $ do it "Spago should ls packages successfully" $ do @@ -771,6 +721,54 @@ spec = do withEnvVar "XDG_CACHE_HOME" "./nonexisting-cache" $ spago ["repl"] >>= shouldBeSuccess + describe "spago bundle-app" $ do + it "Spago should bundle successfully" $ do + spagoInit >>= shouldBeSuccess + if usingEsModules then do + spago ["bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess + checkFixture "bundle-app-esm.js" + else do + spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess + checkFixture "bundle-app.js" + + it "Spago should bundle successfully with source map" $ do + spagoInit >>= shouldBeSuccess + if usingEsModules then do + spago ["bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-app-src-map-esm.js" + checkFileExist "bundle-app-src-map-esm.js.map" + else do + spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-app-src-map.js" + checkFileExist "bundle-app-src-map.js.map" + + describe "spago bundle-module" $ do + it "Spago should successfully make a module" $ do + spagoInit >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + -- Now we don't remove the output folder, but we pass the `--no-build` + -- flag to skip rebuilding (i.e. we are counting on the previous command + -- to have built stuff for us) + if usingEsModules then do + spago ["bundle-module", "--to", "bundle-module-esm.js", "--no-build"] >>= shouldBeSuccess + checkFixture "bundle-module-esm.js" + else do + spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess + checkFixture "bundle-module.js" + + it "Spago should successfully make a module with source map" $ do + spagoInit >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + + if usingEsModules then do + spago ["bundle-module", "--to", "bundle-module-src-map-esm.js", "--no-build", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-module-src-map-esm.js" + checkFileExist "bundle-module-src-map-esm.js.map" + else do + spago ["bundle-module", "--to", "bundle-module-src-map.js", "--no-build", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-module-src-map.js" + checkFileExist "bundle-module-src-map.js.map" + around_ (setup "spago test") $ do describe "spago run" $ do From 06ad139a4038e80eea61167db4cbcdea6d345a73 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 29 Mar 2022 16:44:31 -0500 Subject: [PATCH 32/82] Group bundle-app/module, run, test tests by purs-0.15 --- test/SpagoSpec.hs | 232 +++++++++++++++++++++++----------------------- 1 file changed, 118 insertions(+), 114 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 3d438f889..fc4ed0c25 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -31,6 +31,7 @@ spec = do esmVersion <- either (const $ die "Failed to parse `0.15.0` static version") pure $ Version.semver "0.15.0-alpha-02" pure $ pursVersion >= esmVersion let + purs0_15_0TestMsg = "purs-0.15" spagoInit | usingEsModules = do -- The prepare-0.15 package set's contents can change. @@ -721,144 +722,147 @@ spec = do withEnvVar "XDG_CACHE_HOME" "./nonexisting-cache" $ spago ["repl"] >>= shouldBeSuccess - describe "spago bundle-app" $ do - it "Spago should bundle successfully" $ do - spagoInit >>= shouldBeSuccess - if usingEsModules then do - spago ["bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess - checkFixture "bundle-app-esm.js" - else do - spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess - checkFixture "bundle-app.js" - - it "Spago should bundle successfully with source map" $ do - spagoInit >>= shouldBeSuccess - if usingEsModules then do - spago ["bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-app-src-map-esm.js" - checkFileExist "bundle-app-src-map-esm.js.map" - else do - spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-app-src-map.js" - checkFileExist "bundle-app-src-map.js.map" - - describe "spago bundle-module" $ do - it "Spago should successfully make a module" $ do - spagoInit >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - -- Now we don't remove the output folder, but we pass the `--no-build` - -- flag to skip rebuilding (i.e. we are counting on the previous command - -- to have built stuff for us) - if usingEsModules then do - spago ["bundle-module", "--to", "bundle-module-esm.js", "--no-build"] >>= shouldBeSuccess - checkFixture "bundle-module-esm.js" - else do - spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess - checkFixture "bundle-module.js" - - it "Spago should successfully make a module with source map" $ do - spagoInit >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - - if usingEsModules then do - spago ["bundle-module", "--to", "bundle-module-src-map-esm.js", "--no-build", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-module-src-map-esm.js" - checkFileExist "bundle-module-src-map-esm.js.map" - else do - spago ["bundle-module", "--to", "bundle-module-src-map.js", "--no-build", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-module-src-map.js" - checkFileExist "bundle-module-src-map.js.map" + describe purs0_15_0TestMsg $ do + describe "spago bundle-app" $ do + it "Spago should bundle successfully" $ do + spagoInit >>= shouldBeSuccess + if usingEsModules then do + spago ["bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess + checkFixture "bundle-app-esm.js" + else do + spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess + checkFixture "bundle-app.js" + + it "Spago should bundle successfully with source map" $ do + spagoInit >>= shouldBeSuccess + if usingEsModules then do + spago ["bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-app-src-map-esm.js" + checkFileExist "bundle-app-src-map-esm.js.map" + else do + spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-app-src-map.js" + checkFileExist "bundle-app-src-map.js.map" + + describe "spago bundle-module" $ do + it "Spago should successfully make a module" $ do + spagoInit >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + -- Now we don't remove the output folder, but we pass the `--no-build` + -- flag to skip rebuilding (i.e. we are counting on the previous command + -- to have built stuff for us) + if usingEsModules then do + spago ["bundle-module", "--to", "bundle-module-esm.js", "--no-build"] >>= shouldBeSuccess + checkFixture "bundle-module-esm.js" + else do + spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess + checkFixture "bundle-module.js" + + it "Spago should successfully make a module with source map" $ do + spagoInit >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + + if usingEsModules then do + spago ["bundle-module", "--to", "bundle-module-src-map-esm.js", "--no-build", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-module-src-map-esm.js" + checkFileExist "bundle-module-src-map-esm.js.map" + else do + spago ["bundle-module", "--to", "bundle-module-src-map.js", "--no-build", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-module-src-map.js" + checkFileExist "bundle-module-src-map.js.map" around_ (setup "spago test") $ do - describe "spago run" $ do + describe purs0_15_0TestMsg $ do - it "Spago should run successfully" $ do + describe "spago run" $ do - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess + it "Spago should run successfully" $ do - shell "psa --version" empty >>= \case - ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" - ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess - it "Spago should be able to not use `psa`" $ do + shell "psa --version" empty >>= \case + ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" + ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" - spago ["init"] >>= shouldBeSuccess - spago ["--no-psa", "build"] >>= shouldBeSuccess - spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" + it "Spago should be able to not use `psa`" $ do - it "Spago should pass stdin to the child process" $ do + spago ["init"] >>= shouldBeSuccess + spago ["--no-psa", "build"] >>= shouldBeSuccess + spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-stdin.purs" "src/Main.purs" - spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt" + it "Spago should pass stdin to the child process" $ do - it "Spago should use exec-args" $ do + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-stdin.purs" "src/Main.purs" + spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt" - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" + it "Spago should use exec-args" $ do - it "Spago should use node-args" $ do + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" - spago ["run", "--node-args", "--flagName"] >>= shouldBeSuccess + it "Spago should use node-args" $ do - it "Spago should prefer exec-args" $ do + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" + spago ["run", "--node-args", "--flagName"] >>= shouldBeSuccess - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt" + it "Spago should prefer exec-args" $ do - describe "spago test" $ do + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt" - it "Spago should test successfully" $ do + describe "spago test" $ do - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" + it "Spago should test successfully" $ do - it "Spago should fail nicely when the test module is not found" $ do + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" - spago ["init"] >>= shouldBeSuccess - mv "test" "test2" - spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" + it "Spago should fail nicely when the test module is not found" $ do - it "Spago should test in custom output folder" $ do + spago ["init"] >>= shouldBeSuccess + mv "test" "test2" + spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" - spago ["init"] >>= shouldBeSuccess - spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess - testdir "myOutput" `shouldReturn` True + it "Spago should test in custom output folder" $ do - it "Spago should test successfully with a different output folder" $ do + spago ["init"] >>= shouldBeSuccess + spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess + testdir "myOutput" `shouldReturn` True - -- Create root-level packages.dhall - mkdir "monorepo" - cd "monorepo" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" + it "Spago should test successfully with a different output folder" $ do - -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) - mkdir "lib-a" - cd "lib-a" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - rm "packages.dhall" - writeTextFile "packages.dhall" $ "../packages.dhall" - spago ["test"] >>= shouldBeSuccess - testdir "output" `shouldReturn` True + -- Create root-level packages.dhall + mkdir "monorepo" + cd "monorepo" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" - cd ".." - testdir "output" `shouldReturn` False + -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) + mkdir "lib-a" + cd "lib-a" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["test"] >>= shouldBeSuccess + testdir "output" `shouldReturn` True + + cd ".." + testdir "output" `shouldReturn` False From 4f35278d23d809127d0b53c278cb49f48173bb01 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 29 Mar 2022 17:12:09 -0500 Subject: [PATCH 33/82] Use temporary fork of package sets for prepare-0.15 --- test/fixtures/packages-prepare-0-15.dhall | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/packages-prepare-0-15.dhall b/test/fixtures/packages-prepare-0-15.dhall index a1bedf12b..4963b0ada 100644 --- a/test/fixtures/packages-prepare-0-15.dhall +++ b/test/fixtures/packages-prepare-0-15.dhall @@ -99,6 +99,6 @@ in upstream ------------------------------- -} let upstream = - https://raw.githubusercontent.com/purescript/package-sets/prepare-0.15/src/packages.dhall + https://github.com/JordanMartinez/package-sets/releases/download/psc-0.15.0-20220329/packages.dhall in upstream \ No newline at end of file From 90df061684599a0ebbe087dd1e5b3304aca83569 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 29 Mar 2022 17:12:39 -0500 Subject: [PATCH 34/82] Run purs-0.15 tests on purs 0.15 Installation approach follows that used in `pulp`'s CI --- .github/workflows/build.yml | 40 ++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7297c35db..51f9f9103 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,6 +8,7 @@ on: env: STACK_VERSION: '2.7.3' + PS_0_15_0_VERSION: '0.15.0-alpha-02' jobs: build: @@ -112,6 +113,43 @@ jobs: run: ./scripts/fix-home stack install shell: bash - - name: Run tests + - name: Run tests (PureScript < 0.15.0) run: ./scripts/fix-home stack test shell: bash + + - name: non-Windows - Download PureScript 0.15.0 + if: runner.os != 'Windows' + shell: bash + run: | + DIR="$HOME/bin/purescript-$PS_0_15_0_VERSION" + mkdir -p "$DIR" + wget -O "$DIR/purescript.tar.gz" "https://github.com/purescript/purescript/releases/download/$PS_0_15_0_VERSION/linux64.tar.gz" + tar -xvf "$DIR/purescript.tar.gz" -C "$DIR" --strip-components 1 purescript/purs + chmod a+x "$DIR/purs" + + - name: non-Windows - Run tests (PureScript >= 0.15.0) + if: runner.os != 'Windows' + shell: bash + run: | + PATH="$HOME/bin/purescript-$PS_0_15_0_VERSION:$PATH" + purs --version + ./scripts/fix-home stack test --ta "match purs-0.15" + + - name: Windows - Download PureScript 0.15.0 + if: runner.os == 'Windows' + shell: bash + run: | + pushd C:\\tools + DIR="$HOME/bin/$PS_0_15_0_VERSION" + mkdir -p "$DIR" + curl -opurescript.tar.gz -L "https://github.com/purescript/purescript/releases/download/$PS_0_15_0_VERSION/win64.tar.gz" + tar -xvzf purescript.tar.gz -C "$DIR" --strip-components 1 purescript/purs.exe + popd + + - name: Windows - Run tests (PureScript >= 0.15.0) + if: runner.os == 'Windows' + shell: bash + run: | + $env:Path="C:\tools\purescript-$env:PS_0_15_0_VERSION;$env:Path" + purs.exe --version + ./scripts/fix-home stack test --ta "match purs-0.15" From 3f23d39794f6be34b5a31d20e031d193f5bf2b5a Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 29 Mar 2022 17:23:08 -0500 Subject: [PATCH 35/82] Try download using curl --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 51f9f9103..72bc73b41 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -123,7 +123,7 @@ jobs: run: | DIR="$HOME/bin/purescript-$PS_0_15_0_VERSION" mkdir -p "$DIR" - wget -O "$DIR/purescript.tar.gz" "https://github.com/purescript/purescript/releases/download/$PS_0_15_0_VERSION/linux64.tar.gz" + curl -o "$DIR/purescript.tar.gz" -L "https://github.com/purescript/purescript/releases/download/$PS_0_15_0_VERSION/linux64.tar.gz" tar -xvf "$DIR/purescript.tar.gz" -C "$DIR" --strip-components 1 purescript/purs chmod a+x "$DIR/purs" From 5e346310e603b5eb9a73c517bf5bf94a8a6bb068 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 29 Mar 2022 23:05:37 -0500 Subject: [PATCH 36/82] Run all builds to end --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 72bc73b41..422cb2a0c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,6 +15,7 @@ jobs: runs-on: ${{ matrix.os }} container: ${{ matrix.image }} strategy: + fail-fast: false matrix: include: - os: ubuntu-latest From f9e63e01b454f463d2a6dfdb5e8892767672d8b8 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 30 Mar 2022 01:30:28 -0500 Subject: [PATCH 37/82] Fix tag name: add v prefix --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 422cb2a0c..72e0a763b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ on: env: STACK_VERSION: '2.7.3' - PS_0_15_0_VERSION: '0.15.0-alpha-02' + PS_0_15_0_VERSION: 'v0.15.0-alpha-02' jobs: build: From a13e8f23764094413bbbb4ee32cbd73356379ce8 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Fri, 1 Apr 2022 16:02:48 -0500 Subject: [PATCH 38/82] Use alpha-03 release --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 72e0a763b..1f43aeba0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ on: env: STACK_VERSION: '2.7.3' - PS_0_15_0_VERSION: 'v0.15.0-alpha-02' + PS_0_15_0_VERSION: 'v0.15.0-alpha-03' jobs: build: From 2e794699367057e74b6997751285b3e7fab561ec Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Fri, 1 Apr 2022 16:48:27 -0500 Subject: [PATCH 39/82] Make *nix and Windows 0.15.0 test setup similar --- .github/workflows/build.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1f43aeba0..396987143 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -140,17 +140,15 @@ jobs: if: runner.os == 'Windows' shell: bash run: | - pushd C:\\tools - DIR="$HOME/bin/$PS_0_15_0_VERSION" + DIR="$HOME/bin/purescript-$PS_0_15_0_VERSION" mkdir -p "$DIR" curl -opurescript.tar.gz -L "https://github.com/purescript/purescript/releases/download/$PS_0_15_0_VERSION/win64.tar.gz" tar -xvzf purescript.tar.gz -C "$DIR" --strip-components 1 purescript/purs.exe - popd + chmod a+x "$DIR/purs.exe" - name: Windows - Run tests (PureScript >= 0.15.0) if: runner.os == 'Windows' shell: bash run: | - $env:Path="C:\tools\purescript-$env:PS_0_15_0_VERSION;$env:Path" - purs.exe --version + PATH="$HOME/bin/purescript-$PS_0_15_0_VERSION:$PATH" ./scripts/fix-home stack test --ta "match purs-0.15" From 83d306d6183e5edcfcba562e5a0d836176904015 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Fri, 1 Apr 2022 21:04:27 -0500 Subject: [PATCH 40/82] Bump to alpha-04 release --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 396987143..cc9e31cc4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ on: env: STACK_VERSION: '2.7.3' - PS_0_15_0_VERSION: 'v0.15.0-alpha-03' + PS_0_15_0_VERSION: 'v0.15.0-alpha-04' jobs: build: From 8c2ab7b8c827cb6a74f7f21d5c4cb315226e12bd Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 08:50:29 -0500 Subject: [PATCH 41/82] Prefix match option with '--' --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cc9e31cc4..bdd83c9c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -134,7 +134,7 @@ jobs: run: | PATH="$HOME/bin/purescript-$PS_0_15_0_VERSION:$PATH" purs --version - ./scripts/fix-home stack test --ta "match purs-0.15" + ./scripts/fix-home stack test --ta "--match purs-0.15" - name: Windows - Download PureScript 0.15.0 if: runner.os == 'Windows' @@ -151,4 +151,4 @@ jobs: shell: bash run: | PATH="$HOME/bin/purescript-$PS_0_15_0_VERSION:$PATH" - ./scripts/fix-home stack test --ta "match purs-0.15" + ./scripts/fix-home stack test --ta "--match purs-0.15" From 0f8a49f32740d474b3df281b2135fccae3d0f51f Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 09:40:51 -0500 Subject: [PATCH 42/82] Use spagoInit in run/test tests --- test/SpagoSpec.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index fc4ed0c25..9ee9d6e01 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -779,7 +779,7 @@ spec = do it "Spago should run successfully" $ do - spago ["init"] >>= shouldBeSuccess + spagoInit >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess shell "psa --version" empty >>= \case @@ -788,13 +788,13 @@ spec = do it "Spago should be able to not use `psa`" $ do - spago ["init"] >>= shouldBeSuccess + spagoInit >>= shouldBeSuccess spago ["--no-psa", "build"] >>= shouldBeSuccess spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" it "Spago should pass stdin to the child process" $ do - spago ["init"] >>= shouldBeSuccess + spagoInit >>= shouldBeSuccess cp "../fixtures/spago-run-stdin.purs" "src/Main.purs" spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess @@ -802,7 +802,7 @@ spec = do it "Spago should use exec-args" $ do - spago ["init"] >>= shouldBeSuccess + spagoInit >>= shouldBeSuccess cp "../fixtures/spago-run-args.purs" "src/Main.purs" spago ["install", "node-process", "arrays"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess @@ -810,7 +810,7 @@ spec = do it "Spago should use node-args" $ do - spago ["init"] >>= shouldBeSuccess + spagoInit >>= shouldBeSuccess cp "../fixtures/spago-run-args.purs" "src/Main.purs" spago ["install", "node-process", "arrays"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess @@ -819,7 +819,7 @@ spec = do it "Spago should prefer exec-args" $ do - spago ["init"] >>= shouldBeSuccess + spagoInit >>= shouldBeSuccess cp "../fixtures/spago-run-args.purs" "src/Main.purs" spago ["install", "node-process", "arrays"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess @@ -829,19 +829,19 @@ spec = do it "Spago should test successfully" $ do - spago ["init"] >>= shouldBeSuccess + spagoInit >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" it "Spago should fail nicely when the test module is not found" $ do - spago ["init"] >>= shouldBeSuccess + spagoInit >>= shouldBeSuccess mv "test" "test2" spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" it "Spago should test in custom output folder" $ do - spago ["init"] >>= shouldBeSuccess + spagoInit >>= shouldBeSuccess spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess testdir "myOutput" `shouldReturn` True From 6e233834aec530107faac7e6499f10771349c59d Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 09:47:07 -0500 Subject: [PATCH 43/82] Update packages.dhall for last test --- test/SpagoSpec.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 9ee9d6e01..1ed3f278a 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -8,7 +8,7 @@ import Test.Hspec (Spec, around_, describe, it, shouldBe, shou shouldNotBe, shouldReturn, shouldSatisfy, runIO) import Turtle (ExitCode (..), cd, cp, decodeString, empty, encodeString, mkdir, mktree, mv, pwd, readTextFile, rm, shell, - shellStrictWithErr, testdir, writeTextFile, (), die) + shellStrictWithErr, testdir, writeTextFile, (), die, when, void) import Utils (checkFileHasInfix, checkFixture, checkFileExist, outputShouldEqual, readFixture, runFor, shouldBeFailure, shouldBeFailureInfix, shouldBeFailureStderr, shouldBeSuccess, shouldBeSuccessOutput, @@ -850,12 +850,18 @@ spec = do -- Create root-level packages.dhall mkdir "monorepo" cd "monorepo" + when usingEsModules $ do + cp "../../fixtures/packages-prepare-0-15.dhall" "packages.dhall" + void $ dhall ["freeze", "packages.dhall"] spago ["init"] >>= shouldBeSuccess rm "spago.dhall" -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) mkdir "lib-a" cd "lib-a" + when usingEsModules $ do + cp "../../../fixtures/packages-prepare-0-15.dhall" "packages.dhall" + void $ dhall ["freeze", "packages.dhall"] spago ["init"] >>= shouldBeSuccess rm "spago.dhall" writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" From 42981ab9875509f3c0281b8a3de173514219b2aa Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 09:50:48 -0500 Subject: [PATCH 44/82] Make it easier to drop packages.dhall fix --- test/SpagoSpec.hs | 56 ++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 1ed3f278a..6551c5e17 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -32,16 +32,13 @@ spec = do pure $ pursVersion >= esmVersion let purs0_15_0TestMsg = "purs-0.15" - spagoInit - | usingEsModules = do - -- The prepare-0.15 package set's contents can change. - -- So, we copy an unfrozen one into the directory - -- and then freeze it before running `spago init`. - cp "../fixtures/packages-prepare-0-15.dhall" "packages.dhall" - dhall ["freeze", "packages.dhall"] >>= shouldBeSuccess - spago ["init"] - | otherwise = do - spago ["init"] + whenUsingEsModulesFixPackagesDhall = when usingEsModules $ do + -- The prepare-0.15 package set's contents can change. + -- So, we copy an unfrozen one into the directory + -- and then freeze it before running `spago init`. + cp "../fixtures/packages-prepare-0-15.dhall" "packages.dhall" + dhall ["freeze", "packages.dhall"] >>= shouldBeSuccess + around_ (setup "spago-test") $ do describe "spago init" $ do @@ -725,7 +722,8 @@ spec = do describe purs0_15_0TestMsg $ do describe "spago bundle-app" $ do it "Spago should bundle successfully" $ do - spagoInit >>= shouldBeSuccess + whenUsingEsModulesFixPackagesDhall + spago ["init"] >>= shouldBeSuccess if usingEsModules then do spago ["bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess checkFixture "bundle-app-esm.js" @@ -734,7 +732,8 @@ spec = do checkFixture "bundle-app.js" it "Spago should bundle successfully with source map" $ do - spagoInit >>= shouldBeSuccess + whenUsingEsModulesFixPackagesDhall + spago ["init"] >>= shouldBeSuccess if usingEsModules then do spago ["bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess checkFixture "bundle-app-src-map-esm.js" @@ -746,7 +745,8 @@ spec = do describe "spago bundle-module" $ do it "Spago should successfully make a module" $ do - spagoInit >>= shouldBeSuccess + whenUsingEsModulesFixPackagesDhall + spago ["init"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess -- Now we don't remove the output folder, but we pass the `--no-build` -- flag to skip rebuilding (i.e. we are counting on the previous command @@ -759,7 +759,8 @@ spec = do checkFixture "bundle-module.js" it "Spago should successfully make a module with source map" $ do - spagoInit >>= shouldBeSuccess + whenUsingEsModulesFixPackagesDhall + spago ["init"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess if usingEsModules then do @@ -779,7 +780,8 @@ spec = do it "Spago should run successfully" $ do - spagoInit >>= shouldBeSuccess + whenUsingEsModulesFixPackagesDhall + spago ["init"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess shell "psa --version" empty >>= \case @@ -788,13 +790,15 @@ spec = do it "Spago should be able to not use `psa`" $ do - spagoInit >>= shouldBeSuccess + whenUsingEsModulesFixPackagesDhall + spago ["init"] >>= shouldBeSuccess spago ["--no-psa", "build"] >>= shouldBeSuccess spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" it "Spago should pass stdin to the child process" $ do - spagoInit >>= shouldBeSuccess + whenUsingEsModulesFixPackagesDhall + spago ["init"] >>= shouldBeSuccess cp "../fixtures/spago-run-stdin.purs" "src/Main.purs" spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess @@ -802,7 +806,8 @@ spec = do it "Spago should use exec-args" $ do - spagoInit >>= shouldBeSuccess + whenUsingEsModulesFixPackagesDhall + spago ["init"] >>= shouldBeSuccess cp "../fixtures/spago-run-args.purs" "src/Main.purs" spago ["install", "node-process", "arrays"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess @@ -810,7 +815,8 @@ spec = do it "Spago should use node-args" $ do - spagoInit >>= shouldBeSuccess + whenUsingEsModulesFixPackagesDhall + spago ["init"] >>= shouldBeSuccess cp "../fixtures/spago-run-args.purs" "src/Main.purs" spago ["install", "node-process", "arrays"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess @@ -819,7 +825,8 @@ spec = do it "Spago should prefer exec-args" $ do - spagoInit >>= shouldBeSuccess + whenUsingEsModulesFixPackagesDhall + spago ["init"] >>= shouldBeSuccess cp "../fixtures/spago-run-args.purs" "src/Main.purs" spago ["install", "node-process", "arrays"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess @@ -829,19 +836,22 @@ spec = do it "Spago should test successfully" $ do - spagoInit >>= shouldBeSuccess + whenUsingEsModulesFixPackagesDhall + spago ["init"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" it "Spago should fail nicely when the test module is not found" $ do - spagoInit >>= shouldBeSuccess + whenUsingEsModulesFixPackagesDhall + spago ["init"] >>= shouldBeSuccess mv "test" "test2" spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" it "Spago should test in custom output folder" $ do - spagoInit >>= shouldBeSuccess + whenUsingEsModulesFixPackagesDhall + spago ["init"] >>= shouldBeSuccess spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess testdir "myOutput" `shouldReturn` True From 397c11e499ac824216351799e00ee62985090cf7 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 10:00:04 -0500 Subject: [PATCH 45/82] Update expected ESM files --- test/fixtures/bundle-app-esm.js | 2 +- test/fixtures/bundle-app-src-map-esm.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fixtures/bundle-app-esm.js b/test/fixtures/bundle-app-esm.js index 54a5c7b6f..fef3eca9a 100644 --- a/test/fixtures/bundle-app-esm.js +++ b/test/fixtures/bundle-app-esm.js @@ -9,6 +9,6 @@ // output/Main/index.js var main = /* @__PURE__ */ log("\u{1F35D}"); - // index.js + // main(); })(); diff --git a/test/fixtures/bundle-app-src-map-esm.js b/test/fixtures/bundle-app-src-map-esm.js index 663b8f14c..b167ded57 100644 --- a/test/fixtures/bundle-app-src-map-esm.js +++ b/test/fixtures/bundle-app-src-map-esm.js @@ -9,7 +9,7 @@ // output/Main/index.js var main = /* @__PURE__ */ log("\u{1F35D}"); - // index.js + // main(); })(); //# sourceMappingURL=bundle-app-src-map-esm.js.map From ef84d2ba0c1c0e587ddc7efc6b96ad737eaf08f5 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 10:33:25 -0500 Subject: [PATCH 46/82] Use 'file://' to fix Windows issue --- src/Spago/Build.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 23b117a36..bcd3f9656 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -356,7 +356,7 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe nodeArgs = Text.intercalate " " $ map unBackendArg extraArgs esContents outputPath' = fold - [ "import { main } from '" + [ "import { main } from 'file://" , Text.replace "\\" "/" (fromFilePath sourceDir) , "/" , Text.pack outputPath' From ac8ec3cb12d1452cd5f937e9181d13d370ba89ec Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 10:37:40 -0500 Subject: [PATCH 47/82] Stop calling `purs --version` --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bdd83c9c6..bdd49c1de 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -133,7 +133,6 @@ jobs: shell: bash run: | PATH="$HOME/bin/purescript-$PS_0_15_0_VERSION:$PATH" - purs --version ./scripts/fix-home stack test --ta "--match purs-0.15" - name: Windows - Download PureScript 0.15.0 From 5da2a6cdac4eb7132bc5b98973b17e2a3e7781d0 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 10:37:59 -0500 Subject: [PATCH 48/82] Use same script for running test --- .github/workflows/build.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bdd49c1de..94a6c3f3e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -128,13 +128,6 @@ jobs: tar -xvf "$DIR/purescript.tar.gz" -C "$DIR" --strip-components 1 purescript/purs chmod a+x "$DIR/purs" - - name: non-Windows - Run tests (PureScript >= 0.15.0) - if: runner.os != 'Windows' - shell: bash - run: | - PATH="$HOME/bin/purescript-$PS_0_15_0_VERSION:$PATH" - ./scripts/fix-home stack test --ta "--match purs-0.15" - - name: Windows - Download PureScript 0.15.0 if: runner.os == 'Windows' shell: bash @@ -145,8 +138,7 @@ jobs: tar -xvzf purescript.tar.gz -C "$DIR" --strip-components 1 purescript/purs.exe chmod a+x "$DIR/purs.exe" - - name: Windows - Run tests (PureScript >= 0.15.0) - if: runner.os == 'Windows' + - name: Run tests (PureScript >= 0.15.0) shell: bash run: | PATH="$HOME/bin/purescript-$PS_0_15_0_VERSION:$PATH" From ba00594fa4f289ad31ee5c2c009946c140719e09 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 10:53:27 -0500 Subject: [PATCH 49/82] Only run purs-0.15 tests --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 94a6c3f3e..94a64d6b9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -114,9 +114,9 @@ jobs: run: ./scripts/fix-home stack install shell: bash - - name: Run tests (PureScript < 0.15.0) - run: ./scripts/fix-home stack test - shell: bash + # - name: Run tests (PureScript < 0.15.0) + # run: ./scripts/fix-home stack test + # shell: bash - name: non-Windows - Download PureScript 0.15.0 if: runner.os != 'Windows' From ca8f4ee596ffcc76eb6fcb252d8a73a489e25cf2 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 11:06:55 -0500 Subject: [PATCH 50/82] Download macos file for Mac, not linux file --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 94a64d6b9..5340d5599 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,7 +20,9 @@ jobs: include: - os: ubuntu-latest image: haskell:8.10.7-stretch@sha256:100f8fb7d7d8d64adb5e106fe8136b8d4cbdc03aeb2cbd145a7597d74b69bafb + purs_0_15_file: linux64 - os: macOS-latest + purs_0_15_file: macos - os: windows-latest steps: # We need a proper Git repository, but the checkout step will unpack a tarball instead of doing a clone @@ -121,10 +123,12 @@ jobs: - name: non-Windows - Download PureScript 0.15.0 if: runner.os != 'Windows' shell: bash + env: + FILE: ${{ matrix.purs_0_15_file }} run: | DIR="$HOME/bin/purescript-$PS_0_15_0_VERSION" mkdir -p "$DIR" - curl -o "$DIR/purescript.tar.gz" -L "https://github.com/purescript/purescript/releases/download/$PS_0_15_0_VERSION/linux64.tar.gz" + curl -o "$DIR/purescript.tar.gz" -L "https://github.com/purescript/purescript/releases/download/$PS_0_15_0_VERSION/$FILE.tar.gz" tar -xvf "$DIR/purescript.tar.gz" -C "$DIR" --strip-components 1 purescript/purs chmod a+x "$DIR/purs" From 13252403030aaac73319965182475462dc431ed8 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 11:17:42 -0500 Subject: [PATCH 51/82] Output contents of dir after bundle-app --- test/SpagoSpec.hs | 6 +++++- test/Utils.hs | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 6551c5e17..a7e47ed8f 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -13,7 +13,7 @@ import Utils (checkFileHasInfix, checkFixture, checkFileE readFixture, runFor, shouldBeFailure, shouldBeFailureInfix, shouldBeFailureStderr, shouldBeSuccess, shouldBeSuccessOutput, shouldBeSuccessOutputWithErr, shouldBeSuccessStderr, spago, - withCwd, withEnvVar, dhall) + withCwd, withEnvVar, dhall, ls, cat) import qualified Data.Versions as Version import qualified Spago.Cmd as Cmd @@ -726,6 +726,8 @@ spec = do spago ["init"] >>= shouldBeSuccess if usingEsModules then do spago ["bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess + ls [] + cat ["bundle-app-esm.js"] checkFixture "bundle-app-esm.js" else do spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess @@ -736,6 +738,8 @@ spec = do spago ["init"] >>= shouldBeSuccess if usingEsModules then do spago ["bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess + ls [] + cat ["bundle-app-src-map-esm.js"] checkFixture "bundle-app-src-map-esm.js" checkFileExist "bundle-app-src-map-esm.js.map" else do diff --git a/test/Utils.hs b/test/Utils.hs index 603f53709..3304f6612 100644 --- a/test/Utils.hs +++ b/test/Utils.hs @@ -20,6 +20,8 @@ module Utils , shouldBeEmptySuccess , spago , dhall + , ls + , cat , withCwd , withEnvVar) where @@ -59,6 +61,16 @@ proc cmd args = do (c, out, err) <- Turtle.Bytes.procStrictWithErr cmd args empty pure (c, b2t out, b2t err) +ls :: [Text] -> IO () +ls args = proc "ls" args >>= \(_, _stdout, _stderr) -> do + print $ "STDOUT: " <> _stdout + print $ "STDERR: " <> _stderr + +cat :: [Text] -> IO () +cat args = proc "cat" args >>= \(_, _stdout, _stderr) -> do + print $ "STDOUT: " <> _stdout + print $ "STDERR: " <> _stderr + dhall :: [Text] -> IO (ExitCode, Text, Text) dhall = proc "dhall" From c4678ac102d208605911c143485237beb0da5488 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 11:54:38 -0500 Subject: [PATCH 52/82] Run test with verbose output --- test/SpagoSpec.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index a7e47ed8f..a53e98985 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -725,7 +725,7 @@ spec = do whenUsingEsModulesFixPackagesDhall spago ["init"] >>= shouldBeSuccess if usingEsModules then do - spago ["bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess + spago [ "-V", "bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess ls [] cat ["bundle-app-esm.js"] checkFixture "bundle-app-esm.js" @@ -737,7 +737,7 @@ spec = do whenUsingEsModulesFixPackagesDhall spago ["init"] >>= shouldBeSuccess if usingEsModules then do - spago ["bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess + spago ["-V", "bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess ls [] cat ["bundle-app-src-map-esm.js"] checkFixture "bundle-app-src-map-esm.js" From 4de386743d9ea8a44eed594a24f56ad83688b363 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 12:07:17 -0500 Subject: [PATCH 53/82] Drop ls and cat --- test/SpagoSpec.hs | 6 +----- test/Utils.hs | 12 ------------ 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index a53e98985..a06183a7b 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -13,7 +13,7 @@ import Utils (checkFileHasInfix, checkFixture, checkFileE readFixture, runFor, shouldBeFailure, shouldBeFailureInfix, shouldBeFailureStderr, shouldBeSuccess, shouldBeSuccessOutput, shouldBeSuccessOutputWithErr, shouldBeSuccessStderr, spago, - withCwd, withEnvVar, dhall, ls, cat) + withCwd, withEnvVar, dhall) import qualified Data.Versions as Version import qualified Spago.Cmd as Cmd @@ -726,8 +726,6 @@ spec = do spago ["init"] >>= shouldBeSuccess if usingEsModules then do spago [ "-V", "bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess - ls [] - cat ["bundle-app-esm.js"] checkFixture "bundle-app-esm.js" else do spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess @@ -738,8 +736,6 @@ spec = do spago ["init"] >>= shouldBeSuccess if usingEsModules then do spago ["-V", "bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess - ls [] - cat ["bundle-app-src-map-esm.js"] checkFixture "bundle-app-src-map-esm.js" checkFileExist "bundle-app-src-map-esm.js.map" else do diff --git a/test/Utils.hs b/test/Utils.hs index 3304f6612..603f53709 100644 --- a/test/Utils.hs +++ b/test/Utils.hs @@ -20,8 +20,6 @@ module Utils , shouldBeEmptySuccess , spago , dhall - , ls - , cat , withCwd , withEnvVar) where @@ -61,16 +59,6 @@ proc cmd args = do (c, out, err) <- Turtle.Bytes.procStrictWithErr cmd args empty pure (c, b2t out, b2t err) -ls :: [Text] -> IO () -ls args = proc "ls" args >>= \(_, _stdout, _stderr) -> do - print $ "STDOUT: " <> _stdout - print $ "STDERR: " <> _stderr - -cat :: [Text] -> IO () -cat args = proc "cat" args >>= \(_, _stdout, _stderr) -> do - print $ "STDOUT: " <> _stdout - print $ "STDERR: " <> _stderr - dhall :: [Text] -> IO (ExitCode, Text, Text) dhall = proc "dhall" From 3ac069395e4629f13a6b85c0102d71bf0ca42048 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Sat, 2 Apr 2022 12:26:49 -0500 Subject: [PATCH 54/82] Replace '\n' with ';' --- src/Spago/Build.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index bcd3f9656..d28cfc7f5 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -426,7 +426,7 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath WithoutSrcMap -> "" cmd = case withMain of WithMain -> - "echo \"import { main } from './output/" <> moduleName <> "/index.js'\nmain()\" | " + "echo \"import { main } from './output/" <> moduleName <> "/index.js'; main();\" | " <> esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --bundle " <> " --outfile=" <> targetPath WithoutMain -> From 2403d693340562eac7d813e2c36a19bb83125979 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Sun, 3 Apr 2022 08:51:16 +0100 Subject: [PATCH 55/82] Fix echo line on windows --- src/Spago/Build.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index d28cfc7f5..330c8d957 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -21,6 +21,7 @@ import qualified Data.Versions as Version import System.Directory (getCurrentDirectory) import System.FilePath (splitDirectories) import qualified System.FilePath.Glob as Glob +import qualified System.Info import qualified System.IO as Sys import qualified System.IO.Temp as Temp import qualified System.IO.Utf8 as Utf8 @@ -424,9 +425,12 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath srcMapOpt = case srcMap of WithSrcMap -> " --sourcemap" WithoutSrcMap -> "" + echoLine = case System.Info.os of + "mingw3" -> "echo import { main } from './output/" <> moduleName <> "/index.js'; main(); | " + _ -> "echo \"import { main } from './output/" <> moduleName <> "/index.js'; main();\" | " cmd = case withMain of WithMain -> - "echo \"import { main } from './output/" <> moduleName <> "/index.js'; main();\" | " + echoLine <> esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --bundle " <> " --outfile=" <> targetPath WithoutMain -> From e706a2d940c6b410bdc7a4d6f1e631bf9e3b6a42 Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Sun, 3 Apr 2022 09:14:29 +0100 Subject: [PATCH 56/82] Try backslash --- src/Spago/Build.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 330c8d957..e322cd7fb 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -426,7 +426,7 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath WithSrcMap -> " --sourcemap" WithoutSrcMap -> "" echoLine = case System.Info.os of - "mingw3" -> "echo import { main } from './output/" <> moduleName <> "/index.js'; main(); | " + "mingw3" -> "echo import { main } from '.\\output\\" <> moduleName <> "\\index.js'; main(); | " _ -> "echo \"import { main } from './output/" <> moduleName <> "/index.js'; main();\" | " cmd = case withMain of WithMain -> From e5db7dea433a7cc4adec982f9f267aaae733dd8c Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Sun, 3 Apr 2022 09:26:45 +0100 Subject: [PATCH 57/82] Add file protocol --- src/Spago/Build.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index e322cd7fb..22a26ea7d 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -426,7 +426,7 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath WithSrcMap -> " --sourcemap" WithoutSrcMap -> "" echoLine = case System.Info.os of - "mingw3" -> "echo import { main } from '.\\output\\" <> moduleName <> "\\index.js'; main(); | " + "mingw3" -> "echo import { main } from 'file://./output/" <> moduleName <> "/index.js'; main(); | " _ -> "echo \"import { main } from './output/" <> moduleName <> "/index.js'; main();\" | " cmd = case withMain of WithMain -> From d76ef524054e36309f742b05bfe00dfdb4f0f1ee Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Sun, 3 Apr 2022 09:46:03 +0100 Subject: [PATCH 58/82] Try using quotation marks --- src/Spago/Build.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 22a26ea7d..168b599e1 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -426,7 +426,7 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath WithSrcMap -> " --sourcemap" WithoutSrcMap -> "" echoLine = case System.Info.os of - "mingw3" -> "echo import { main } from 'file://./output/" <> moduleName <> "/index.js'; main(); | " + "mingw3" -> "echo import { main } from \"file://./output/" <> moduleName <> "/index.js\"; main(); | " _ -> "echo \"import { main } from './output/" <> moduleName <> "/index.js'; main();\" | " cmd = case withMain of WithMain -> From 71a21231ada0ad0b4cb55b01f208b616168949dc Mon Sep 17 00:00:00 2001 From: sigma-andex Date: Sun, 3 Apr 2022 09:58:47 +0100 Subject: [PATCH 59/82] Revert intents --- src/Spago/Build.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 168b599e1..134fbfc72 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -426,7 +426,7 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath WithSrcMap -> " --sourcemap" WithoutSrcMap -> "" echoLine = case System.Info.os of - "mingw3" -> "echo import { main } from \"file://./output/" <> moduleName <> "/index.js\"; main(); | " + "mingw3" -> "echo import { main } from './output/" <> moduleName <> "/index.js'; main(); | " _ -> "echo \"import { main } from './output/" <> moduleName <> "/index.js'; main();\" | " cmd = case withMain of WithMain -> From d18cc88e488f8a8d2e33802534b1bd699a250b12 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Sun, 3 Apr 2022 23:18:15 +0100 Subject: [PATCH 60/82] Update src/Spago/Build.hs Co-authored-by: Nicholas Yip --- src/Spago/Build.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 134fbfc72..0ade7337b 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -426,7 +426,7 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath WithSrcMap -> " --sourcemap" WithoutSrcMap -> "" echoLine = case System.Info.os of - "mingw3" -> "echo import { main } from './output/" <> moduleName <> "/index.js'; main(); | " + "mingw32" -> "echo import { main } from './output/" <> moduleName <> "/index.js'; main(); | " _ -> "echo \"import { main } from './output/" <> moduleName <> "/index.js'; main();\" | " cmd = case withMain of WithMain -> From 92176bd0d207046291e2e52b2764c29fc0b6f319 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 4 Apr 2022 08:48:40 -0500 Subject: [PATCH 61/82] Merge purs-0.15 download steps into 1 --- .github/workflows/build.yml | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5340d5599..a6d8315e1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,10 +20,14 @@ jobs: include: - os: ubuntu-latest image: haskell:8.10.7-stretch@sha256:100f8fb7d7d8d64adb5e106fe8136b8d4cbdc03aeb2cbd145a7597d74b69bafb - purs_0_15_file: linux64 + purs_0_15_download_file: linux64 + purs_0_15_binary_file: purs - os: macOS-latest - purs_0_15_file: macos + purs_0_15_download_file: macos + purs_0_15_binary_file: purs - os: windows-latest + purs_0_15_download_file: win64 + purs_0_15_binary_file: purs.exe steps: # We need a proper Git repository, but the checkout step will unpack a tarball instead of doing a clone # if the Git version is less than 2.18. @@ -120,27 +124,17 @@ jobs: # run: ./scripts/fix-home stack test # shell: bash - - name: non-Windows - Download PureScript 0.15.0 - if: runner.os != 'Windows' + - name: Download PureScript 0.15.0 shell: bash env: - FILE: ${{ matrix.purs_0_15_file }} - run: | - DIR="$HOME/bin/purescript-$PS_0_15_0_VERSION" - mkdir -p "$DIR" - curl -o "$DIR/purescript.tar.gz" -L "https://github.com/purescript/purescript/releases/download/$PS_0_15_0_VERSION/$FILE.tar.gz" - tar -xvf "$DIR/purescript.tar.gz" -C "$DIR" --strip-components 1 purescript/purs - chmod a+x "$DIR/purs" - - - name: Windows - Download PureScript 0.15.0 - if: runner.os == 'Windows' - shell: bash + DL_FILE: ${{ matrix.purs_0_15_download_file }} + BIN_FILE: ${{ matrix.purs_0_15_binary_file }} run: | DIR="$HOME/bin/purescript-$PS_0_15_0_VERSION" mkdir -p "$DIR" - curl -opurescript.tar.gz -L "https://github.com/purescript/purescript/releases/download/$PS_0_15_0_VERSION/win64.tar.gz" - tar -xvzf purescript.tar.gz -C "$DIR" --strip-components 1 purescript/purs.exe - chmod a+x "$DIR/purs.exe" + curl -o "$DIR/purescript.tar.gz" -L "https://github.com/purescript/purescript/releases/download/$PS_0_15_0_VERSION/$DL_FILE.tar.gz" + tar -xvf "$DIR/purescript.tar.gz" -C "$DIR" --strip-components 1 "purescript/$BIN_FILE" + chmod a+x "$DIR/$BIN_FILE" - name: Run tests (PureScript >= 0.15.0) shell: bash From 5faebf4260f46bc7c6cf9c03e01a4d7fcc4b3739 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 4 Apr 2022 08:48:59 -0500 Subject: [PATCH 62/82] Re-enable standard spago tests --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a6d8315e1..751f5ee92 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -120,9 +120,9 @@ jobs: run: ./scripts/fix-home stack install shell: bash - # - name: Run tests (PureScript < 0.15.0) - # run: ./scripts/fix-home stack test - # shell: bash + - name: Run tests (PureScript < 0.15.0) + run: ./scripts/fix-home stack test + shell: bash - name: Download PureScript 0.15.0 shell: bash From 0a6fd136c03d3766c55fae3eb20aba0a7dd40eb2 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 4 Apr 2022 12:42:33 -0500 Subject: [PATCH 63/82] Use esm format for bundle-app --- src/Spago/Build.hs | 30 ++++++++++++------------- test/fixtures/bundle-app-esm.js | 20 ++++++++--------- test/fixtures/bundle-app-src-map-esm.js | 20 ++++++++--------- 3 files changed, 32 insertions(+), 38 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 0ade7337b..b13a83cad 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -21,7 +21,6 @@ import qualified Data.Versions as Version import System.Directory (getCurrentDirectory) import System.FilePath (splitDirectories) import qualified System.FilePath.Glob as Glob -import qualified System.Info import qualified System.IO as Sys import qualified System.IO.Temp as Temp import qualified System.IO.Utf8 as Utf8 @@ -425,21 +424,20 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath srcMapOpt = case srcMap of WithSrcMap -> " --sourcemap" WithoutSrcMap -> "" - echoLine = case System.Info.os of - "mingw32" -> "echo import { main } from './output/" <> moduleName <> "/index.js'; main(); | " - _ -> "echo \"import { main } from './output/" <> moduleName <> "/index.js'; main();\" | " - cmd = case withMain of - WithMain -> - echoLine - <> esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --bundle " - <> " --outfile=" <> targetPath - WithoutMain -> - esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --format=esm --bundle " - <> "output/" <> moduleName <> "/index.js" - <> " --outfile=" <> targetPath - runWithOutput cmd - ("Bundle succeeded and output file to " <> targetPath) - "Bundle failed." + successMsg = "Bundle succeeded and output file to " <> targetPath + failMsg = "Bundle failed." + case withMain of + WithMain -> do + let + cmd = esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --format=esm --bundle " + <> " --outfile=" <> targetPath <> " --allow-overwrite " <> targetPath + writeTextFile targetPath $ "import { main } from './output/" <> moduleName <> "/index.js'; main();" + runWithOutput cmd successMsg failMsg + WithoutMain -> do + let + cmd = esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --format=esm --bundle " + <> " --outfile=" <> targetPath <> " output/" <> moduleName <> "/index.js" + runWithOutput cmd successMsg failMsg where getESBuild = do maybeESBuild <- findExecutable "esbuild" diff --git a/test/fixtures/bundle-app-esm.js b/test/fixtures/bundle-app-esm.js index fef3eca9a..7b71d459d 100644 --- a/test/fixtures/bundle-app-esm.js +++ b/test/fixtures/bundle-app-esm.js @@ -1,14 +1,12 @@ -(() => { - // output/Effect.Console/foreign.js - var log = function(s) { - return function() { - console.log(s); - }; +// output/Effect.Console/foreign.js +var log = function(s) { + return function() { + console.log(s); }; +}; - // output/Main/index.js - var main = /* @__PURE__ */ log("\u{1F35D}"); +// output/Main/index.js +var main = /* @__PURE__ */ log("\u{1F35D}"); - // - main(); -})(); +// bundle-app-esm.js +main(); diff --git a/test/fixtures/bundle-app-src-map-esm.js b/test/fixtures/bundle-app-src-map-esm.js index b167ded57..8dd58b506 100644 --- a/test/fixtures/bundle-app-src-map-esm.js +++ b/test/fixtures/bundle-app-src-map-esm.js @@ -1,15 +1,13 @@ -(() => { - // output/Effect.Console/foreign.js - var log = function(s) { - return function() { - console.log(s); - }; +// output/Effect.Console/foreign.js +var log = function(s) { + return function() { + console.log(s); }; +}; - // output/Main/index.js - var main = /* @__PURE__ */ log("\u{1F35D}"); +// output/Main/index.js +var main = /* @__PURE__ */ log("\u{1F35D}"); - // - main(); -})(); +// bundle-app-src-map-esm.js +main(); //# sourceMappingURL=bundle-app-src-map-esm.js.map From 7b3ed9d0720624125b53f0da7b81f147b0ee0fdb Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 4 Apr 2022 12:45:03 -0500 Subject: [PATCH 64/82] Deduplicate esbuild command --- src/Spago/Build.hs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index b13a83cad..cb7accf7c 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -426,17 +426,16 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath WithoutSrcMap -> "" successMsg = "Bundle succeeded and output file to " <> targetPath failMsg = "Bundle failed." + esbuildBase = esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --format=esm --bundle --outfile=" <> targetPath case withMain of WithMain -> do - let - cmd = esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --format=esm --bundle " - <> " --outfile=" <> targetPath <> " --allow-overwrite " <> targetPath + -- Since `targetPath` is used as both input/output, + -- we also need the `--allow-overwrite` flag. + let cmd = esbuildBase <> " --allow-overwrite " <> targetPath writeTextFile targetPath $ "import { main } from './output/" <> moduleName <> "/index.js'; main();" runWithOutput cmd successMsg failMsg WithoutMain -> do - let - cmd = esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --format=esm --bundle " - <> " --outfile=" <> targetPath <> " output/" <> moduleName <> "/index.js" + let cmd = esbuildBase <> " output/" <> moduleName <> "/index.js" runWithOutput cmd successMsg failMsg where getESBuild = do From 9b3d49eb151660a68b2d5a0253a4ba81dc99bb59 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 5 Apr 2022 20:36:34 -0500 Subject: [PATCH 65/82] Revert back to using echo line for wrapper This drops the change were we use the target path for both the `import { main } from '..'; main();` wrapper input file and the esbuild output file --- src/Spago/Build.hs | 23 ++++++++++++----------- test/fixtures/bundle-app-esm.js | 2 +- test/fixtures/bundle-app-src-map-esm.js | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index cb7accf7c..26e031b9e 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -21,6 +21,7 @@ import qualified Data.Versions as Version import System.Directory (getCurrentDirectory) import System.FilePath (splitDirectories) import qualified System.FilePath.Glob as Glob +import qualified System.Info as SysInfo import qualified System.IO as Sys import qualified System.IO.Temp as Temp import qualified System.IO.Utf8 as Utf8 @@ -424,19 +425,19 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath srcMapOpt = case srcMap of WithSrcMap -> " --sourcemap" WithoutSrcMap -> "" - successMsg = "Bundle succeeded and output file to " <> targetPath - failMsg = "Bundle failed." esbuildBase = esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --format=esm --bundle --outfile=" <> targetPath - case withMain of + cmd = case withMain of WithMain -> do - -- Since `targetPath` is used as both input/output, - -- we also need the `--allow-overwrite` flag. - let cmd = esbuildBase <> " --allow-overwrite " <> targetPath - writeTextFile targetPath $ "import { main } from './output/" <> moduleName <> "/index.js'; main();" - runWithOutput cmd successMsg failMsg - WithoutMain -> do - let cmd = esbuildBase <> " output/" <> moduleName <> "/index.js" - runWithOutput cmd successMsg failMsg + let + echoLine = case SysInfo.os of + "mingw32" -> "echo import { main } from './output/" <> moduleName <> "/index.js'; main(); | " + _ -> "echo \"import { main } from './output/" <> moduleName <> "/index.js'; main();\" | " + echoLine <> esbuildBase + WithoutMain -> + esbuildBase <> " output/" <> moduleName <> "/index.js" + runWithOutput cmd + ("Bundle succeeded and output file to " <> targetPath) + "Bundle failed." where getESBuild = do maybeESBuild <- findExecutable "esbuild" diff --git a/test/fixtures/bundle-app-esm.js b/test/fixtures/bundle-app-esm.js index 7b71d459d..0c581ab56 100644 --- a/test/fixtures/bundle-app-esm.js +++ b/test/fixtures/bundle-app-esm.js @@ -8,5 +8,5 @@ var log = function(s) { // output/Main/index.js var main = /* @__PURE__ */ log("\u{1F35D}"); -// bundle-app-esm.js +// main(); diff --git a/test/fixtures/bundle-app-src-map-esm.js b/test/fixtures/bundle-app-src-map-esm.js index 8dd58b506..0c26d4716 100644 --- a/test/fixtures/bundle-app-src-map-esm.js +++ b/test/fixtures/bundle-app-src-map-esm.js @@ -8,6 +8,6 @@ var log = function(s) { // output/Main/index.js var main = /* @__PURE__ */ log("\u{1F35D}"); -// bundle-app-src-map-esm.js +// main(); //# sourceMappingURL=bundle-app-src-map-esm.js.map From 0a6acaa9a7a8159fefead44418e5589a8598d0d4 Mon Sep 17 00:00:00 2001 From: Nicholas Yip Date: Tue, 5 Apr 2022 15:28:19 +0900 Subject: [PATCH 66/82] Define `runProcessWithOutput` --- src/Spago/Prelude.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Spago/Prelude.hs b/src/Spago/Prelude.hs index daf32765a..79c93bc30 100644 --- a/src/Spago/Prelude.hs +++ b/src/Spago/Prelude.hs @@ -67,6 +67,7 @@ module Spago.Prelude , findExecutableOrDie , findExecutable , runWithOutput + , runProcessWithOutput -- * Other , Dhall.Core.throws , repr @@ -108,7 +109,7 @@ import RIO as X hiding (FilePath, fi import RIO.Orphans as X import Safe (headMay, lastMay) import System.FilePath (isAbsolute, pathSeparator, ()) -import Turtle (FilePath, appendonly, chmod, +import Turtle (FilePath, Line, appendonly, chmod, executable, mktree, repr, shell, shellStrict, shellStrictWithErr, systemStrictWithErr, testdir) @@ -271,6 +272,14 @@ runWithOutput command success failure = do ExitSuccess -> logInfo $ display success ExitFailure _ -> die [ display failure ] +-- | Run the given command. +runProcessWithOutput :: HasLogFunc env => NonEmpty Text -> Maybe Line -> Text -> Text -> RIO env () +runProcessWithOutput (command :| arguments) input success failure = do + logDebug $ "Running command: `" <> display (Text.intercalate " " $ command : arguments) <> "`" + Turtle.proc command arguments (Turtle.select input) >>= \case + ExitSuccess -> logInfo $ display success + ExitFailure _ -> die [ display failure ] + -- | Return the full path of the executable we're trying to call, -- or die trying findExecutableOrDie :: HasLogFunc env => String -> RIO env Text From f6138909d756026cc08fc618515adda58499295a Mon Sep 17 00:00:00 2001 From: Nicholas Yip Date: Wed, 6 Apr 2022 13:22:11 +0900 Subject: [PATCH 67/82] Supply stdin separately --- src/Spago/Build.hs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index 26e031b9e..ad30febca 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -21,7 +21,6 @@ import qualified Data.Versions as Version import System.Directory (getCurrentDirectory) import System.FilePath (splitDirectories) import qualified System.FilePath.Glob as Glob -import qualified System.Info as SysInfo import qualified System.IO as Sys import qualified System.IO.Temp as Temp import qualified System.IO.Utf8 as Utf8 @@ -417,25 +416,23 @@ bundleWithEsbuild withMain srcMap (ModuleName moduleName) (TargetPath targetPath esbuild <- getESBuild let platformOpt = case platform of - Browser -> " --platform=browser" - Node -> " --platform=node" + Browser -> ["--platform=browser"] + Node -> ["--platform=node"] minifyOpt = case minify of - NoMinify -> "" - Minify -> " --minify" + NoMinify -> [] + Minify -> ["--minify"] srcMapOpt = case srcMap of - WithSrcMap -> " --sourcemap" - WithoutSrcMap -> "" - esbuildBase = esbuild <> platformOpt <> minifyOpt <> srcMapOpt <> " --format=esm --bundle --outfile=" <> targetPath - cmd = case withMain of + WithSrcMap -> ["--sourcemap"] + WithoutSrcMap -> [] + esbuildBase = platformOpt <> minifyOpt <> srcMapOpt <> ["--format=esm", "--bundle", "--outfile=" <> targetPath] + (input, cmd) = case withMain of WithMain -> do let - echoLine = case SysInfo.os of - "mingw32" -> "echo import { main } from './output/" <> moduleName <> "/index.js'; main(); | " - _ -> "echo \"import { main } from './output/" <> moduleName <> "/index.js'; main();\" | " - echoLine <> esbuildBase + echoLine = "import { main } from './output/" <> moduleName <> "/index.js'; main();" + (Turtle.textToLine echoLine, esbuild :| esbuildBase) WithoutMain -> - esbuildBase <> " output/" <> moduleName <> "/index.js" - runWithOutput cmd + (Nothing, esbuild :| esbuildBase <> ["output/" <> moduleName <> "/index.js"]) + runProcessWithOutput cmd input ("Bundle succeeded and output file to " <> targetPath) "Bundle failed." where From af6b03468ab603eb117cc4ce1bb9deba95ef7a4b Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 6 Apr 2022 06:46:04 -0500 Subject: [PATCH 68/82] Drop fail-fast in build.yml --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 751f5ee92..87403e72b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,7 +15,6 @@ jobs: runs-on: ${{ matrix.os }} container: ${{ matrix.image }} strategy: - fail-fast: false matrix: include: - os: ubuntu-latest From 222a743a5df5710d6e9d1de696316a08fe3d9967 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 6 Apr 2022 06:55:43 -0500 Subject: [PATCH 69/82] Drop comment on packages.dhall prepare-0.15 --- test/fixtures/packages-prepare-0-15.dhall | 100 ---------------------- 1 file changed, 100 deletions(-) diff --git a/test/fixtures/packages-prepare-0-15.dhall b/test/fixtures/packages-prepare-0-15.dhall index 4963b0ada..aa940d7fe 100644 --- a/test/fixtures/packages-prepare-0-15.dhall +++ b/test/fixtures/packages-prepare-0-15.dhall @@ -1,103 +1,3 @@ -{- -Welcome to your new Dhall package-set! - -Below are instructions for how to edit this file for most use -cases, so that you don't need to know Dhall to use it. - -## Use Cases - -Most will want to do one or both of these options: -1. Override/Patch a package's dependency -2. Add a package not already in the default package set - -This file will continue to work whether you use one or both options. -Instructions for each option are explained below. - -### Overriding/Patching a package - -Purpose: -- Change a package's dependency to a newer/older release than the - default package set's release -- Use your own modified version of some dependency that may - include new API, changed API, removed API by - using your custom git repo of the library rather than - the package set's repo - -Syntax: -where `entityName` is one of the following: -- dependencies -- repo -- version -------------------------------- -let upstream = -- -in upstream - with packageName.entityName = "new value" -------------------------------- - -Example: -------------------------------- -let upstream = -- -in upstream - with halogen.version = "master" - with halogen.repo = "https://example.com/path/to/git/repo.git" - - with halogen-vdom.version = "v4.0.0" - with halogen-vdom.dependencies = [ "extra-dependency" ] # halogen-vdom.dependencies -------------------------------- - -### Additions - -Purpose: -- Add packages that aren't already included in the default package set - -Syntax: -where `` is: -- a tag (i.e. "v4.0.0") -- a branch (i.e. "master") -- commit hash (i.e. "701f3e44aafb1a6459281714858fadf2c4c2a977") -------------------------------- -let upstream = -- -in upstream - with new-package-name = - { dependencies = - [ "dependency1" - , "dependency2" - ] - , repo = - "https://example.com/path/to/git/repo.git" - , version = - "" - } -------------------------------- - -Example: -------------------------------- -let upstream = -- -in upstream - with benchotron = - { dependencies = - [ "arrays" - , "exists" - , "profunctor" - , "strings" - , "quickcheck" - , "lcg" - , "transformers" - , "foldable-traversable" - , "exceptions" - , "node-fs" - , "node-buffer" - , "node-readline" - , "datetime" - , "now" - ] - , repo = - "https://github.com/hdgarrood/purescript-benchotron.git" - , version = - "v7.0.0" - } -------------------------------- --} let upstream = https://github.com/JordanMartinez/package-sets/releases/download/psc-0.15.0-20220329/packages.dhall From 2555923c92add1c48b06ddcaf0c54f83ffd5a900 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 6 Apr 2022 07:04:35 -0500 Subject: [PATCH 70/82] Move Node code into nodeAction This change forces the `build` command's `Env` arg to have more capabilities. For now, I've propagated that by granting it the `HasBuildEnv`, but that might be granting it too many capabilities. --- src/Spago/Build.hs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Spago/Build.hs b/src/Spago/Build.hs index ad30febca..b4ef1b073 100644 --- a/src/Spago/Build.hs +++ b/src/Spago/Build.hs @@ -52,7 +52,7 @@ prepareBundleDefaults maybeModuleName maybeTargetPath maybePlatform = (moduleNam platform = fromMaybe Browser maybePlatform -- eventually running some other action after the build -build :: HasBuildEnv env => Maybe (RIO Env ()) -> RIO env () +build :: HasBuildEnv env => Maybe (RIO env ()) -> RIO env () build maybePostBuild = do logDebug "Running `spago build`" BuildOptions{..} <- view (the @BuildOptions) @@ -145,8 +145,7 @@ build maybePostBuild = do checkImports buildAction globs = do - env <- Run.getEnv - let action = buildBackend globs >> (runRIO env $ fromMaybe (pure ()) maybePostBuild) + let action = buildBackend globs >> (fromMaybe (pure ()) maybePostBuild) runCommands "Before" beforeCommands action `onException` (runCommands "Else" elseCommands) runCommands "Then" thenCommands @@ -341,14 +340,9 @@ runBackend runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybeSuccessMessage failureMessage extraArgs = do logDebug $ display $ "Running with backend: " <> fromMaybe "nodejs" maybeBackend BuildOptions{ pursArgs } <- view (the @BuildOptions) - isES <- Purs.hasMinPursVersion "0.15.0-alpha-01" - nodeEsSupport <- hasNodeEsSupport - case (isES, nodeEsSupport) of - (True, Unsupported nv) -> die [ "Unsupported Node.js version: " <> display (Version.prettySemVer nv), "Required Node.js version >=12." ] - _ -> - let - postBuild = maybe (nodeAction isES nodeEsSupport $ Path.getOutputPath pursArgs) backendAction maybeBackend - in build (Just postBuild) + let + postBuild = maybe (nodeAction $ Path.getOutputPath pursArgs) backendAction maybeBackend + build (Just postBuild) where fromFilePath = Text.pack . Turtle.encodeString runJsSource = fromFilePath (sourceDir Turtle. ".spago/run.js") @@ -386,7 +380,14 @@ runBackend maybeBackend RunDirectories{ sourceDir, executeDir } moduleName maybe nodeCmd isES Experimental | isES = "node --experimental-modules \"" <> runJsSource <> "\" " <> nodeArgs nodeCmd _ _ = "node \"" <> runJsSource <> "\" " <> nodeArgs - nodeAction isES nodeVersion outputPath' = do + nodeAction outputPath' = do + isES <- Purs.hasMinPursVersion "0.15.0-alpha-01" + nodeVersion <- hasNodeEsSupport + case (isES, nodeVersion) of + (True, Unsupported nv) -> + die [ "Unsupported Node.js version: " <> display (Version.prettySemVer nv), "Required Node.js version >=12." ] + _ -> + pure () logDebug $ "Writing " <> displayShow @Text runJsSource writeTextFile runJsSource (nodeContents isES outputPath') void $ chmod executable $ pathFromText runJsSource @@ -474,7 +475,7 @@ bundleModule withMain BundleOptions { maybeModuleName, maybeTargetPath, maybePla Left (n :: SomeException) -> die [ "Make module failed: " <> repr n ] case noBuild of DoBuild -> Run.withBuildEnv usePsa buildOpts $ build (Just bundleAction) - NoBuild -> Run.getEnv >>= (flip runRIO) bundleAction + NoBuild -> Run.withBuildEnv usePsa buildOpts bundleAction docsSearchTemplate :: (HasType LogFunc env, HasType PursCmd env) => RIO env Text docsSearchTemplate = ifM (Purs.hasMinPursVersion "0.14.0") From 6b4d25ef24629dd82024ee43559bea53bb1edf82 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 13 Apr 2022 13:55:01 -0500 Subject: [PATCH 71/82] Push things to top-level; use two test fns --- test/SpagoSpec.hs | 216 ++++++++++++++++++++++++---------------------- 1 file changed, 113 insertions(+), 103 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index a06183a7b..39588cc24 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -24,22 +24,31 @@ setup dir cmd = do -- print ("Running in " <> temp) withCwd (decodeString temp) cmd +purs0_15_0TestMsg :: String +purs0_15_0TestMsg = "purs-0.15" + +fixPackagesDhall :: Bool -> IO () +fixPackagesDhall usingEsModules = when usingEsModules $ do + -- The prepare-0.15 package set's contents can change. + -- So, we copy an unfrozen one into the directory + -- and then freeze it before running `spago init`. + cp "../fixtures/packages-prepare-0-15.dhall" "packages.dhall" + dhall ["freeze", "packages.dhall"] >>= shouldBeSuccess + +getUsingEsModules :: IO Bool +getUsingEsModules = do + pursVersion <- Cmd.getCmdVersion "purs" >>= either die pure + esmVersion <- either (const $ die "Failed to parse `0.15.0` static version") pure $ Version.semver "0.15.0-alpha-02" + pure $ pursVersion >= esmVersion + spec :: Spec spec = do - usingEsModules <- runIO $ do - pursVersion <- Cmd.getCmdVersion "purs" >>= either die pure - esmVersion <- either (const $ die "Failed to parse `0.15.0` static version") pure $ Version.semver "0.15.0-alpha-02" - pure $ pursVersion >= esmVersion - let - purs0_15_0TestMsg = "purs-0.15" - whenUsingEsModulesFixPackagesDhall = when usingEsModules $ do - -- The prepare-0.15 package set's contents can change. - -- So, we copy an unfrozen one into the directory - -- and then freeze it before running `spago init`. - cp "../fixtures/packages-prepare-0-15.dhall" "packages.dhall" - dhall ["freeze", "packages.dhall"] >>= shouldBeSuccess - - around_ (setup "spago-test") $ do + usingEsModules <- runIO getUsingEsModules + noSpacesInParentDir usingEsModules + spacesInParentDir usingEsModules + +noSpacesInParentDir :: Bool -> Spec +noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do describe "spago init" $ do @@ -722,7 +731,7 @@ spec = do describe purs0_15_0TestMsg $ do describe "spago bundle-app" $ do it "Spago should bundle successfully" $ do - whenUsingEsModulesFixPackagesDhall + fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess if usingEsModules then do spago [ "-V", "bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess @@ -732,7 +741,7 @@ spec = do checkFixture "bundle-app.js" it "Spago should bundle successfully with source map" $ do - whenUsingEsModulesFixPackagesDhall + fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess if usingEsModules then do spago ["-V", "bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess @@ -745,7 +754,7 @@ spec = do describe "spago bundle-module" $ do it "Spago should successfully make a module" $ do - whenUsingEsModulesFixPackagesDhall + fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess -- Now we don't remove the output folder, but we pass the `--no-build` @@ -759,7 +768,7 @@ spec = do checkFixture "bundle-module.js" it "Spago should successfully make a module with source map" $ do - whenUsingEsModulesFixPackagesDhall + fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess @@ -772,113 +781,114 @@ spec = do checkFixture "bundle-module-src-map.js" checkFileExist "bundle-module-src-map.js.map" - around_ (setup "spago test") $ do +spacesInParentDir :: Bool -> Spec +spacesInParentDir usingEsModules = around_ (setup "spago test") $ do - describe purs0_15_0TestMsg $ do + describe purs0_15_0TestMsg $ do - describe "spago run" $ do + describe "spago run" $ do - it "Spago should run successfully" $ do + it "Spago should run successfully" $ do - whenUsingEsModulesFixPackagesDhall - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess - shell "psa --version" empty >>= \case - ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" - ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" + shell "psa --version" empty >>= \case + ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" + ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" - it "Spago should be able to not use `psa`" $ do + it "Spago should be able to not use `psa`" $ do - whenUsingEsModulesFixPackagesDhall - spago ["init"] >>= shouldBeSuccess - spago ["--no-psa", "build"] >>= shouldBeSuccess - spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["--no-psa", "build"] >>= shouldBeSuccess + spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" - it "Spago should pass stdin to the child process" $ do + it "Spago should pass stdin to the child process" $ do - whenUsingEsModulesFixPackagesDhall - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-stdin.purs" "src/Main.purs" - spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-stdin.purs" "src/Main.purs" + spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt" - it "Spago should use exec-args" $ do + it "Spago should use exec-args" $ do - whenUsingEsModulesFixPackagesDhall - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" - it "Spago should use node-args" $ do + it "Spago should use node-args" $ do - whenUsingEsModulesFixPackagesDhall - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" - spago ["run", "--node-args", "--flagName"] >>= shouldBeSuccess + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" + spago ["run", "--node-args", "--flagName"] >>= shouldBeSuccess - it "Spago should prefer exec-args" $ do + it "Spago should prefer exec-args" $ do - whenUsingEsModulesFixPackagesDhall - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + cp "../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt" - describe "spago test" $ do + describe "spago test" $ do - it "Spago should test successfully" $ do + it "Spago should test successfully" $ do - whenUsingEsModulesFixPackagesDhall - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" - it "Spago should fail nicely when the test module is not found" $ do + it "Spago should fail nicely when the test module is not found" $ do - whenUsingEsModulesFixPackagesDhall - spago ["init"] >>= shouldBeSuccess - mv "test" "test2" - spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + mv "test" "test2" + spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" - it "Spago should test in custom output folder" $ do + it "Spago should test in custom output folder" $ do - whenUsingEsModulesFixPackagesDhall - spago ["init"] >>= shouldBeSuccess - spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess - testdir "myOutput" `shouldReturn` True + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess + testdir "myOutput" `shouldReturn` True - it "Spago should test successfully with a different output folder" $ do + it "Spago should test successfully with a different output folder" $ do - -- Create root-level packages.dhall - mkdir "monorepo" - cd "monorepo" - when usingEsModules $ do - cp "../../fixtures/packages-prepare-0-15.dhall" "packages.dhall" - void $ dhall ["freeze", "packages.dhall"] - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" + -- Create root-level packages.dhall + mkdir "monorepo" + cd "monorepo" + when usingEsModules $ do + cp "../../fixtures/packages-prepare-0-15.dhall" "packages.dhall" + void $ dhall ["freeze", "packages.dhall"] + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" - -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) - mkdir "lib-a" - cd "lib-a" - when usingEsModules $ do - cp "../../../fixtures/packages-prepare-0-15.dhall" "packages.dhall" - void $ dhall ["freeze", "packages.dhall"] - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - rm "packages.dhall" - writeTextFile "packages.dhall" $ "../packages.dhall" - spago ["test"] >>= shouldBeSuccess - testdir "output" `shouldReturn` True - - cd ".." - testdir "output" `shouldReturn` False + -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) + mkdir "lib-a" + cd "lib-a" + when usingEsModules $ do + cp "../../../fixtures/packages-prepare-0-15.dhall" "packages.dhall" + void $ dhall ["freeze", "packages.dhall"] + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["test"] >>= shouldBeSuccess + testdir "output" `shouldReturn` True + + cd ".." + testdir "output" `shouldReturn` False From eca612e908d54f21133bc629fc5f507fc4058c18 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 13 Apr 2022 13:56:21 -0500 Subject: [PATCH 72/82] Actually dedent tests in noSpacesInParentDir --- test/SpagoSpec.hs | 1228 ++++++++++++++++++++++----------------------- 1 file changed, 614 insertions(+), 614 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 39588cc24..3195d7cd5 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -50,736 +50,736 @@ spec = do noSpacesInParentDir :: Bool -> Spec noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do - describe "spago init" $ do + describe "spago init" $ do - it "Spago should have set up a project" $ do + it "Spago should have set up a project" $ do - spago ["init"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess - it "Spago should refuse to overwrite an existing project without -f" $ do + it "Spago should refuse to overwrite an existing project without -f" $ do - spago ["init"] >>= shouldBeSuccess - spago ["init"] >>= shouldBeFailure + spago ["init"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeFailure - it "Spago should not overwrite files when initing a project" $ do + it "Spago should not overwrite files when initing a project" $ do - mktree "src" - writeTextFile "src/Main.purs" "Something" - spago ["init"] >>= shouldBeSuccess - readTextFile "src/Main.purs" `shouldReturn` "Something" + mktree "src" + writeTextFile "src/Main.purs" "Something" + spago ["init"] >>= shouldBeSuccess + readTextFile "src/Main.purs" `shouldReturn` "Something" - it "Spago should always succeed in doing init with force" $ do + it "Spago should always succeed in doing init with force" $ do - spago ["init"] >>= shouldBeSuccess - spago ["init", "-f"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + spago ["init", "-f"] >>= shouldBeSuccess - it "Spago should import config from psc-package" $ do + it "Spago should import config from psc-package" $ do - writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" - spago ["init"] >>= shouldBeSuccess - cp "spago.dhall" "spago-psc-success.dhall" - checkFixture "spago-psc-success.dhall" + writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" + spago ["init"] >>= shouldBeSuccess + cp "spago.dhall" "spago-psc-success.dhall" + checkFixture "spago-psc-success.dhall" - it "Spago should not import dependencies that are not in the package-set" $ do + it "Spago should not import dependencies that are not in the package-set" $ do - writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\", \"foo\", \"bar\" ], \"set\": \"foo\", \"source\": \"bar\" }" - spago ["init", "-f"] >>= shouldBeSuccess - cp "spago.dhall" "spago-psc-failure.dhall" - checkFixture "spago-psc-failure.dhall" + writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\", \"foo\", \"bar\" ], \"set\": \"foo\", \"source\": \"bar\" }" + spago ["init", "-f"] >>= shouldBeSuccess + cp "spago.dhall" "spago-psc-failure.dhall" + checkFixture "spago-psc-failure.dhall" - it "Spago should import configs from Bower" $ do + it "Spago should import configs from Bower" $ do - shellStrictWithErr "git clone https://github.com/justinwoo/purescript-simple-json.git ." empty - shellStrictWithErr "git checkout v8.0.0" empty - spago ["init"] >>= shouldBeSuccess - mv "spago.dhall" "spago-bower-import.dhall" - checkFixture "spago-bower-import.dhall" + shellStrictWithErr "git clone https://github.com/justinwoo/purescript-simple-json.git ." empty + shellStrictWithErr "git checkout v8.0.0" empty + spago ["init"] >>= shouldBeSuccess + mv "spago.dhall" "spago-bower-import.dhall" + checkFixture "spago-bower-import.dhall" - it "Spago should strip comments from spago.dhall and packages.dhall" $ do + it "Spago should strip comments from spago.dhall and packages.dhall" $ do - spago ["init", "--no-comments"] >>= shouldBeSuccess + spago ["init", "--no-comments"] >>= shouldBeSuccess - cp "spago.dhall" "spago-no-comments.dhall" - checkFixture "spago-no-comments.dhall" + cp "spago.dhall" "spago-no-comments.dhall" + checkFixture "spago-no-comments.dhall" - -- We don't want fixture for packages.dhall to avoid having to maintain upstream package-set URL in fixture - dhallSource <- readTextFile "packages.dhall" - dhallSource `shouldNotSatisfy` (Text.isInfixOf "{-") -- comments not present - dhallSource `shouldSatisfy` (Text.isInfixOf "let upstream") -- some dhall stuff is present + -- We don't want fixture for packages.dhall to avoid having to maintain upstream package-set URL in fixture + dhallSource <- readTextFile "packages.dhall" + dhallSource `shouldNotSatisfy` (Text.isInfixOf "{-") -- comments not present + dhallSource `shouldSatisfy` (Text.isInfixOf "let upstream") -- some dhall stuff is present - it "Spago should use user-specified tag if it exists instead of latest release" $ do - spago ["init", "--tag", "psc-0.13.4-20191025"] >>= shouldBeSuccess + it "Spago should use user-specified tag if it exists instead of latest release" $ do + spago ["init", "--tag", "psc-0.13.4-20191025"] >>= shouldBeSuccess - mv "packages.dhall" "packages-older-tag.dhall" - checkFixture "packages-older-tag.dhall" + mv "packages.dhall" "packages-older-tag.dhall" + checkFixture "packages-older-tag.dhall" - it "Spago should use template/packages.dhall file if user-specified tag does not exist" $ do - spago ["init", "--tag", "does-not-exist"] >>= shouldBeSuccess + it "Spago should use template/packages.dhall file if user-specified tag does not exist" $ do + spago ["init", "--tag", "does-not-exist"] >>= shouldBeSuccess - originalPackage <- readTextFile "packages.dhall" - let [originalPackageSetUrl] - = map Text.strip - $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") - $ Text.lines originalPackage + originalPackage <- readTextFile "packages.dhall" + let [originalPackageSetUrl] + = map Text.strip + $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") + $ Text.lines originalPackage - mv "packages.dhall" "original-packages.dhall" + mv "packages.dhall" "original-packages.dhall" - spago ["init", "--force"] >>= shouldBeSuccess + spago ["init", "--force"] >>= shouldBeSuccess - templatePackages <- readTextFile "../../templates/packages.dhall" - let [templatePackageSetUrl] - = map Text.strip - $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") - $ Text.lines templatePackages + templatePackages <- readTextFile "../../templates/packages.dhall" + let [templatePackageSetUrl] + = map Text.strip + $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") + $ Text.lines templatePackages - originalPackageSetUrl `shouldBe` templatePackageSetUrl + originalPackageSetUrl `shouldBe` templatePackageSetUrl - describe "spago install" $ do + describe "spago install" $ do - it "Subsequent installs should succeed after failed install" $ do + it "Subsequent installs should succeed after failed install" $ do - spago ["init"] >>= shouldBeSuccess - -- Run `install` once and kill it soon to simulate failure - runFor 5000 "spago" ["install", "-j", "3"] - -- Sleep for some time, as the above might take time to cleanup old processes - threadDelay 1000000 - spago ["install", "-j", "10"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + -- Run `install` once and kill it soon to simulate failure + runFor 5000 "spago" ["install", "-j", "3"] + -- Sleep for some time, as the above might take time to cleanup old processes + threadDelay 1000000 + spago ["install", "-j", "10"] >>= shouldBeSuccess - it "Spago should warn that config was not changed, when trying to install package already present in project dependencies" $ do + it "Spago should warn that config was not changed, when trying to install package already present in project dependencies" $ do - spago ["init"] >>= shouldBeSuccess - spago ["install"] >>= shouldBeSuccess - spago ["install", "effect"] >>= shouldBeSuccessStderr "spago-install-existing-dep-stderr.txt" + spago ["init"] >>= shouldBeSuccess + spago ["install"] >>= shouldBeSuccess + spago ["install", "effect"] >>= shouldBeSuccessStderr "spago-install-existing-dep-stderr.txt" - it "Spago should strip 'purescript-' prefix and give warning if package without prefix is present in package set" $ do + it "Spago should strip 'purescript-' prefix and give warning if package without prefix is present in package set" $ do - spago ["init"] >>= shouldBeSuccess - spago ["install", "safe-coerce"] >>= shouldBeSuccess - spago ["install", "purescript-newtype"] >>= shouldBeSuccessStderr "spago-install-purescript-prefix-stderr.txt" - -- dep added without "purescript-" prefix - checkFileHasInfix "spago.dhall" "\"newtype\"" + spago ["init"] >>= shouldBeSuccess + spago ["install", "safe-coerce"] >>= shouldBeSuccess + spago ["install", "purescript-newtype"] >>= shouldBeSuccessStderr "spago-install-purescript-prefix-stderr.txt" + -- dep added without "purescript-" prefix + checkFileHasInfix "spago.dhall" "\"newtype\"" - it "Spago should be able to add dependencies" $ do + it "Spago should be able to add dependencies" $ do - writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" - spago ["init"] >>= shouldBeSuccess - spago ["-j 10", "install", "simple-json", "foreign"] >>= shouldBeSuccess - mv "spago.dhall" "spago-install-success.dhall" - checkFixture "spago-install-success.dhall" + writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" + spago ["init"] >>= shouldBeSuccess + spago ["-j 10", "install", "simple-json", "foreign"] >>= shouldBeSuccess + mv "spago.dhall" "spago-install-success.dhall" + checkFixture "spago-install-success.dhall" - it "Spago should not add dependencies that are not in the package set" $ do + it "Spago should not add dependencies that are not in the package set" $ do - writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" - spago ["init"] >>= shouldBeSuccess - spago ["install", "foo", "bar"] >>= shouldBeFailureStderr "missing-dependencies.txt" - mv "spago.dhall" "spago-install-failure.dhall" - checkFixture "spago-install-failure.dhall" + writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" + spago ["init"] >>= shouldBeSuccess + spago ["install", "foo", "bar"] >>= shouldBeFailureStderr "missing-dependencies.txt" + mv "spago.dhall" "spago-install-failure.dhall" + checkFixture "spago-install-failure.dhall" - it "Spago should not allow circular dependencies" $ do + it "Spago should not allow circular dependencies" $ do - writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" - spago ["init"] >>= shouldBeSuccess - writeTextFile "spago.dhall" "{- Welcome to a Spago project! You can edit this file as you like. -} { name = \"my-project\" , dependencies = [ \"effect\", \"console\", \"a\", \"b\" ] , packages = ./packages.dhall // { a = { version = \"a1\", dependencies = [\"b\"], repo = \"https://github.com/fake/fake.git\" }, b = { version = \"b1\", dependencies = [\"a\"], repo = \"https://github.com/fake/fake.git\" } } }" - spago ["install"] >>= shouldBeFailureStderr "circular-dependencies.txt" + writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }" + spago ["init"] >>= shouldBeSuccess + writeTextFile "spago.dhall" "{- Welcome to a Spago project! You can edit this file as you like. -} { name = \"my-project\" , dependencies = [ \"effect\", \"console\", \"a\", \"b\" ] , packages = ./packages.dhall // { a = { version = \"a1\", dependencies = [\"b\"], repo = \"https://github.com/fake/fake.git\" }, b = { version = \"b1\", dependencies = [\"a\"], repo = \"https://github.com/fake/fake.git\" } } }" + spago ["install"] >>= shouldBeFailureStderr "circular-dependencies.txt" - it "Spago should be able to install a package in the set from a commit hash" $ do + it "Spago should be able to install a package in the set from a commit hash" $ do - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packagesBase.dhall" - writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { simple-json = pkgs.simple-json // { version = \"d45590f493d68baae174b2d3062d502c0cc4c265\" } }" - spago ["install", "simple-json"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packagesBase.dhall" + writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { simple-json = pkgs.simple-json // { version = \"d45590f493d68baae174b2d3062d502c0cc4c265\" } }" + spago ["install", "simple-json"] >>= shouldBeSuccess - it "Spago should be able to install a package version by branch name with / in it" $ do + it "Spago should be able to install a package version by branch name with / in it" $ do - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packagesBase.dhall" - writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { metadata_ = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/purescript-metadata.git\", version = \"spago-test/branch-with-slash\" }}" - spago ["install", "metadata_"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packagesBase.dhall" + writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { metadata_ = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/purescript-metadata.git\", version = \"spago-test/branch-with-slash\" }}" + spago ["install", "metadata_"] >>= shouldBeSuccess - it "Spago should be able to install a package not in the set from a commit hash" $ do + it "Spago should be able to install a package not in the set from a commit hash" $ do - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packagesBase.dhall" - writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { spago = { dependencies = [\"prelude\"], repo = \"https://github.com/purescript/spago.git\", version = \"cbdbbf8f8771a7e43f04b18cdefffbcb0f03a990\" }}" - spago ["install", "spago"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packagesBase.dhall" + writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { spago = { dependencies = [\"prelude\"], repo = \"https://github.com/purescript/spago.git\", version = \"cbdbbf8f8771a7e43f04b18cdefffbcb0f03a990\" }}" + spago ["install", "spago"] >>= shouldBeSuccess - it "Spago should not be able to install a package from a not-existing commit hash" $ do + it "Spago should not be able to install a package from a not-existing commit hash" $ do - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packagesBase.dhall" - writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { spago = { dependencies = [\"prelude\"], repo = \"https://github.com/purescript/spago.git\", version = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" }}" - spago ["install", "spago"] >>= shouldBeFailure + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packagesBase.dhall" + writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { spago = { dependencies = [\"prelude\"], repo = \"https://github.com/purescript/spago.git\", version = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" }}" + spago ["install", "spago"] >>= shouldBeFailure - it "Spago should be able to update dependencies in an alternative config" $ do + it "Spago should be able to update dependencies in an alternative config" $ do - spago ["init"] >>= shouldBeSuccess - writeTextFile "alternative1.dhall" "./spago.dhall // {dependencies = [\"prelude\"]}" - spago ["-x", "alternative1.dhall", "install", "simple-json"] >>= shouldBeSuccess - checkFixture "alternative1.dhall" + spago ["init"] >>= shouldBeSuccess + writeTextFile "alternative1.dhall" "./spago.dhall // {dependencies = [\"prelude\"]}" + spago ["-x", "alternative1.dhall", "install", "simple-json"] >>= shouldBeSuccess + checkFixture "alternative1.dhall" - it "Spago should fail when the alternate config file doesn't exist" $ do - spago ["init"] >>= shouldBeSuccess - spago ["install", "-x", "test.dhall"] >>= shouldBeFailureStderr "alternate-config-missing.txt" + it "Spago should fail when the alternate config file doesn't exist" $ do + spago ["init"] >>= shouldBeSuccess + spago ["install", "-x", "test.dhall"] >>= shouldBeFailureStderr "alternate-config-missing.txt" - it "Spago should install successfully when the config file is in another directory" $ do + it "Spago should install successfully when the config file is in another directory" $ do - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - mkdir "nested" - writeTextFile "./nested/spago.dhall" "{ name = \"nested\", sources = [ \"src/**/*.purs\" ], dependencies = [ \"effect\", \"console\", ] , packages = ../packages.dhall }" - spago ["install", "--config", "./nested/spago.dhall"] >>= shouldBeSuccess + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + mkdir "nested" + writeTextFile "./nested/spago.dhall" "{ name = \"nested\", sources = [ \"src/**/*.purs\" ], dependencies = [ \"effect\", \"console\", ] , packages = ../packages.dhall }" + spago ["install", "--config", "./nested/spago.dhall"] >>= shouldBeSuccess - it "Spago should not change the alternative config if it does not change dependencies" $ do + it "Spago should not change the alternative config if it does not change dependencies" $ do - spago ["init"] >>= shouldBeSuccess - writeTextFile "alternative2.dhall" "./spago.dhall // { sources = [ \"src/**/*.purs\" ] }\n" - spago ["-x", "alternative2.dhall", "install", "simple-json"] >>= shouldBeSuccess - spago ["-x", "alternative2.dhall", "install", "simple-json"] >>= shouldBeSuccessStderr "alternative2install-stderr.txt" - checkFixture "alternative2.dhall" + spago ["init"] >>= shouldBeSuccess + writeTextFile "alternative2.dhall" "./spago.dhall // { sources = [ \"src/**/*.purs\" ] }\n" + spago ["-x", "alternative2.dhall", "install", "simple-json"] >>= shouldBeSuccess + spago ["-x", "alternative2.dhall", "install", "simple-json"] >>= shouldBeSuccessStderr "alternative2install-stderr.txt" + checkFixture "alternative2.dhall" - it "Spago should install successfully when there are local dependencies sharing the same packages.dhall" $ do + it "Spago should install successfully when there are local dependencies sharing the same packages.dhall" $ do - -- Create local 'lib-a' package that depends on lib-c - mkdir "lib-a" - cd "lib-a" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-a\", dependencies = [\"console\", \"effect\", \"prelude\", \"lib-c\"], packages = ../packages.dhall }" - cd ".." + -- Create local 'lib-a' package that depends on lib-c + mkdir "lib-a" + cd "lib-a" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-a\", dependencies = [\"console\", \"effect\", \"prelude\", \"lib-c\"], packages = ../packages.dhall }" + cd ".." - -- Create local 'lib-b' package that has its dependencies in a separate file - mkdir "lib-b" - cd "lib-b" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-b\", dependencies = ./spago-deps.dhall, packages = ../packages.dhall }" - writeTextFile "spago-deps.dhall" "[\"console\", \"effect\", \"prelude\"]" - cd ".." + -- Create local 'lib-b' package that has its dependencies in a separate file + mkdir "lib-b" + cd "lib-b" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-b\", dependencies = ./spago-deps.dhall, packages = ../packages.dhall }" + writeTextFile "spago-deps.dhall" "[\"console\", \"effect\", \"prelude\"]" + cd ".." - -- Create local 'lib-c' package - mkdir "lib-c" - cd "lib-c" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-c\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ../packages.dhall }" - cd ".." + -- Create local 'lib-c' package + mkdir "lib-c" + cd "lib-c" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-c\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ../packages.dhall }" + cd ".." - -- Create 'app' package that depends on 'lib-a' and 'lib-b' - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" "{ name = \"app\", dependencies = [\"console\", \"effect\", \"prelude\", \"lib-a\", \"lib-b\"], packages = ./packages.dhall }" - packageDhall <- readTextFile "packages.dhall" - writeTextFile "packages.dhall" $ packageDhall <> " // { lib-a = ./lib-a/spago.dhall as Location, lib-b = ./lib-b/spago.dhall as Location, lib-c = ./lib-c/spago.dhall as Location }" - - spago ["install"] >>= shouldBeSuccess - - it "Spago should not warn about freezing remote imports if they can be located from spago.dhall" $ do - - spago ["init"] >>= shouldBeSuccess - -- Do an initial installation so that it's easier to compare subsequent output - spago ["install"] >>= shouldBeSuccess + -- Create 'app' package that depends on 'lib-a' and 'lib-b' + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" "{ name = \"app\", dependencies = [\"console\", \"effect\", \"prelude\", \"lib-a\", \"lib-b\"], packages = ./packages.dhall }" + packageDhall <- readTextFile "packages.dhall" + writeTextFile "packages.dhall" $ packageDhall <> " // { lib-a = ./lib-a/spago.dhall as Location, lib-b = ./lib-b/spago.dhall as Location, lib-c = ./lib-c/spago.dhall as Location }" - mkdir "elsewhere" - writeTextFile "elsewhere/a.dhall" "let p = ./b.dhall in p" - mv "packages.dhall" "elsewhere/b.dhall" - spagoDhall <- readTextFile "spago.dhall" - writeTextFile "spago.dhall" $ Text.replace "./packages.dhall" "./elsewhere/a.dhall" spagoDhall - spago ["install"] >>= shouldBeSuccessStderr "ensure-frozen-success.txt" + spago ["install"] >>= shouldBeSuccess - describe "spago sources" $ do - - it "Spago should print both dependencies and project sources" $ do + it "Spago should not warn about freezing remote imports if they can be located from spago.dhall" $ do - spago ["init"] >>= shouldBeSuccess - spago ["sources"] >>= shouldBeSuccessOutput "sources-output.txt" - - -- -- This is currently commented because it requires a GitHub token and Travis makes it hard to do it securely - -- describe "spago login" $ do - -- - -- it "Spago should login correctly" $ do - -- - -- spago ["login"] >>= shouldBeSuccessOutput "login-output.txt" - - describe "spago build" $ do - - it "Spago should build successfully" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - - it "Spago should pass options to purs" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["build", "--purs-args", "-o myOutput"] >>= shouldBeSuccess - testdir "myOutput" `shouldReturn` True - - it "Spago should pass multiple options to purs" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["build", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess - testdir "myOutput" `shouldReturn` True - - it "Spago should build successfully with sources included from custom path" $ do - - spago ["init"] >>= shouldBeSuccess - mkdir "another_source_path" - mv "src/Main.purs" "another_source_path/Main.purs" - spago ["build", "--path", "another_source_path/*.purs"] >>= shouldBeSuccess - - it "Spago should not install packages when passing the --no-install flag" $ do - - spago ["init"] >>= shouldBeSuccess - spago ["build", "--no-install"] >>= shouldBeFailure - spago ["install"] >>= shouldBeSuccess - spago ["build", "--no-install"] >>= shouldBeSuccess - - it "Spago should add sources to config when key is missing" $ do - - configV1 <- readFixture "spago-configV1.dhall" - spago ["init"] >>= shouldBeSuccess - -- Replace initial config with the old config format (without 'sources') - mv "spago.dhall" "spago-old.dhall" - writeTextFile "spago.dhall" configV1 - - spago ["install"] >>= shouldBeSuccess - mv "spago.dhall" "spago-configV2.dhall" - checkFixture "spago-configV2.dhall" - - it "Spago should create a local output folder" $ do - - -- Create root-level packages.dhall - mkdir "monorepo" - cd "monorepo" + spago ["init"] >>= shouldBeSuccess + -- Do an initial installation so that it's easier to compare subsequent output + spago ["install"] >>= shouldBeSuccess + + mkdir "elsewhere" + writeTextFile "elsewhere/a.dhall" "let p = ./b.dhall in p" + mv "packages.dhall" "elsewhere/b.dhall" + spagoDhall <- readTextFile "spago.dhall" + writeTextFile "spago.dhall" $ Text.replace "./packages.dhall" "./elsewhere/a.dhall" spagoDhall + spago ["install"] >>= shouldBeSuccessStderr "ensure-frozen-success.txt" + + describe "spago sources" $ do + + it "Spago should print both dependencies and project sources" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["sources"] >>= shouldBeSuccessOutput "sources-output.txt" + + -- -- This is currently commented because it requires a GitHub token and Travis makes it hard to do it securely + -- describe "spago login" $ do + -- + -- it "Spago should login correctly" $ do + -- + -- spago ["login"] >>= shouldBeSuccessOutput "login-output.txt" + + describe "spago build" $ do + + it "Spago should build successfully" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + + it "Spago should pass options to purs" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["build", "--purs-args", "-o myOutput"] >>= shouldBeSuccess + testdir "myOutput" `shouldReturn` True + + it "Spago should pass multiple options to purs" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["build", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess + testdir "myOutput" `shouldReturn` True + + it "Spago should build successfully with sources included from custom path" $ do + + spago ["init"] >>= shouldBeSuccess + mkdir "another_source_path" + mv "src/Main.purs" "another_source_path/Main.purs" + spago ["build", "--path", "another_source_path/*.purs"] >>= shouldBeSuccess + + it "Spago should not install packages when passing the --no-install flag" $ do + + spago ["init"] >>= shouldBeSuccess + spago ["build", "--no-install"] >>= shouldBeFailure + spago ["install"] >>= shouldBeSuccess + spago ["build", "--no-install"] >>= shouldBeSuccess + + it "Spago should add sources to config when key is missing" $ do + + configV1 <- readFixture "spago-configV1.dhall" + spago ["init"] >>= shouldBeSuccess + -- Replace initial config with the old config format (without 'sources') + mv "spago.dhall" "spago-old.dhall" + writeTextFile "spago.dhall" configV1 + + spago ["install"] >>= shouldBeSuccess + mv "spago.dhall" "spago-configV2.dhall" + checkFixture "spago-configV2.dhall" + + it "Spago should create a local output folder" $ do + + -- Create root-level packages.dhall + mkdir "monorepo" + cd "monorepo" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + + -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) + mkdir "lib-a" + cd "lib-a" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["build"] >>= shouldBeSuccess + testdir "output" `shouldReturn` True + + cd ".." + testdir "output" `shouldReturn` False + + it "Spago should use the main packages.dhall even when another packages.dhall is further up the tree" $ do + + -- Create root-level packages.dhall that directs to middle one + mkdir "monorepo-1" + cd "monorepo-1" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "./monorepo-2/packages.dhall" + + -- Create local 'monorepo-2' package that is the real root + mkdir "monorepo-2" + cd "monorepo-2" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + spago ["build"] >>= shouldBeSuccess + testdir "output" `shouldReturn` True + + -- Create local 'monorepo-3' package that uses packages.dhall on top level + mkdir "monorepo-3" + cd "monorepo-3" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../../packages.dhall" + spago ["build"] >>= shouldBeSuccess + testdir "output" `shouldReturn` True + + cd ".." + testdir "output" `shouldReturn` True + + cd ".." + testdir "output" `shouldReturn` False + + it "Spago should find the middle packages.dhall even when another file is further up the tree" $ do + + -- Create root-level module to confuse things + mkdir "monorepo-root" + cd "monorepo-root" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-extra\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + + -- get rid of duplicate Main module + cd "src" + rm "Main.purs" + writeTextFile "Main.purs" $ "module OtherMain where \n import Prelude\n import Effect\n main :: Effect Unit\n main = pure unit" + cd ".." + + -- create real root + mkdir "subfolder" + cd "subfolder" + spago ["init"] >>= shouldBeSuccess + packageDhall <- readTextFile "packages.dhall" + writeTextFile "packages.dhall" $ packageDhall <> " // { lib-extra = ../spago.dhall as Location }" + + -- Create local 'lib-a' package that uses packages.dhall in middle folder + mkdir "lib-a" + cd "lib-a" + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"lib-extra\",\"console\", \"effect\", \"prelude\"], packages = ../packages.dhall }" + rm "packages.dhall" + spago ["build"] >>= shouldBeSuccess + + -- don't use nested folder + testdir "output" `shouldReturn` True + + -- use middle one + cd ".." + testdir "output" `shouldReturn` False + + -- not the trick root folder + cd ".." + testdir "output" `shouldReturn` False + + describe "import checking" $ do + + it "Spago should fail on direct project imports from transitive dependencies" $ do spago ["init"] >>= shouldBeSuccess rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"check-imports\", dependencies = [\"effect\", \"lists\"], packages = ./packages.dhall }" + rm "src/Main.purs" + writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nimport Data.Maybe\nimport Data.List\nmain = unit" + rm "test/Main.purs" + spago ["build"] + spago ["--no-psa", "build"] >>= shouldBeFailureStderr "check-direct-import-transitive-dependency.txt" - -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) - mkdir "lib-a" - cd "lib-a" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - rm "packages.dhall" - writeTextFile "packages.dhall" $ "../packages.dhall" - spago ["build"] >>= shouldBeSuccess - testdir "output" `shouldReturn` True - - cd ".." - testdir "output" `shouldReturn` False - - it "Spago should use the main packages.dhall even when another packages.dhall is further up the tree" $ do - - -- Create root-level packages.dhall that directs to middle one - mkdir "monorepo-1" - cd "monorepo-1" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - rm "packages.dhall" - writeTextFile "packages.dhall" $ "./monorepo-2/packages.dhall" - - -- Create local 'monorepo-2' package that is the real root - mkdir "monorepo-2" - cd "monorepo-2" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - spago ["build"] >>= shouldBeSuccess - testdir "output" `shouldReturn` True - - -- Create local 'monorepo-3' package that uses packages.dhall on top level - mkdir "monorepo-3" - cd "monorepo-3" - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - rm "packages.dhall" - writeTextFile "packages.dhall" $ "../../packages.dhall" - spago ["build"] >>= shouldBeSuccess - testdir "output" `shouldReturn` True - - cd ".." - testdir "output" `shouldReturn` True - - cd ".." - testdir "output" `shouldReturn` False - - it "Spago should find the middle packages.dhall even when another file is further up the tree" $ do - - -- Create root-level module to confuse things - mkdir "monorepo-root" - cd "monorepo-root" + it "Spago should warn on unused dependencies" $ do spago ["init"] >>= shouldBeSuccess rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-extra\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - - -- get rid of duplicate Main module - cd "src" - rm "Main.purs" - writeTextFile "Main.purs" $ "module OtherMain where \n import Prelude\n import Effect\n main :: Effect Unit\n main = pure unit" - cd ".." - - -- create real root - mkdir "subfolder" - cd "subfolder" - spago ["init"] >>= shouldBeSuccess - packageDhall <- readTextFile "packages.dhall" - writeTextFile "packages.dhall" $ packageDhall <> " // { lib-extra = ../spago.dhall as Location }" + writeTextFile "spago.dhall" $ "{ name = \"check-imports\", dependencies = [\"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "src/Main.purs" + writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nmain :: Unit\nmain = unit" + rm "test/Main.purs" + spago ["build"] + spago ["--no-psa", "build"] >>= shouldBeSuccessStderr "check-unused-dependency.txt" - -- Create local 'lib-a' package that uses packages.dhall in middle folder - mkdir "lib-a" - cd "lib-a" + it "Spago should not warn on unused dependencies when building deps-only" $ do spago ["init"] >>= shouldBeSuccess rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"lib-extra\",\"console\", \"effect\", \"prelude\"], packages = ../packages.dhall }" - rm "packages.dhall" - spago ["build"] >>= shouldBeSuccess - - -- don't use nested folder - testdir "output" `shouldReturn` True - - -- use middle one - cd ".." - testdir "output" `shouldReturn` False - - -- not the trick root folder - cd ".." - testdir "output" `shouldReturn` False - - describe "import checking" $ do - - it "Spago should fail on direct project imports from transitive dependencies" $ do - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"check-imports\", dependencies = [\"effect\", \"lists\"], packages = ./packages.dhall }" - rm "src/Main.purs" - writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nimport Data.Maybe\nimport Data.List\nmain = unit" - rm "test/Main.purs" - spago ["build"] - spago ["--no-psa", "build"] >>= shouldBeFailureStderr "check-direct-import-transitive-dependency.txt" - - it "Spago should warn on unused dependencies" $ do - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"check-imports\", dependencies = [\"effect\", \"prelude\"], packages = ./packages.dhall }" - rm "src/Main.purs" - writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nmain :: Unit\nmain = unit" - rm "test/Main.purs" - spago ["build"] - spago ["--no-psa", "build"] >>= shouldBeSuccessStderr "check-unused-dependency.txt" - - it "Spago should not warn on unused dependencies when building deps-only" $ do - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"check-imports\", dependencies = [\"effect\", \"prelude\"], packages = ./packages.dhall }" - rm "src/Main.purs" - writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nmain :: Unit\nmain = unit" - rm "test/Main.purs" - spago ["build"] - spago ["--no-psa", "build", "--deps-only"] >>= shouldBeSuccessStderr "spago-build-succeeded-stderr.txt" - - describe "alternate backend" $ do - - it "Spago should use alternate backend if option is specified" $ do - configWithBackend <- readFixture "spago-configWithBackend.dhall" - spago ["init"] >>= shouldBeSuccess - mv "spago.dhall" "spago-old.dhall" - writeTextFile "spago.dhall" configWithBackend - - -- Blocked by https://github.com/purescript/purescript/issues/3743 - -- spago ["-j", "5", "build"] >>= shouldBeSuccess - -- checkFixture "alternate-backend-output.txt" - - it "Passing `--codegen corefn` with backend option should fail" $ do - configWithBackend <- readFixture "spago-configWithBackend.dhall" - spago ["init"] >>= shouldBeSuccess - mv "spago.dhall" "spago-old.dhall" - writeTextFile "spago.dhall" configWithBackend - - -- Blocked by https://github.com/purescript/purescript/issues/3743 - -- spago ["-j", "5", "build"] >>= shouldBeSuccess - -- spago ["build", "--purs-args", "--codegen", "--purs-args", "corefn"] >>= shouldBeFailureOutput "codegen-opt-with-backend.txt" - -- spago ["build", "--purs-args", "--codegen", "--purs-args", "docs"] >>= shouldBeFailureOutput "codegen-opt-with-backend.txt" - - it "Spago should run a before command" $ do - - spago ["init"] >>= shouldBeSuccess - - dir <- pwd - let dumpFile = dir "testOutput" - spago ["build", "--before", "echo before>> " <> (Text.pack $ encodeString dumpFile)] >>= shouldBeSuccess - test <- readTextFile dumpFile - test `shouldBe` "before\n" - - it "Spago should run a then command" $ do - - spago ["init"] >>= shouldBeSuccess - - dir <- pwd - let dumpFile = dir "testOutput" - spago [ "build" - , "--then", "echo then>> " <> ( Text.pack $ encodeString dumpFile ) - , "--else", "echo else>> " <> ( Text.pack $ encodeString dumpFile ) - ] >>= shouldBeSuccess - test <- readTextFile dumpFile - test `shouldBe` "then\n" + writeTextFile "spago.dhall" $ "{ name = \"check-imports\", dependencies = [\"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "src/Main.purs" + writeTextFile "src/Main.purs" "module Main where\nimport Prelude\nmain :: Unit\nmain = unit" + rm "test/Main.purs" + spago ["build"] + spago ["--no-psa", "build", "--deps-only"] >>= shouldBeSuccessStderr "spago-build-succeeded-stderr.txt" - it "Spago should run a before command before a then command" $ do + describe "alternate backend" $ do + it "Spago should use alternate backend if option is specified" $ do + configWithBackend <- readFixture "spago-configWithBackend.dhall" spago ["init"] >>= shouldBeSuccess + mv "spago.dhall" "spago-old.dhall" + writeTextFile "spago.dhall" configWithBackend - dir <- pwd - let dumpFile = dir "testOutput" - spago [ "build" - , "--before", "echo before>> " <> Text.pack (encodeString dumpFile) - , "--then", "echo then>> " <> Text.pack (encodeString dumpFile) - ] >>= shouldBeSuccess - test <- readTextFile dumpFile - test `shouldBe` "before\nthen\n" - - it "Spago should run an else command if there is an error in the build" $ do + -- Blocked by https://github.com/purescript/purescript/issues/3743 + -- spago ["-j", "5", "build"] >>= shouldBeSuccess + -- checkFixture "alternate-backend-output.txt" + it "Passing `--codegen corefn` with backend option should fail" $ do + configWithBackend <- readFixture "spago-configWithBackend.dhall" spago ["init"] >>= shouldBeSuccess + mv "spago.dhall" "spago-old.dhall" + writeTextFile "spago.dhall" configWithBackend + + -- Blocked by https://github.com/purescript/purescript/issues/3743 + -- spago ["-j", "5", "build"] >>= shouldBeSuccess + -- spago ["build", "--purs-args", "--codegen", "--purs-args", "corefn"] >>= shouldBeFailureOutput "codegen-opt-with-backend.txt" + -- spago ["build", "--purs-args", "--codegen", "--purs-args", "docs"] >>= shouldBeFailureOutput "codegen-opt-with-backend.txt" - dir <- pwd - let dumpFile = dir "testOutput" - rm "src/Main.purs" - writeTextFile "src/Main.purs" "Invalid Purescript code" - spago [ "build" - , "--then", "echo then>> " <> ( Text.pack $ encodeString dumpFile ) - , "--else", "echo else>> " <> ( Text.pack $ encodeString dumpFile ) - ] >>= shouldBeFailure - test <- readTextFile dumpFile - test `shouldBe` "else\n" - - - it "Spago should run an else command if there is an error in the run file" $ do + it "Spago should run a before command" $ do + + spago ["init"] >>= shouldBeSuccess + + dir <- pwd + let dumpFile = dir "testOutput" + spago ["build", "--before", "echo before>> " <> (Text.pack $ encodeString dumpFile)] >>= shouldBeSuccess + test <- readTextFile dumpFile + test `shouldBe` "before\n" - spago ["init"] >>= shouldBeSuccess - spago ["install", "exceptions"] >>= shouldBeSuccess + it "Spago should run a then command" $ do - 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" + spago ["init"] >>= shouldBeSuccess + + dir <- pwd + let dumpFile = dir "testOutput" + spago [ "build" + , "--then", "echo then>> " <> ( Text.pack $ encodeString dumpFile ) + , "--else", "echo else>> " <> ( Text.pack $ encodeString dumpFile ) + ] >>= shouldBeSuccess + test <- readTextFile dumpFile + test `shouldBe` "then\n" + + it "Spago should run a before command before a then command" $ do + + spago ["init"] >>= shouldBeSuccess + + dir <- pwd + let dumpFile = dir "testOutput" + spago [ "build" + , "--before", "echo before>> " <> Text.pack (encodeString dumpFile) + , "--then", "echo then>> " <> Text.pack (encodeString dumpFile) + ] >>= shouldBeSuccess + test <- readTextFile dumpFile + test `shouldBe` "before\nthen\n" + + it "Spago should run an else command if there is an error in the build" $ do + + spago ["init"] >>= shouldBeSuccess + + dir <- pwd + let dumpFile = dir "testOutput" + rm "src/Main.purs" + writeTextFile "src/Main.purs" "Invalid Purescript code" + spago [ "build" + , "--then", "echo then>> " <> ( Text.pack $ encodeString dumpFile ) + , "--else", "echo else>> " <> ( Text.pack $ encodeString dumpFile ) + ] >>= shouldBeFailure + 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 - it "Spago should run multiple commands in order" $ do + dir <- pwd + let dumpFile = dir "testOutput" + spago [ "build" + , "--before", "echo before1>> " <> ( Text.pack $ encodeString dumpFile ) + , "--before", "echo before2>> " <> ( Text.pack $ encodeString dumpFile ) + , "--then", "echo then1>> " <> ( Text.pack $ encodeString dumpFile ) + , "--then", "echo then2>> " <> ( Text.pack $ encodeString dumpFile ) + ] >>= shouldBeSuccess + test <- readTextFile dumpFile + test `shouldBe` "before1\nbefore2\nthen1\nthen2\n" - spago ["init"] >>= shouldBeSuccess + it "Spago should fail the build if a before command fails" $ do - dir <- pwd - let dumpFile = dir "testOutput" - spago [ "build" - , "--before", "echo before1>> " <> ( Text.pack $ encodeString dumpFile ) - , "--before", "echo before2>> " <> ( Text.pack $ encodeString dumpFile ) - , "--then", "echo then1>> " <> ( Text.pack $ encodeString dumpFile ) - , "--then", "echo then2>> " <> ( Text.pack $ encodeString dumpFile ) - ] >>= shouldBeSuccess - test <- readTextFile dumpFile - test `shouldBe` "before1\nbefore2\nthen1\nthen2\n" + spago ["init"] >>= shouldBeSuccess + spago [ "build" + , "--before", "exit 1" + ] >>= shouldBeFailure - it "Spago should fail the build if a before command fails" $ do + it "Spago should fail the build if a then command fails" $ do - spago ["init"] >>= shouldBeSuccess - spago [ "build" - , "--before", "exit 1" - ] >>= shouldBeFailure + spago ["init"] >>= shouldBeSuccess + spago [ "build" + , "--then", "exit 1" + ] >>= shouldBeFailure - it "Spago should fail the build if a then command fails" $ do + it "Spago should still fail the build if an else command fails" $ do - spago ["init"] >>= shouldBeSuccess - spago [ "build" - , "--then", "exit 1" - ] >>= shouldBeFailure + spago ["init"] >>= shouldBeSuccess + rm "src/Main.purs" + writeTextFile "src/Main.purs" "Invalid Purescript code" + spago [ "build" + , "--else", "exit 1" + ] >>= shouldBeFailure - it "Spago should still fail the build if an else command fails" $ do + describe "spago upgrade-set" $ do - spago ["init"] >>= shouldBeSuccess - rm "src/Main.purs" - writeTextFile "src/Main.purs" "Invalid Purescript code" - spago [ "build" - , "--else", "exit 1" - ] >>= shouldBeFailure + it "Spago should migrate package-sets from src/packages.dhall to the released one" $ do - describe "spago upgrade-set" $ do + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packages-expected.dhall" + packages <- readTextFile "packages-expected.dhall" + let [packageSetUrl] + = map Text.strip + $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") + $ Text.lines packages + writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" + spago ["-v", "upgrade-set"] >>= shouldBeSuccess + newPackages <- Text.strip . head . Text.lines <$> readTextFile "packages.dhall" + newPackages `shouldBe` packageSetUrl + + it "Spago should migrate a package set from an alternative repository from src/packages.dhall" $ do - it "Spago should migrate package-sets from src/packages.dhall to the released one" $ do + spago ["init"] >>= shouldBeSuccess + writeTextFile "packages.dhall" "https://github.com/purerl/package-sets/releases/download/erl-0.13.6-20200713/packages.dhall sha256:6b1dcfe05ee95229b654462bf5d36864f9a0dfbc2ac120192aaa25f9fceb9967" + spago ["-v", "upgrade-set"] >>= shouldBeSuccess + newPackages <- Text.strip <$> readTextFile "packages.dhall" + newPackages `shouldNotBe` "https://github.com/purerl/package-sets/releases/download/erl-0.13.6-20200713/packages.dhall" + newPackages `shouldSatisfy` Text.isPrefixOf "https://github.com/purerl/package-sets/releases/download" + + it "Spago should migrate package-set from src/packages.dhall to the user-specified one if it exists" $ do + -- initialize the project, so that it uses latest package set release + spago ["init"] >>= shouldBeSuccess - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packages-expected.dhall" - packages <- readTextFile "packages-expected.dhall" - let [packageSetUrl] - = map Text.strip - $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") - $ Text.lines packages - writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" - spago ["-v", "upgrade-set"] >>= shouldBeSuccess - newPackages <- Text.strip . head . Text.lines <$> readTextFile "packages.dhall" - newPackages `shouldBe` packageSetUrl - - it "Spago should migrate a package set from an alternative repository from src/packages.dhall" $ do + spago ["-v", "upgrade-set", "--tag", "psc-0.13.4-20191025"] >>= shouldBeSuccess + mv "packages.dhall" "packages-older-tag.dhall" + checkFixture "packages-older-tag.dhall" - spago ["init"] >>= shouldBeSuccess - writeTextFile "packages.dhall" "https://github.com/purerl/package-sets/releases/download/erl-0.13.6-20200713/packages.dhall sha256:6b1dcfe05ee95229b654462bf5d36864f9a0dfbc2ac120192aaa25f9fceb9967" - spago ["-v", "upgrade-set"] >>= shouldBeSuccess - newPackages <- Text.strip <$> readTextFile "packages.dhall" - newPackages `shouldNotBe` "https://github.com/purerl/package-sets/releases/download/erl-0.13.6-20200713/packages.dhall" - newPackages `shouldSatisfy` Text.isPrefixOf "https://github.com/purerl/package-sets/releases/download" - - it "Spago should migrate package-set from src/packages.dhall to the user-specified one if it exists" $ do - -- initialize the project, so that it uses latest package set release - spago ["init"] >>= shouldBeSuccess + it "Spago should not migrate to the user-specified package-set if does not exist" $ do + -- initialize the project, so that it uses latest package set release + spago ["init"] >>= shouldBeSuccess + + originalPackages <- readTextFile "packages.dhall" + let [originalPackageSetUrl] + = map Text.strip + $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") + $ Text.lines originalPackages - spago ["-v", "upgrade-set", "--tag", "psc-0.13.4-20191025"] >>= shouldBeSuccess - mv "packages.dhall" "packages-older-tag.dhall" - checkFixture "packages-older-tag.dhall" + spago ["-v", "upgrade-set", "--tag", "does-not-exist"] >>= shouldBeSuccess + packages <- readTextFile "packages.dhall" + let [packageSetUrl] + = map Text.strip + $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") + $ Text.lines packages + + packageSetUrl `shouldBe` originalPackageSetUrl + + describe "spago script" $ do + + -- At that time, we should add more tests checking the output of the script + + it "Spago script should create file in directory where it is executed" $ do - it "Spago should not migrate to the user-specified package-set if does not exist" $ do - -- initialize the project, so that it uses latest package set release - spago ["init"] >>= shouldBeSuccess + spago ["script", "../fixtures/spago-script-make-file.purs", "-d", "node-fs", "-d", "node-buffer"] >>= shouldBeSuccess + checkFixture "spago-script-result.txt" - originalPackages <- readTextFile "packages.dhall" - let [originalPackageSetUrl] - = map Text.strip - $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") - $ Text.lines originalPackages + describe "spago bundle" $ do - spago ["-v", "upgrade-set", "--tag", "does-not-exist"] >>= shouldBeSuccess - packages <- readTextFile "packages.dhall" - let [packageSetUrl] - = map Text.strip - $ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets") - $ Text.lines packages + it "Spago should fail but should point to the replacement command" $ do - packageSetUrl `shouldBe` originalPackageSetUrl + spago ["bundle", "--to", "bundle.js"] >>= shouldBeFailureStderr "bundle-stderr.txt" + + describe "spago make-module" $ do - describe "spago script" $ do + it "Spago should fail but should point to the replacement command" $ do - -- At that time, we should add more tests checking the output of the script + spago ["make-module", "--to", "make-module.js"] >>= shouldBeFailureStderr "make-module-stderr.txt" - it "Spago script should create file in directory where it is executed" $ do + describe "spago ls packages" $ do - spago ["script", "../fixtures/spago-script-make-file.purs", "-d", "node-fs", "-d", "node-buffer"] >>= shouldBeSuccess - checkFixture "spago-script-result.txt" + it "Spago should ls packages successfully" $ do - describe "spago bundle" $ do + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packages-old.dhall" + writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" + spago ["ls", "packages"] >>= shouldBeSuccessOutput "list-packages.txt" - it "Spago should fail but should point to the replacement command" $ do + it "Spago should ls packages in JSON successfully" $ do - spago ["bundle", "--to", "bundle.js"] >>= shouldBeFailureStderr "bundle-stderr.txt" + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packages-old.dhall" + writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" + spago ["ls", "packages", "--json"] >>= shouldBeSuccessOutput "list-packages.json" - describe "spago make-module" $ do + describe "spago path output" $ do + it "Spago should output the correct path" $ do + -- Create local 'monorepo-1' package that is the real root + mkdir "monorepo-1" + cd "monorepo-1" + spago ["init"] >>= shouldBeSuccess - it "Spago should fail but should point to the replacement command" $ do + -- Create local 'monorepo-2' package that uses packages.dhall on top level + mkdir "monorepo-2" + cd "monorepo-2" + spago ["init"] >>= shouldBeSuccess + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["path", "output"] >>= outputShouldEqual "output\n" + pure () - spago ["make-module", "--to", "make-module.js"] >>= shouldBeFailureStderr "make-module-stderr.txt" + describe "spago verify-set" $ do + it "Spago should fail when there is no spago.dhall or packages.dhall" $ do + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + rm "packages.dhall" + spago ["verify-set"] >>= shouldBeFailureStderr "verify-set-failure-no-files.txt" - describe "spago ls packages" $ do + it "Spago should fail when packages.dhall is malformed" $ do + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packages-old.dhall" + writeTextFile "packages.dhall" $ "abcdef" + spago ["verify-set"] >>= shouldBeFailure - it "Spago should ls packages successfully" $ do + describe "global cache" $ do + it "Spago should create global cache directory if it does not exist" $ do + withEnvVar "XDG_CACHE_HOME" "./nonexisting-cache" $ + spago ["repl"] >>= shouldBeSuccess + describe purs0_15_0TestMsg $ do + describe "spago bundle-app" $ do + it "Spago should bundle successfully" $ do + fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packages-old.dhall" - writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" - spago ["ls", "packages"] >>= shouldBeSuccessOutput "list-packages.txt" - - it "Spago should ls packages in JSON successfully" $ do + if usingEsModules then do + spago [ "-V", "bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess + checkFixture "bundle-app-esm.js" + else do + spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess + checkFixture "bundle-app.js" + it "Spago should bundle successfully with source map" $ do + fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packages-old.dhall" - writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" - spago ["ls", "packages", "--json"] >>= shouldBeSuccessOutput "list-packages.json" - - describe "spago path output" $ do - it "Spago should output the correct path" $ do - -- Create local 'monorepo-1' package that is the real root - mkdir "monorepo-1" - cd "monorepo-1" - spago ["init"] >>= shouldBeSuccess - - -- Create local 'monorepo-2' package that uses packages.dhall on top level - mkdir "monorepo-2" - cd "monorepo-2" + if usingEsModules then do + spago ["-V", "bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-app-src-map-esm.js" + checkFileExist "bundle-app-src-map-esm.js.map" + else do + spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-app-src-map.js" + checkFileExist "bundle-app-src-map.js.map" + + describe "spago bundle-module" $ do + it "Spago should successfully make a module" $ do + fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess - rm "packages.dhall" - writeTextFile "packages.dhall" $ "../packages.dhall" - spago ["path", "output"] >>= outputShouldEqual "output\n" - pure () - - describe "spago verify-set" $ do - it "Spago should fail when there is no spago.dhall or packages.dhall" $ do + spago ["build"] >>= shouldBeSuccess + -- Now we don't remove the output folder, but we pass the `--no-build` + -- flag to skip rebuilding (i.e. we are counting on the previous command + -- to have built stuff for us) + if usingEsModules then do + spago ["bundle-module", "--to", "bundle-module-esm.js", "--no-build"] >>= shouldBeSuccess + checkFixture "bundle-module-esm.js" + else do + spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess + checkFixture "bundle-module.js" + + it "Spago should successfully make a module with source map" $ do + fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - rm "packages.dhall" - spago ["verify-set"] >>= shouldBeFailureStderr "verify-set-failure-no-files.txt" + spago ["build"] >>= shouldBeSuccess - it "Spago should fail when packages.dhall is malformed" $ do - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packages-old.dhall" - writeTextFile "packages.dhall" $ "abcdef" - spago ["verify-set"] >>= shouldBeFailure - - describe "global cache" $ do - it "Spago should create global cache directory if it does not exist" $ do - withEnvVar "XDG_CACHE_HOME" "./nonexisting-cache" $ - spago ["repl"] >>= shouldBeSuccess - - describe purs0_15_0TestMsg $ do - describe "spago bundle-app" $ do - it "Spago should bundle successfully" $ do - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - if usingEsModules then do - spago [ "-V", "bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess - checkFixture "bundle-app-esm.js" - else do - spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess - checkFixture "bundle-app.js" - - it "Spago should bundle successfully with source map" $ do - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - if usingEsModules then do - spago ["-V", "bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-app-src-map-esm.js" - checkFileExist "bundle-app-src-map-esm.js.map" - else do - spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-app-src-map.js" - checkFileExist "bundle-app-src-map.js.map" - - describe "spago bundle-module" $ do - it "Spago should successfully make a module" $ do - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - -- Now we don't remove the output folder, but we pass the `--no-build` - -- flag to skip rebuilding (i.e. we are counting on the previous command - -- to have built stuff for us) - if usingEsModules then do - spago ["bundle-module", "--to", "bundle-module-esm.js", "--no-build"] >>= shouldBeSuccess - checkFixture "bundle-module-esm.js" - else do - spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess - checkFixture "bundle-module.js" - - it "Spago should successfully make a module with source map" $ do - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - - if usingEsModules then do - spago ["bundle-module", "--to", "bundle-module-src-map-esm.js", "--no-build", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-module-src-map-esm.js" - checkFileExist "bundle-module-src-map-esm.js.map" - else do - spago ["bundle-module", "--to", "bundle-module-src-map.js", "--no-build", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-module-src-map.js" - checkFileExist "bundle-module-src-map.js.map" + if usingEsModules then do + spago ["bundle-module", "--to", "bundle-module-src-map-esm.js", "--no-build", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-module-src-map-esm.js" + checkFileExist "bundle-module-src-map-esm.js.map" + else do + spago ["bundle-module", "--to", "bundle-module-src-map.js", "--no-build", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-module-src-map.js" + checkFileExist "bundle-module-src-map.js.map" spacesInParentDir :: Bool -> Spec spacesInParentDir usingEsModules = around_ (setup "spago test") $ do From 1ed311aa2bc78313c36ad5a25f2825168ae7eb4b Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 13 Apr 2022 13:59:00 -0500 Subject: [PATCH 73/82] Remove various formatting changes --- test/SpagoSpec.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 3195d7cd5..0f1a4cd65 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -386,7 +386,7 @@ noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do spago ["build"] >>= shouldBeSuccess testdir "output" `shouldReturn` True - -- Create local 'monorepo-3' package that uses packages.dhall on top level + -- Create local 'monorepo-3' package that uses packages.dhall on top level mkdir "monorepo-3" cd "monorepo-3" spago ["init"] >>= shouldBeSuccess @@ -506,7 +506,7 @@ noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do dir <- pwd let dumpFile = dir "testOutput" - spago ["build", "--before", "echo before>> " <> (Text.pack $ encodeString dumpFile)] >>= shouldBeSuccess + spago ["build", "--before", "echo before>> " <> ( Text.pack $ encodeString dumpFile )] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "before\n" @@ -530,8 +530,8 @@ noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do dir <- pwd let dumpFile = dir "testOutput" spago [ "build" - , "--before", "echo before>> " <> Text.pack (encodeString dumpFile) - , "--then", "echo then>> " <> Text.pack (encodeString dumpFile) + , "--before", "echo before>> " <> ( Text.pack $ encodeString dumpFile ) + , "--then", "echo then>> " <> ( Text.pack $ encodeString dumpFile ) ] >>= shouldBeSuccess test <- readTextFile dumpFile test `shouldBe` "before\nthen\n" @@ -562,7 +562,7 @@ noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do 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) + , "--else", "echo else>> " <> ( Text.pack $ encodeString dumpFile ) ] >>= shouldBeFailure test <- readTextFile dumpFile test `shouldBe` "else\n" @@ -701,7 +701,7 @@ noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do cd "monorepo-1" spago ["init"] >>= shouldBeSuccess - -- Create local 'monorepo-2' package that uses packages.dhall on top level + -- Create local 'monorepo-2' package that uses packages.dhall on top level mkdir "monorepo-2" cd "monorepo-2" spago ["init"] >>= shouldBeSuccess From 2e1f3144d9db979484d00b132ee1b0e7bd6e3dd7 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 13 Apr 2022 17:02:06 -0500 Subject: [PATCH 74/82] Minimize diff even more - checkFixture and fixPackagesDhall works regardless of the number of nested dirs used - run and test tests run in another nested folder with space - run, test, bundle-app/module tests remain in original positions - run, test, bundle-app/module tests wrapped by a purs-0.15 label --- test/SpagoSpec.hs | 338 ++++++++++++++++++++++++---------------------- test/Utils.hs | 17 ++- 2 files changed, 188 insertions(+), 167 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 0f1a4cd65..406e5756c 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -8,14 +8,15 @@ import Test.Hspec (Spec, around_, describe, it, shouldBe, shou shouldNotBe, shouldReturn, shouldSatisfy, runIO) import Turtle (ExitCode (..), cd, cp, decodeString, empty, encodeString, mkdir, mktree, mv, pwd, readTextFile, rm, shell, - shellStrictWithErr, testdir, writeTextFile, (), die, when, void) + shellStrictWithErr, testdir, writeTextFile, (), die, when) import Utils (checkFileHasInfix, checkFixture, checkFileExist, outputShouldEqual, readFixture, runFor, shouldBeFailure, shouldBeFailureInfix, shouldBeFailureStderr, shouldBeSuccess, shouldBeSuccessOutput, shouldBeSuccessOutputWithErr, shouldBeSuccessStderr, spago, - withCwd, withEnvVar, dhall) -import qualified Data.Versions as Version + withCwd, withEnvVar, dhall, getFixturesDir) import qualified Spago.Cmd as Cmd +import qualified Data.Versions as Version +import System.Directory.Extra (getCurrentDirectory) setup :: String -> IO () -> IO () @@ -24,15 +25,23 @@ setup dir cmd = do -- print ("Running in " <> temp) withCwd (decodeString temp) cmd +setup' :: String -> IO () -> IO () +setup' dir cmd = do + currentDir <- getCurrentDirectory + Temp.withTempDirectory "test/" (currentDir <> "/" <> dir) $ \temp -> do + -- print ("Running in " <> temp) + withCwd (decodeString temp) cmd + purs0_15_0TestMsg :: String purs0_15_0TestMsg = "purs-0.15" fixPackagesDhall :: Bool -> IO () fixPackagesDhall usingEsModules = when usingEsModules $ do + fixturesDir <- getFixturesDir -- The prepare-0.15 package set's contents can change. -- So, we copy an unfrozen one into the directory -- and then freeze it before running `spago init`. - cp "../fixtures/packages-prepare-0-15.dhall" "packages.dhall" + cp (fixturesDir "packages-prepare-0-15.dhall") "packages.dhall" dhall ["freeze", "packages.dhall"] >>= shouldBeSuccess getUsingEsModules :: IO Bool @@ -42,13 +51,7 @@ getUsingEsModules = do pure $ pursVersion >= esmVersion spec :: Spec -spec = do - usingEsModules <- runIO getUsingEsModules - noSpacesInParentDir usingEsModules - spacesInParentDir usingEsModules - -noSpacesInParentDir :: Bool -> Spec -noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do +spec = runIO getUsingEsModules >>= \usingEsModules -> around_ (setup "spago-test") $ do describe "spago init" $ do @@ -605,6 +608,56 @@ noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do , "--else", "exit 1" ] >>= shouldBeFailure + describe purs0_15_0TestMsg $ do + + around_ (setup' "spago test") $ do + + it "Spago should test successfully" $ do + + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" + + it "Spago should fail nicely when the test module is not found" $ do + + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + mv "test" "test2" + spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" + + it "Spago should test in custom output folder" $ do + + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess + testdir "myOutput" `shouldReturn` True + + it "Spago should test successfully with a different output folder" $ do + + -- Create root-level packages.dhall + mkdir "monorepo" + cd "monorepo" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + + -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) + mkdir "lib-a" + cd "lib-a" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["test"] >>= shouldBeSuccess + testdir "output" `shouldReturn` True + + cd ".." + testdir "output" `shouldReturn` False + + describe "spago upgrade-set" $ do it "Spago should migrate package-sets from src/packages.dhall to the released one" $ do @@ -657,80 +710,87 @@ noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do packageSetUrl `shouldBe` originalPackageSetUrl - describe "spago script" $ do + describe purs0_15_0TestMsg $ do - -- At that time, we should add more tests checking the output of the script + around_ (setup' "spago test") $ do - it "Spago script should create file in directory where it is executed" $ do + describe "spago run" $ do - spago ["script", "../fixtures/spago-script-make-file.purs", "-d", "node-fs", "-d", "node-buffer"] >>= shouldBeSuccess - checkFixture "spago-script-result.txt" + it "Spago should run successfully" $ do - describe "spago bundle" $ do + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess - it "Spago should fail but should point to the replacement command" $ do + shell "psa --version" empty >>= \case + ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" + ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" - spago ["bundle", "--to", "bundle.js"] >>= shouldBeFailureStderr "bundle-stderr.txt" + it "Spago should be able to not use `psa`" $ do - describe "spago make-module" $ do + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["--no-psa", "build"] >>= shouldBeSuccess + spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" - it "Spago should fail but should point to the replacement command" $ do + it "Spago should pass stdin to the child process" $ do - spago ["make-module", "--to", "make-module.js"] >>= shouldBeFailureStderr "make-module-stderr.txt" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + cp "../../fixtures/spago-run-stdin.purs" "src/Main.purs" + spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt" - describe "spago ls packages" $ do + it "Spago should use exec-args" $ do - it "Spago should ls packages successfully" $ do + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + cp "../../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packages-old.dhall" - writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" - spago ["ls", "packages"] >>= shouldBeSuccessOutput "list-packages.txt" + it "Spago should use node-args" $ do - it "Spago should ls packages in JSON successfully" $ do + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + cp "../../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" + spago ["run", "--node-args", "--flagName"] >>= shouldBeSuccess - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packages-old.dhall" - writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" - spago ["ls", "packages", "--json"] >>= shouldBeSuccessOutput "list-packages.json" + it "Spago should prefer exec-args" $ do - describe "spago path output" $ do - it "Spago should output the correct path" $ do - -- Create local 'monorepo-1' package that is the real root - mkdir "monorepo-1" - cd "monorepo-1" - spago ["init"] >>= shouldBeSuccess + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + cp "../../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt" - -- Create local 'monorepo-2' package that uses packages.dhall on top level - mkdir "monorepo-2" - cd "monorepo-2" - spago ["init"] >>= shouldBeSuccess - rm "packages.dhall" - writeTextFile "packages.dhall" $ "../packages.dhall" - spago ["path", "output"] >>= outputShouldEqual "output\n" - pure () + describe "spago script" $ do - describe "spago verify-set" $ do - it "Spago should fail when there is no spago.dhall or packages.dhall" $ do - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - rm "packages.dhall" - spago ["verify-set"] >>= shouldBeFailureStderr "verify-set-failure-no-files.txt" + -- At that time, we should add more tests checking the output of the script - it "Spago should fail when packages.dhall is malformed" $ do - spago ["init"] >>= shouldBeSuccess - mv "packages.dhall" "packages-old.dhall" - writeTextFile "packages.dhall" $ "abcdef" - spago ["verify-set"] >>= shouldBeFailure + it "Spago script should create file in directory where it is executed" $ do - describe "global cache" $ do - it "Spago should create global cache directory if it does not exist" $ do - withEnvVar "XDG_CACHE_HOME" "./nonexisting-cache" $ - spago ["repl"] >>= shouldBeSuccess + spago ["script", "../fixtures/spago-script-make-file.purs", "-d", "node-fs", "-d", "node-buffer"] >>= shouldBeSuccess + checkFixture "spago-script-result.txt" + + describe "spago bundle" $ do + + it "Spago should fail but should point to the replacement command" $ do + + spago ["bundle", "--to", "bundle.js"] >>= shouldBeFailureStderr "bundle-stderr.txt" describe purs0_15_0TestMsg $ do + describe "spago bundle-app" $ do + it "Spago should bundle successfully" $ do + fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess if usingEsModules then do @@ -741,6 +801,7 @@ noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do checkFixture "bundle-app.js" it "Spago should bundle successfully with source map" $ do + fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess if usingEsModules then do @@ -752,8 +813,18 @@ noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do checkFixture "bundle-app-src-map.js" checkFileExist "bundle-app-src-map.js.map" + describe "spago make-module" $ do + + it "Spago should fail but should point to the replacement command" $ do + + spago ["make-module", "--to", "make-module.js"] >>= shouldBeFailureStderr "make-module-stderr.txt" + + describe purs0_15_0TestMsg $ do + describe "spago bundle-module" $ do + it "Spago should successfully make a module" $ do + fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess @@ -768,6 +839,7 @@ noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do checkFixture "bundle-module.js" it "Spago should successfully make a module with source map" $ do + fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess @@ -781,114 +853,52 @@ noSpacesInParentDir usingEsModules = around_ (setup "spago-test") $ do checkFixture "bundle-module-src-map.js" checkFileExist "bundle-module-src-map.js.map" -spacesInParentDir :: Bool -> Spec -spacesInParentDir usingEsModules = around_ (setup "spago test") $ do - - describe purs0_15_0TestMsg $ do - - describe "spago run" $ do - - it "Spago should run successfully" $ do - - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - - shell "psa --version" empty >>= \case - ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" - ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" - - it "Spago should be able to not use `psa`" $ do - - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - spago ["--no-psa", "build"] >>= shouldBeSuccess - spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" - - it "Spago should pass stdin to the child process" $ do - - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-stdin.purs" "src/Main.purs" - spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt" - - it "Spago should use exec-args" $ do - - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" - - it "Spago should use node-args" $ do - - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" - spago ["run", "--node-args", "--flagName"] >>= shouldBeSuccess - - it "Spago should prefer exec-args" $ do - - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - cp "../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt" - - describe "spago test" $ do - - it "Spago should test successfully" $ do + describe "spago ls packages" $ do - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" + it "Spago should ls packages successfully" $ do - it "Spago should fail nicely when the test module is not found" $ do + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packages-old.dhall" + writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" + spago ["ls", "packages"] >>= shouldBeSuccessOutput "list-packages.txt" - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - mv "test" "test2" - spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" + it "Spago should ls packages in JSON successfully" $ do - it "Spago should test in custom output folder" $ do + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packages-old.dhall" + writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4" + spago ["ls", "packages", "--json"] >>= shouldBeSuccessOutput "list-packages.json" - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess - testdir "myOutput" `shouldReturn` True + describe "spago path output" $ do + it "Spago should output the correct path" $ do + -- Create local 'monorepo-1' package that is the real root + mkdir "monorepo-1" + cd "monorepo-1" + spago ["init"] >>= shouldBeSuccess - it "Spago should test successfully with a different output folder" $ do + -- Create local 'monorepo-2' package that uses packages.dhall on top level + mkdir "monorepo-2" + cd "monorepo-2" + spago ["init"] >>= shouldBeSuccess + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["path", "output"] >>= outputShouldEqual "output\n" + pure () - -- Create root-level packages.dhall - mkdir "monorepo" - cd "monorepo" - when usingEsModules $ do - cp "../../fixtures/packages-prepare-0-15.dhall" "packages.dhall" - void $ dhall ["freeze", "packages.dhall"] - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" + describe "spago verify-set" $ do + it "Spago should fail when there is no spago.dhall or packages.dhall" $ do + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + rm "packages.dhall" + spago ["verify-set"] >>= shouldBeFailureStderr "verify-set-failure-no-files.txt" - -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) - mkdir "lib-a" - cd "lib-a" - when usingEsModules $ do - cp "../../../fixtures/packages-prepare-0-15.dhall" "packages.dhall" - void $ dhall ["freeze", "packages.dhall"] - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - rm "packages.dhall" - writeTextFile "packages.dhall" $ "../packages.dhall" - spago ["test"] >>= shouldBeSuccess - testdir "output" `shouldReturn` True + it "Spago should fail when packages.dhall is malformed" $ do + spago ["init"] >>= shouldBeSuccess + mv "packages.dhall" "packages-old.dhall" + writeTextFile "packages.dhall" $ "abcdef" + spago ["verify-set"] >>= shouldBeFailure - cd ".." - testdir "output" `shouldReturn` False + describe "global cache" $ do + it "Spago should create global cache directory if it does not exist" $ do + withEnvVar "XDG_CACHE_HOME" "./nonexisting-cache" $ + spago ["repl"] >>= shouldBeSuccess diff --git a/test/Utils.hs b/test/Utils.hs index 603f53709..dd2d91c2f 100644 --- a/test/Utils.hs +++ b/test/Utils.hs @@ -2,6 +2,7 @@ module Utils ( checkFixture , checkFileHasInfix , checkFileExist + , getFixturesDir , readFixture , getHighestTag , git @@ -34,7 +35,7 @@ import System.Directory (removePathForcibly, doesFileExist) import qualified System.Process as Process import Test.Hspec (HasCallStack, shouldBe, shouldSatisfy) import Turtle (ExitCode (..), FilePath, Text, cd, empty, encodeString, export, - inproc, limit, need, pwd, readTextFile, strict) + inproc, limit, need, pwd, readTextFile, strict, testdir, (), parent) import qualified Turtle.Bytes @@ -135,9 +136,19 @@ shouldBeFailureInfix :: HasCallStack => Text -> (ExitCode, Text, Text) -> IO () shouldBeFailureInfix expected result = do result `shouldSatisfy` (\(code, _stdout, stderr) -> code == ExitFailure 1 && Text.isInfixOf expected stderr) +getFixturesDir :: IO FilePath +getFixturesDir = pwd >>= go + where + fixturesDirName = "fixtures" + go accumPath = do + let fixturesDir = accumPath fixturesDirName + hasFixturesDir <- testdir fixturesDir + if hasFixturesDir + then pure fixturesDir + else go (parent accumPath) + readFixture :: FilePath -> IO Text -readFixture path = - readTextFile $ "../fixtures/" <> path +readFixture filePath = getFixturesDir >>= \fixturesDir -> readTextFile $ fixturesDir filePath checkFixture :: HasCallStack => FilePath -> IO () checkFixture path = do From ac8d5227b3b6064d07e497d290d1c6370016605b Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 13 Apr 2022 17:04:34 -0500 Subject: [PATCH 75/82] Refactor setup' to reuse setup so one print cmd works --- test/SpagoSpec.hs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 406e5756c..875a335ba 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -28,9 +28,7 @@ setup dir cmd = do setup' :: String -> IO () -> IO () setup' dir cmd = do currentDir <- getCurrentDirectory - Temp.withTempDirectory "test/" (currentDir <> "/" <> dir) $ \temp -> do - -- print ("Running in " <> temp) - withCwd (decodeString temp) cmd + setup (currentDir <> "/" <> dir) cmd purs0_15_0TestMsg :: String purs0_15_0TestMsg = "purs-0.15" From a52a1646736cd955f9a4f4cc57dde1722b0992ed Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 13 Apr 2022 17:08:04 -0500 Subject: [PATCH 76/82] Refactor common cp code into cpFixture --- test/SpagoSpec.hs | 5 ++--- test/Utils.hs | 8 +++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 875a335ba..f9414faa4 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -13,7 +13,7 @@ import Utils (checkFileHasInfix, checkFixture, checkFileE readFixture, runFor, shouldBeFailure, shouldBeFailureInfix, shouldBeFailureStderr, shouldBeSuccess, shouldBeSuccessOutput, shouldBeSuccessOutputWithErr, shouldBeSuccessStderr, spago, - withCwd, withEnvVar, dhall, getFixturesDir) + withCwd, withEnvVar, dhall, cpFixture) import qualified Spago.Cmd as Cmd import qualified Data.Versions as Version import System.Directory.Extra (getCurrentDirectory) @@ -35,11 +35,10 @@ purs0_15_0TestMsg = "purs-0.15" fixPackagesDhall :: Bool -> IO () fixPackagesDhall usingEsModules = when usingEsModules $ do - fixturesDir <- getFixturesDir -- The prepare-0.15 package set's contents can change. -- So, we copy an unfrozen one into the directory -- and then freeze it before running `spago init`. - cp (fixturesDir "packages-prepare-0-15.dhall") "packages.dhall" + cpFixture "packages-prepare-0-15.dhall" "packages.dhall" dhall ["freeze", "packages.dhall"] >>= shouldBeSuccess getUsingEsModules :: IO Bool diff --git a/test/Utils.hs b/test/Utils.hs index dd2d91c2f..4cf86cde5 100644 --- a/test/Utils.hs +++ b/test/Utils.hs @@ -4,6 +4,7 @@ module Utils , checkFileExist , getFixturesDir , readFixture + , cpFixture , getHighestTag , git , outputShouldEqual @@ -35,7 +36,7 @@ import System.Directory (removePathForcibly, doesFileExist) import qualified System.Process as Process import Test.Hspec (HasCallStack, shouldBe, shouldSatisfy) import Turtle (ExitCode (..), FilePath, Text, cd, empty, encodeString, export, - inproc, limit, need, pwd, readTextFile, strict, testdir, (), parent) + inproc, limit, need, pwd, readTextFile, strict, testdir, (), parent, cp) import qualified Turtle.Bytes @@ -150,6 +151,11 @@ getFixturesDir = pwd >>= go readFixture :: FilePath -> IO Text readFixture filePath = getFixturesDir >>= \fixturesDir -> readTextFile $ fixturesDir filePath +cpFixture :: FilePath -> FilePath -> IO () +cpFixture fixture path = do + fixturesDir <- getFixturesDir + cp (fixturesDir fixture) path + checkFixture :: HasCallStack => FilePath -> IO () checkFixture path = do actual <- readTextFile path From f8cd1a12d40d42ac530c54deacf78cff37d81af7 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 13 Apr 2022 17:11:04 -0500 Subject: [PATCH 77/82] Minimize diff due to indentation --- test/SpagoSpec.hs | 264 ++++++++++++++++++++++------------------------ 1 file changed, 127 insertions(+), 137 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index f9414faa4..3fa8fd55b 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -605,54 +605,52 @@ spec = runIO getUsingEsModules >>= \usingEsModules -> around_ (setup "spago-test , "--else", "exit 1" ] >>= shouldBeFailure - describe purs0_15_0TestMsg $ do + describe "spago test" $ describe purs0_15_0TestMsg $ around_ (setup' "spago test") $ do - around_ (setup' "spago test") $ do + it "Spago should test successfully" $ do - it "Spago should test successfully" $ do - - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["--no-psa", "test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt" - it "Spago should fail nicely when the test module is not found" $ do + it "Spago should fail nicely when the test module is not found" $ do - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - mv "test" "test2" - spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + mv "test" "test2" + spago ["test"] >>= shouldBeFailureInfix "Module 'Test.Main' not found! Are you including it in your build?" - it "Spago should test in custom output folder" $ do + it "Spago should test in custom output folder" $ do - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess - testdir "myOutput" `shouldReturn` True + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess + testdir "myOutput" `shouldReturn` True - it "Spago should test successfully with a different output folder" $ do + it "Spago should test successfully with a different output folder" $ do - -- Create root-level packages.dhall - mkdir "monorepo" - cd "monorepo" - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" + -- Create root-level packages.dhall + mkdir "monorepo" + cd "monorepo" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" - -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) - mkdir "lib-a" - cd "lib-a" - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - rm "spago.dhall" - writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" - rm "packages.dhall" - writeTextFile "packages.dhall" $ "../packages.dhall" - spago ["test"] >>= shouldBeSuccess - testdir "output" `shouldReturn` True + -- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things) + mkdir "lib-a" + cd "lib-a" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + rm "spago.dhall" + writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }" + rm "packages.dhall" + writeTextFile "packages.dhall" $ "../packages.dhall" + spago ["test"] >>= shouldBeSuccess + testdir "output" `shouldReturn` True - cd ".." - testdir "output" `shouldReturn` False + cd ".." + testdir "output" `shouldReturn` False describe "spago upgrade-set" $ do @@ -707,65 +705,61 @@ spec = runIO getUsingEsModules >>= \usingEsModules -> around_ (setup "spago-test packageSetUrl `shouldBe` originalPackageSetUrl - describe purs0_15_0TestMsg $ do - - around_ (setup' "spago test") $ do + describe "spago run" $ describe purs0_15_0TestMsg $ around_ (setup' "spago test") $ do - describe "spago run" $ do + it "Spago should run successfully" $ do - it "Spago should run successfully" $ do - - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess - shell "psa --version" empty >>= \case - ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" - ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" + shell "psa --version" empty >>= \case + ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" + ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt" - it "Spago should be able to not use `psa`" $ do + it "Spago should be able to not use `psa`" $ do - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - spago ["--no-psa", "build"] >>= shouldBeSuccess - spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["--no-psa", "build"] >>= shouldBeSuccess + spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutput "run-output.txt" - it "Spago should pass stdin to the child process" $ do + it "Spago should pass stdin to the child process" $ do - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - cp "../../fixtures/spago-run-stdin.purs" "src/Main.purs" - spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + cp "../../fixtures/spago-run-stdin.purs" "src/Main.purs" + spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt" - it "Spago should use exec-args" $ do + it "Spago should use exec-args" $ do - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - cp "../../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + cp "../../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" - it "Spago should use node-args" $ do + it "Spago should use node-args" $ do - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - cp "../../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" - spago ["run", "--node-args", "--flagName"] >>= shouldBeSuccess + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + cp "../../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" + spago ["run", "--node-args", "--flagName"] >>= shouldBeSuccess - it "Spago should prefer exec-args" $ do + it "Spago should prefer exec-args" $ do - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - cp "../../fixtures/spago-run-args.purs" "src/Main.purs" - spago ["install", "node-process", "arrays"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + cp "../../fixtures/spago-run-args.purs" "src/Main.purs" + spago ["install", "node-process", "arrays"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt" describe "spago script" $ do @@ -782,33 +776,31 @@ spec = runIO getUsingEsModules >>= \usingEsModules -> around_ (setup "spago-test spago ["bundle", "--to", "bundle.js"] >>= shouldBeFailureStderr "bundle-stderr.txt" - describe purs0_15_0TestMsg $ do + describe "spago bundle-app" $ describe purs0_15_0TestMsg $ do - describe "spago bundle-app" $ do + it "Spago should bundle successfully" $ do - it "Spago should bundle successfully" $ do - - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - if usingEsModules then do - spago [ "-V", "bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess - checkFixture "bundle-app-esm.js" - else do - spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess - checkFixture "bundle-app.js" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + if usingEsModules then do + spago [ "-V", "bundle-app", "--to", "bundle-app-esm.js"] >>= shouldBeSuccess + checkFixture "bundle-app-esm.js" + else do + spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess + checkFixture "bundle-app.js" - it "Spago should bundle successfully with source map" $ do + it "Spago should bundle successfully with source map" $ do - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - if usingEsModules then do - spago ["-V", "bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-app-src-map-esm.js" - checkFileExist "bundle-app-src-map-esm.js.map" - else do - spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-app-src-map.js" - checkFileExist "bundle-app-src-map.js.map" + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + if usingEsModules then do + spago ["-V", "bundle-app", "--to", "bundle-app-src-map-esm.js", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-app-src-map-esm.js" + checkFileExist "bundle-app-src-map-esm.js.map" + else do + spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-app-src-map.js" + checkFileExist "bundle-app-src-map.js.map" describe "spago make-module" $ do @@ -816,39 +808,37 @@ spec = runIO getUsingEsModules >>= \usingEsModules -> around_ (setup "spago-test spago ["make-module", "--to", "make-module.js"] >>= shouldBeFailureStderr "make-module-stderr.txt" - describe purs0_15_0TestMsg $ do + describe "spago bundle-module" $ describe purs0_15_0TestMsg $ do - describe "spago bundle-module" $ do + it "Spago should successfully make a module" $ do - it "Spago should successfully make a module" $ do + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + -- Now we don't remove the output folder, but we pass the `--no-build` + -- flag to skip rebuilding (i.e. we are counting on the previous command + -- to have built stuff for us) + if usingEsModules then do + spago ["bundle-module", "--to", "bundle-module-esm.js", "--no-build"] >>= shouldBeSuccess + checkFixture "bundle-module-esm.js" + else do + spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess + checkFixture "bundle-module.js" - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - -- Now we don't remove the output folder, but we pass the `--no-build` - -- flag to skip rebuilding (i.e. we are counting on the previous command - -- to have built stuff for us) - if usingEsModules then do - spago ["bundle-module", "--to", "bundle-module-esm.js", "--no-build"] >>= shouldBeSuccess - checkFixture "bundle-module-esm.js" - else do - spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess - checkFixture "bundle-module.js" - - it "Spago should successfully make a module with source map" $ do - - fixPackagesDhall usingEsModules - spago ["init"] >>= shouldBeSuccess - spago ["build"] >>= shouldBeSuccess - - if usingEsModules then do - spago ["bundle-module", "--to", "bundle-module-src-map-esm.js", "--no-build", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-module-src-map-esm.js" - checkFileExist "bundle-module-src-map-esm.js.map" - else do - spago ["bundle-module", "--to", "bundle-module-src-map.js", "--no-build", "--source-maps"] >>= shouldBeSuccess - checkFixture "bundle-module-src-map.js" - checkFileExist "bundle-module-src-map.js.map" + it "Spago should successfully make a module with source map" $ do + + fixPackagesDhall usingEsModules + spago ["init"] >>= shouldBeSuccess + spago ["build"] >>= shouldBeSuccess + + if usingEsModules then do + spago ["bundle-module", "--to", "bundle-module-src-map-esm.js", "--no-build", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-module-src-map-esm.js" + checkFileExist "bundle-module-src-map-esm.js.map" + else do + spago ["bundle-module", "--to", "bundle-module-src-map.js", "--no-build", "--source-maps"] >>= shouldBeSuccess + checkFixture "bundle-module-src-map.js" + checkFileExist "bundle-module-src-map.js.map" describe "spago ls packages" $ do From b717ca702a2bcc9c26aef5a9c2b680775f739024 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 13 Apr 2022 17:14:05 -0500 Subject: [PATCH 78/82] Document what purs-0.15 label means --- test/SpagoSpec.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 3fa8fd55b..2890ed26c 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -30,6 +30,9 @@ setup' dir cmd = do currentDir <- getCurrentDirectory setup (currentDir <> "/" <> dir) cmd +-- | This label is used to describe +-- tests that can be run on an +-- alpha release of PureScript @0.15.0@. purs0_15_0TestMsg :: String purs0_15_0TestMsg = "purs-0.15" From 52d489ca9a91fe3235cad8ec4719109fceb486ff Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 13 Apr 2022 17:16:57 -0500 Subject: [PATCH 79/82] Add empty blank lines deleted in PR --- test/SpagoSpec.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 2890ed26c..38244f0e7 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -779,6 +779,7 @@ spec = runIO getUsingEsModules >>= \usingEsModules -> around_ (setup "spago-test spago ["bundle", "--to", "bundle.js"] >>= shouldBeFailureStderr "bundle-stderr.txt" + describe "spago bundle-app" $ describe purs0_15_0TestMsg $ do it "Spago should bundle successfully" $ do @@ -811,6 +812,7 @@ spec = runIO getUsingEsModules >>= \usingEsModules -> around_ (setup "spago-test spago ["make-module", "--to", "make-module.js"] >>= shouldBeFailureStderr "make-module-stderr.txt" + describe "spago bundle-module" $ describe purs0_15_0TestMsg $ do it "Spago should successfully make a module" $ do From 73db62769b1ddf7512f7ec6022493f899471e62d Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Wed, 13 Apr 2022 17:18:11 -0500 Subject: [PATCH 80/82] Update usages of cp '../../fixtures/file' with cpFixture 'file' --- test/SpagoSpec.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/SpagoSpec.hs b/test/SpagoSpec.hs index 38244f0e7..c5e5bb505 100644 --- a/test/SpagoSpec.hs +++ b/test/SpagoSpec.hs @@ -731,7 +731,7 @@ spec = runIO getUsingEsModules >>= \usingEsModules -> around_ (setup "spago-test fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess - cp "../../fixtures/spago-run-stdin.purs" "src/Main.purs" + cpFixture "spago-run-stdin.purs" "src/Main.purs" spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt" @@ -740,7 +740,7 @@ spec = runIO getUsingEsModules >>= \usingEsModules -> around_ (setup "spago-test fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess - cp "../../fixtures/spago-run-args.purs" "src/Main.purs" + cpFixture "spago-run-args.purs" "src/Main.purs" spago ["install", "node-process", "arrays"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" @@ -749,7 +749,7 @@ spec = runIO getUsingEsModules >>= \usingEsModules -> around_ (setup "spago-test fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess - cp "../../fixtures/spago-run-args.purs" "src/Main.purs" + cpFixture "spago-run-args.purs" "src/Main.purs" spago ["install", "node-process", "arrays"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt" @@ -759,7 +759,7 @@ spec = runIO getUsingEsModules >>= \usingEsModules -> around_ (setup "spago-test fixPackagesDhall usingEsModules spago ["init"] >>= shouldBeSuccess - cp "../../fixtures/spago-run-args.purs" "src/Main.purs" + cpFixture "spago-run-args.purs" "src/Main.purs" spago ["install", "node-process", "arrays"] >>= shouldBeSuccess spago ["build"] >>= shouldBeSuccess spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt" From df19289a3e57b5e2cda284e3b79f0c64b7298a96 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 26 Apr 2022 14:04:15 -0500 Subject: [PATCH 81/82] Install purescript via next tag --- .github/workflows/build.yml | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 87403e72b..2ef07d0df 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,14 +19,14 @@ jobs: include: - os: ubuntu-latest image: haskell:8.10.7-stretch@sha256:100f8fb7d7d8d64adb5e106fe8136b8d4cbdc03aeb2cbd145a7597d74b69bafb - purs_0_15_download_file: linux64 - purs_0_15_binary_file: purs + purs_download_file: linux64 + purs_binary_file: purs - os: macOS-latest - purs_0_15_download_file: macos - purs_0_15_binary_file: purs + purs_download_file: macos + purs_binary_file: purs - os: windows-latest - purs_0_15_download_file: win64 - purs_0_15_binary_file: purs.exe + purs_download_file: win64 + purs_binary_file: purs.exe steps: # We need a proper Git repository, but the checkout step will unpack a tarball instead of doing a clone # if the Git version is less than 2.18. @@ -123,20 +123,9 @@ jobs: run: ./scripts/fix-home stack test shell: bash - - name: Download PureScript 0.15.0 - shell: bash - env: - DL_FILE: ${{ matrix.purs_0_15_download_file }} - BIN_FILE: ${{ matrix.purs_0_15_binary_file }} - run: | - DIR="$HOME/bin/purescript-$PS_0_15_0_VERSION" - mkdir -p "$DIR" - curl -o "$DIR/purescript.tar.gz" -L "https://github.com/purescript/purescript/releases/download/$PS_0_15_0_VERSION/$DL_FILE.tar.gz" - tar -xvf "$DIR/purescript.tar.gz" -C "$DIR" --strip-components 1 "purescript/$BIN_FILE" - chmod a+x "$DIR/$BIN_FILE" + - name: Install PureScript 0.15.0 + run: npm install -g purescript@next - name: Run tests (PureScript >= 0.15.0) shell: bash - run: | - PATH="$HOME/bin/purescript-$PS_0_15_0_VERSION:$PATH" - ./scripts/fix-home stack test --ta "--match purs-0.15" + run: ./scripts/fix-home stack test --ta "--match purs-0.15" From fc89ea18a2d0640bd0d8b4ae72474c8c80f8e880 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 26 Apr 2022 15:41:19 -0500 Subject: [PATCH 82/82] Drop old metadata for previous purs installation --- .github/workflows/build.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2ef07d0df..2af2f670c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,6 @@ on: env: STACK_VERSION: '2.7.3' - PS_0_15_0_VERSION: 'v0.15.0-alpha-04' jobs: build: @@ -19,14 +18,8 @@ jobs: include: - os: ubuntu-latest image: haskell:8.10.7-stretch@sha256:100f8fb7d7d8d64adb5e106fe8136b8d4cbdc03aeb2cbd145a7597d74b69bafb - purs_download_file: linux64 - purs_binary_file: purs - os: macOS-latest - purs_download_file: macos - purs_binary_file: purs - os: windows-latest - purs_download_file: win64 - purs_binary_file: purs.exe steps: # We need a proper Git repository, but the checkout step will unpack a tarball instead of doing a clone # if the Git version is less than 2.18.