git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Test psc-publish as part of the main test suite
ab7e5f6Harry Garrood
.gitmodulesnew file+3
@@ -0,0 +1,3 @@
1+[submodule "tests/support/prelude"]
2+ path = tests/support/prelude
3+ url = https://github.com/purescript/purescript-prelude
purescript.cabal+3−1
@@ -261,10 +261,12 @@ test-suite tests
261 build-depends: base >=4 && <5, containers -any, directory -any,
261 build-depends: base >=4 && <5, containers -any, directory -any,
262 filepath -any, mtl -any, parsec -any, purescript -any,
262 filepath -any, mtl -any, parsec -any, purescript -any,
263 transformers -any, process -any, transformers-compat -any, time -any,
263 transformers -any, process -any, transformers-compat -any, time -any,
264+ Glob -any, aeson-better-errors -any, bytestring -any, aeson -any,
264− Glob -any, base-compat >=0.6.0
265+ base-compat -any
265 type: exitcode-stdio-1.0
266 type: exitcode-stdio-1.0
266 main-is: Main.hs
267 main-is: Main.hs
267 other-modules: TestsSetup
268 other-modules: TestsSetup
269+ TestPscPublish
268 buildable: True
270 buildable: True
269 hs-source-dirs: tests tests/common
271 hs-source-dirs: tests tests/common
270
272
tests/Main.hs+10
@@ -68,6 +68,7 @@ import qualified System.FilePath.Glob as Glob
68import Text.Parsec (ParseError)
68import Text.Parsec (ParseError)
69
69
70import TestsSetup
70import TestsSetup
71+import TestPscPublish
71
72
72modulesDir :: FilePath
73modulesDir :: FilePath
73modulesDir = ".test_modules" </> "node_modules"
74modulesDir = ".test_modules" </> "node_modules"
@@ -171,6 +172,11 @@ assertDoesNotCompile inputFiles foreigns = do
171
172
172main :: IO ()
173main :: IO ()
173main = do
174main = do
175+ testCompiler
176+ testPscPublish
177+
178+testCompiler :: IO ()
179+testCompiler = do
174 fetchSupportCode
180 fetchSupportCode
175 cwd <- getCurrentDirectory
181 cwd <- getCurrentDirectory
176
182
@@ -203,6 +209,10 @@ main = do
203 in putStrLn $ fp' ++ ": " ++ err
209 in putStrLn $ fp' ++ ": " ++ err
204 exitFailure
210 exitFailure
205
211
212+testPscPublish :: IO ()
213+testPscPublish = do
214+ testPackage "tests/support/prelude"
215+
206supportModules :: [String]
216supportModules :: [String]
207supportModules =
217supportModules =
208 [ "Control.Monad.Eff.Class"
218 [ "Control.Monad.Eff.Class"
psc-publish/tests/Test.hs → tests/TestPscPublish.hsrenamed+22−44
@@ -2,33 +2,24 @@
2{-# OPTIONS_GHC -fno-warn-unused-imports #-}
2{-# OPTIONS_GHC -fno-warn-unused-imports #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4
4
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
12
6
13import Control.Monad
7import Control.Monad
14import Control.Applicative
8import Control.Applicative
15import Control.Exception
9import Control.Exception
16import System.Process
10import System.Process
17import System.Directory
11import System.Directory
12+import System.IO
13+import System.Exit
18import qualified Data.ByteString.Lazy as BL
14import qualified Data.ByteString.Lazy as BL
19import Data.ByteString.Lazy (ByteString)
15import Data.ByteString.Lazy (ByteString)
20import qualified Data.Aeson as A
16import qualified Data.Aeson as A
21import Data.Aeson.BetterErrors
17import Data.Aeson.BetterErrors
22import Data.Version
18import Data.Version
23
19
24−import Main
25import Language.PureScript.Docs
20import Language.PureScript.Docs
26import Language.PureScript.Publish
21import Language.PureScript.Publish
27
22
28−pkgName = "purescript-prelude"
29−packageUrl = "https://github.com/purescript/" ++ pkgName
30−packageDir = "tmp/" ++ pkgName
31−
32pushd :: forall a. FilePath -> IO a -> IO a
23pushd :: forall a. FilePath -> IO a -> IO a
33pushd dir act = do
24pushd dir act = do
34 original <- getCurrentDirectory
25 original <- getCurrentDirectory
@@ -37,44 +28,12 @@ pushd dir act = do
37 setCurrentDirectory original
28 setCurrentDirectory original
38 either throwIO return result
29 either throwIO return result
39
30
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−
67data TestResult
31data TestResult
68 = ParseFailed String
32 = ParseFailed String
69 | Mismatch ByteString ByteString -- ^ encoding before, encoding after
33 | Mismatch ByteString ByteString -- ^ encoding before, encoding after
70 | Pass ByteString
34 | Pass ByteString
71 deriving (Show, Read)
35 deriving (Show, Read)
72
36
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−
78roundTrip :: UploadedPackage -> TestResult
37roundTrip :: UploadedPackage -> TestResult
79roundTrip pkg =
38roundTrip pkg =
80 let before = A.encode pkg
39 let before = A.encode pkg
@@ -85,3 +44,22 @@ roundTrip pkg =
85 if before == after
44 if before == after
86 then Pass before
45 then Pass before
87 else Mismatch before after
46 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/preludenew file+1

Submodule changed.