Skip to content

Commit ab7e5f6

Browse files
hdgarroodgaryb
authored andcommitted
Test psc-publish as part of the main test suite
1 parent 8d3b8b3 commit ab7e5f6

File tree

5 files changed

+39
-45
lines changed

5 files changed

+39
-45
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "tests/support/prelude"]
2+
path = tests/support/prelude
3+
url = https://github.com/purescript/purescript-prelude

purescript.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,12 @@ test-suite tests
261261
build-depends: base >=4 && <5, containers -any, directory -any,
262262
filepath -any, mtl -any, parsec -any, purescript -any,
263263
transformers -any, process -any, transformers-compat -any, time -any,
264-
Glob -any, base-compat >=0.6.0
264+
Glob -any, aeson-better-errors -any, bytestring -any, aeson -any,
265+
base-compat -any
265266
type: exitcode-stdio-1.0
266267
main-is: Main.hs
267268
other-modules: TestsSetup
269+
TestPscPublish
268270
buildable: True
269271
hs-source-dirs: tests tests/common
270272

tests/Main.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import qualified System.FilePath.Glob as Glob
6868
import Text.Parsec (ParseError)
6969

7070
import TestsSetup
71+
import TestPscPublish
7172

7273
modulesDir :: FilePath
7374
modulesDir = ".test_modules" </> "node_modules"
@@ -171,6 +172,11 @@ assertDoesNotCompile inputFiles foreigns = do
171172

172173
main :: IO ()
173174
main = do
175+
testCompiler
176+
testPscPublish
177+
178+
testCompiler :: IO ()
179+
testCompiler = do
174180
fetchSupportCode
175181
cwd <- getCurrentDirectory
176182

@@ -203,6 +209,10 @@ main = do
203209
in putStrLn $ fp' ++ ": " ++ err
204210
exitFailure
205211

212+
testPscPublish :: IO ()
213+
testPscPublish = do
214+
testPackage "tests/support/prelude"
215+
206216
supportModules :: [String]
207217
supportModules =
208218
[ "Control.Monad.Eff.Class"
Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,24 @@
22
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
33
{-# LANGUAGE ScopedTypeVariables #-}
44

5-
-- | To run these tests:
6-
--
7-
-- * `cabal repl psc-publish`
8-
-- * `:l psc-publish/tests/Test.hs`
9-
-- * `test`
10-
11-
module Test where
5+
module TestPscPublish where
126

137
import Control.Monad
148
import Control.Applicative
159
import Control.Exception
1610
import System.Process
1711
import System.Directory
12+
import System.IO
13+
import System.Exit
1814
import qualified Data.ByteString.Lazy as BL
1915
import Data.ByteString.Lazy (ByteString)
2016
import qualified Data.Aeson as A
2117
import Data.Aeson.BetterErrors
2218
import Data.Version
2319

24-
import Main
2520
import Language.PureScript.Docs
2621
import Language.PureScript.Publish
2722

28-
pkgName = "purescript-prelude"
29-
packageUrl = "https://github.com/purescript/" ++ pkgName
30-
packageDir = "tmp/" ++ pkgName
31-
3223
pushd :: forall a. FilePath -> IO a -> IO a
3324
pushd dir act = do
3425
original <- getCurrentDirectory
@@ -37,44 +28,12 @@ pushd dir act = do
3728
setCurrentDirectory original
3829
either throwIO return result
3930

40-
clonePackage :: IO ()
41-
clonePackage = do
42-
createDirectoryIfMissing True packageDir
43-
pushd packageDir $ do
44-
exists <- doesDirectoryExist ".git"
45-
unless exists $ do
46-
putStrLn ("Cloning " ++ pkgName ++ " into " ++ packageDir ++ "...")
47-
readProcess "git" ["clone", packageUrl, "."] "" >>= putStr
48-
readProcess "git" ["tag", "v999.0.0"] "" >>= putStr
49-
50-
bowerInstall :: IO ()
51-
bowerInstall =
52-
pushd packageDir $
53-
readProcess "bower" ["install"] "" >>= putStr
54-
55-
testRunOptions :: PublishOptions
56-
testRunOptions = defaultPublishOptions
57-
{ publishGetVersion = return testVersion
58-
}
59-
where testVersion = ("v999.0.0", Version [999,0,0] [])
60-
61-
getPackage :: IO UploadedPackage
62-
getPackage = do
63-
clonePackage
64-
bowerInstall
65-
pushd packageDir $ preparePackage testRunOptions
66-
6731
data TestResult
6832
= ParseFailed String
6933
| Mismatch ByteString ByteString -- ^ encoding before, encoding after
7034
| Pass ByteString
7135
deriving (Show, Read)
7236

73-
-- | Test JSON encoding/decoding; parse the package, roundtrip to/from JSON,
74-
-- and check we get the same string.
75-
test :: IO TestResult
76-
test = roundTrip <$> getPackage
77-
7837
roundTrip :: UploadedPackage -> TestResult
7938
roundTrip pkg =
8039
let before = A.encode pkg
@@ -85,3 +44,22 @@ roundTrip pkg =
8544
if before == after
8645
then Pass before
8746
else Mismatch before after
47+
48+
testRunOptions :: PublishOptions
49+
testRunOptions = defaultPublishOptions
50+
{ publishGetVersion = return testVersion
51+
}
52+
where testVersion = ("v999.0.0", Version [999,0,0] [])
53+
54+
-- | Given a directory which contains a package, produce JSON from it, and then
55+
-- | attempt to parse it again, and ensure that it doesn't change.
56+
testPackage :: String -> IO ()
57+
testPackage dir = do
58+
pushd dir $ do
59+
r <- roundTrip <$> preparePackage testRunOptions
60+
case r of
61+
Pass _ -> pure ()
62+
other -> do
63+
hPutStrLn stderr ("psc-publish tests failed on " ++ dir ++ ":")
64+
hPutStrLn stderr (show other)
65+
exitFailure

tests/support/prelude

Submodule prelude added at 5b8da18

0 commit comments

Comments
 (0)