forked from purescript/purescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestPscPublish.hs
More file actions
66 lines (57 loc) · 2.05 KB
/
Copy pathTestPscPublish.hs
File metadata and controls
66 lines (57 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
module TestPscPublish where
import Control.Monad.IO.Class (liftIO)
import System.Exit (exitFailure)
import Data.ByteString.Lazy (ByteString)
import Data.Time.Clock (getCurrentTime)
import qualified Data.Aeson as A
import Data.Version
import Language.PureScript.Docs
import Language.PureScript.Publish
import Language.PureScript.Publish.ErrorsWarnings as Publish
import TestUtils
main :: IO ()
main = testPackage
"tests/support/bower_components/purescript-prelude"
"../../prelude-resolutions.json"
data TestResult
= ParseFailed String
| Mismatch ByteString ByteString -- ^ encoding before, encoding after
| Pass ByteString
deriving (Show)
roundTrip :: UploadedPackage -> TestResult
roundTrip pkg =
let before = A.encode pkg
in case A.eitherDecode before of
Left err -> ParseFailed err
Right parsed -> do
let after = A.encode (parsed :: UploadedPackage)
if before == after
then Pass before
else Mismatch before after
testRunOptions :: PublishOptions
testRunOptions = defaultPublishOptions
{ publishGetVersion = return testVersion
, publishGetTagTime = const (liftIO getCurrentTime)
, publishWorkingTreeDirty = return ()
}
where testVersion = ("v999.0.0", Version [999,0,0] [])
-- | Given a directory which contains a package, produce JSON from it, and then
-- | attempt to parse it again, and ensure that it doesn't change.
testPackage :: FilePath -> FilePath -> IO ()
testPackage dir resolutionsFile = pushd dir $ do
res <- preparePackage "bower.json" resolutionsFile testRunOptions
case res of
Left e -> preparePackageError e
Right package -> case roundTrip package of
Pass _ -> do
putStrLn ("psc-publish test passed for: " ++ dir)
pure ()
other -> do
putStrLn ("psc-publish tests failed on " ++ dir ++ ":")
print other
exitFailure
where
preparePackageError e = Publish.printErrorToStdout e >> exitFailure