git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Test psc-publish as part of the main test suite
commitab7e5f6bf641cc193075f46cef2ec49b0259f5ee authorHarry Garrood <harry@garrood.me> dateSat 12 Dec 2015, 23:30 (11 years ago) parent8d3b8b3
5 files changed+39−45
.gitmodules+3 purescript.cabal+3−1 tests/Main.hs+10 psc-publish/tests/Test.hs → tests/TestPscPublish.hs+22−44 tests/support/prelude+1
.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
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+10
@@ -68,6 +68,7 @@ import qualified System.FilePath.Glob as Glob
6868import Text.Parsec (ParseError)
6969
7070import TestsSetup
71+import TestPscPublish
7172
7273modulesDir :: FilePath
7374modulesDir = ".test_modules" </> "node_modules"
@@ -171,6 +172,11 @@ assertDoesNotCompile inputFiles foreigns = do
171172
172173main :: IO ()
173174main = 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+
206216supportModules :: [String]
207217supportModules =
208218 [ "Control.Monad.Eff.Class"
psc-publish/tests/Test.hs → tests/TestPscPublish.hsrenamed+22−44
@@ -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
137import Control.Monad
148import Control.Applicative
159import Control.Exception
1610import System.Process
1711import System.Directory
12+import System.IO
13+import System.Exit
1814import qualified Data.ByteString.Lazy as BL
1915import Data.ByteString.Lazy (ByteString)
2016import qualified Data.Aeson as A
2117import Data.Aeson.BetterErrors
2218import Data.Version
2319
24−import Main
2520import Language.PureScript.Docs
2621import Language.PureScript.Publish
2722
28−pkgName = "purescript-prelude"
29−packageUrl = "https://github.com/purescript/" ++ pkgName
30−packageDir = "tmp/" ++ pkgName
31−
3223pushd :: forall a. FilePath -> IO a -> IO a
3324pushd 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−
6731data 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−
7837roundTrip :: UploadedPackage -> TestResult
7938roundTrip 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/preludenew file+1

Submodule changed.