@@ -2,33 +2,24 @@
2{-# OPTIONS_GHC -fno-warn-unused-imports #-}
2{-# OPTIONS_GHC -fno-warn-unused-imports #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
5−-- | To run these tests:
7−-- * `cabal repl psc-publish`
8−-- * `:l psc-publish/tests/Test.hs`
11−module Test where
5+module TestPscPublish where
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
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
25import Language.PureScript.Docs
20import Language.PureScript.Docs
26import Language.PureScript.Publish
21import Language.PureScript.Publish
28−pkgName = "purescript-prelude"
29−packageUrl = "https://github.com/purescript/" ++ pkgName
30−packageDir = "tmp/" ++ pkgName
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
42− createDirectoryIfMissing True packageDir
43− pushd packageDir $ do
44− exists <- doesDirectoryExist ".git"
46− putStrLn ("Cloning " ++ pkgName ++ " into " ++ packageDir ++ "...")
47− readProcess "git" ["clone", packageUrl, "."] "" >>= putStr
48− readProcess "git" ["tag", "v999.0.0"] "" >>= putStr
53− readProcess "bower" ["install"] "" >>= putStr
55−testRunOptions :: PublishOptions
56−testRunOptions = defaultPublishOptions
57− { publishGetVersion = return testVersion
59− where testVersion = ("v999.0.0", Version [999,0,0] [])
61−getPackage :: IO UploadedPackage
65− pushd packageDir $ preparePackage testRunOptions
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)
73−-- | Test JSON encoding/decoding; parse the package, roundtrip to/from JSON,
74−-- and check we get the same string.
76−test = roundTrip <$> getPackage
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
48+testRunOptions :: PublishOptions
49+testRunOptions = defaultPublishOptions
50+ { publishGetVersion = return testVersion
52+ where testVersion = ("v999.0.0", Version [999,0,0] [])
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 ()
59+ r <- roundTrip <$> preparePackage testRunOptions
63+ hPutStrLn stderr ("psc-publish tests failed on " ++ dir ++ ":")
64+ hPutStrLn stderr (show other)