Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extra-source-files:
- tests/purs/**/*.js
- tests/purs/**/*.purs
- tests/purs/**/*.json
- tests/json-compat/**/*.json
- tests/support/*.json
- tests/support/setup-win.cmd
- tests/support/psci/**.purs
Expand Down
4 changes: 2 additions & 2 deletions tests/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ main = do
TestUtils.updateSupportCode
heading "Prim documentation test suite"
TestPrimDocs.main
heading "psc-publish test suite"
TestPscPublish.main

ideTests <- TestIde.main
compilerTests <- TestCompiler.main
psciTests <- TestPsci.main
coreFnTests <- TestCoreFn.main
docsTests <- TestDocs.main
publishTests <- TestPscPublish.main
hierarchyTests <- TestHierarchy.main

defaultMain $
Expand All @@ -49,6 +48,7 @@ main = do
, ideTests
, coreFnTests
, docsTests
, publishTests
, hierarchyTests
]

Expand Down
64 changes: 45 additions & 19 deletions tests/TestPscPublish.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,47 @@ module TestPscPublish where
import Prelude

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 Data.Foldable (forM_)
import qualified Text.PrettyPrint.Boxes as Boxes
import System.Directory (listDirectory)
import System.FilePath ((</>))

import Language.PureScript.Docs
import Language.PureScript.Publish
import Language.PureScript.Publish.ErrorsWarnings as Publish

import Test.Tasty
import Test.Tasty.Hspec (Spec, Expectation, runIO, context, it, expectationFailure, testSpec)
import TestUtils

main :: IO ()
main = testPackage
"tests/support/bower_components/purescript-prelude"
"../../prelude-resolutions.json"
main :: IO TestTree
main = testSpec "publish" spec

spec :: Spec
spec = do
it "roundtrips the json for purescript-prelude" $ do
testPackage
"tests/support/bower_components/purescript-prelude"
"../../prelude-resolutions.json"

context "json compatibility" $ do
let compatDir = "tests" </> "json-compat"
versions <- runIO $ listDirectory compatDir
forM_ versions $ \version -> do
context ("json produced by " ++ version) $ do
files <- runIO $ listDirectory (compatDir </> version)
forM_ files $ \file -> do
it file $ do
result <- A.eitherDecodeFileStrict' (compatDir </> version </> file)
case result of
Right (_ :: VerifiedPackage) ->
pure ()
Left err ->
expectationFailure ("JSON parsing failed: " ++ err)

data TestResult
= ParseFailed String
Expand Down Expand Up @@ -51,18 +76,19 @@ testRunOptions = defaultPublishOptions

-- | 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
testPackage :: FilePath -> FilePath -> Expectation
testPackage dir resolutionsFile = do
res <- pushd dir (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
Left err ->
expectationFailure $
"Failed to produce JSON from " ++ dir ++ ":\n" ++
Boxes.render (Publish.renderError err)
Right package ->
case roundTrip package of
Pass _ ->
pure ()
ParseFailed msg ->
expectationFailure ("Failed to re-parse: " ++ msg)
Mismatch _ _ ->
expectationFailure "JSON did not match"
1 change: 1 addition & 0 deletions tests/json-compat/v0.11.3/generics-4.0.0.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/json-compat/v0.11.3/symbols-3.0.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"uploader":"paf31","packageMeta":{"homepage":"https://github.com/purescript/purescript-symbols","repository":{"url":"git://github.com/purescript/purescript-symbols.git","type":"git"},"ignore":["**/.*","bower_components","node_modules","output","test","bower.json","package.json"],"dependencies":{"purescript-prelude":"^3.0.0","purescript-unsafe-coerce":"^3.0.0"},"name":"purescript-symbols","license":["MIT"],"description":"Utilities for working with type-level strings"},"tagTime":"2017-03-26T00:59:23+0000","modules":[{"reExports":[],"name":"Data.Symbol","comments":null,"declarations":[{"children":[{"comments":null,"title":"SProxy","info":{"arguments":[],"declType":"dataConstructor"},"sourceSpan":null}],"comments":"A value-level proxy for a type-level symbol.\n","title":"SProxy","info":{"declType":"data","dataDeclType":"data","typeArguments":[["sym",{"tag":"NamedKind","contents":[["Prim"],"Symbol"]}]]},"sourceSpan":{"start":[12,1],"name":"/private/tmp/pursuit-staging/.psc-package/psc-0.11.3/symbols/v3.0.0/src/Data/Symbol.purs","end":[12,37]}},{"children":[{"comments":null,"title":"reflectSymbol","info":{"declType":"typeClassMember","type":{"tag":"TypeApp","contents":[{"tag":"TypeApp","contents":[{"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"tag":"TypeApp","contents":[{"tag":"TypeConstructor","contents":[["Data","Symbol"],"SProxy"]},{"tag":"TypeVar","contents":"sym"}]}]},{"tag":"TypeConstructor","contents":[["Prim"],"String"]}]}},"sourceSpan":null},{"comments":null,"title":"isSymbolTypeConcat","info":{"declType":"instance","dependencies":[{"constraintClass":[["Data","Symbol"],"IsSymbol"],"constraintArgs":[{"tag":"TypeVar","contents":"left"}],"constraintData":null},{"constraintClass":[["Data","Symbol"],"IsSymbol"],"constraintArgs":[{"tag":"TypeVar","contents":"right"}],"constraintData":null}],"type":{"tag":"TypeApp","contents":[{"tag":"TypeConstructor","contents":[["Data","Symbol"],"IsSymbol"]},{"tag":"ParensInType","contents":{"tag":"TypeApp","contents":[{"tag":"TypeApp","contents":[{"tag":"TypeConstructor","contents":[["Prim"],"TypeConcat"]},{"tag":"TypeVar","contents":"left"}]},{"tag":"TypeVar","contents":"right"}]}}]}},"sourceSpan":{"start":[18,1],"name":"/private/tmp/pursuit-staging/.psc-package/psc-0.11.3/symbols/v3.0.0/src/Data/Symbol.purs","end":[19,100]}}],"comments":"A class for known symbols\n","title":"IsSymbol","info":{"fundeps":[],"arguments":[["sym",{"tag":"NamedKind","contents":[["Prim"],"Symbol"]}]],"declType":"typeClass","superclasses":[]},"sourceSpan":{"start":[15,1],"name":"/private/tmp/pursuit-staging/.psc-package/psc-0.11.3/symbols/v3.0.0/src/Data/Symbol.purs","end":[16,40]}},{"children":[],"comments":null,"title":"reifySymbol","info":{"declType":"value","type":{"tag":"ForAll","contents":["r",{"tag":"TypeApp","contents":[{"tag":"TypeApp","contents":[{"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"tag":"TypeConstructor","contents":[["Prim"],"String"]}]},{"tag":"TypeApp","contents":[{"tag":"TypeApp","contents":[{"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"tag":"ParensInType","contents":{"tag":"ForAll","contents":["sym",{"tag":"ConstrainedType","contents":[{"constraintClass":[["Data","Symbol"],"IsSymbol"],"constraintArgs":[{"tag":"TypeVar","contents":"sym"}],"constraintData":null},{"tag":"TypeApp","contents":[{"tag":"TypeApp","contents":[{"tag":"TypeConstructor","contents":[["Prim"],"Function"]},{"tag":"TypeApp","contents":[{"tag":"TypeConstructor","contents":[["Data","Symbol"],"SProxy"]},{"tag":"TypeVar","contents":"sym"}]}]},{"tag":"TypeVar","contents":"r"}]}]},null]}}]},{"tag":"TypeVar","contents":"r"}]}]},null]}},"sourceSpan":{"start":[21,1],"name":"/private/tmp/pursuit-staging/.psc-package/psc-0.11.3/symbols/v3.0.0/src/Data/Symbol.purs","end":[21,86]}}]}],"resolvedDependencies":{"purescript-prelude":"3.0.0","purescript-unsafe-coerce":"3.0.0"},"version":"3.0.0","github":["purescript","purescript-symbols"],"versionTag":"v3.0.0","moduleMap":{"Data.BooleanAlgebra":"purescript-prelude","Data.Ring":"purescript-prelude","Data.Ord":"purescript-prelude","Data.Boolean":"purescript-prelude","Data.Bounded":"purescript-prelude","Data.Show":"purescript-prelude","Control.Apply":"purescript-prelude","Control.Monad":"purescript-prelude","Control.Bind":"purescript-prelude","Data.HeytingAlgebra":"purescript-prelude","Data.Ord.Unsafe":"purescript-prelude","Data.Semigroup":"purescript-prelude","Data.Semiring":"purescript-prelude","Data.CommutativeRing":"purescript-prelude","Data.NaturalTransformation":"purescript-prelude","Data.Functor":"purescript-prelude","Unsafe.Coerce":"purescript-unsafe-coerce","Control.Category":"purescript-prelude","Data.Function":"purescript-prelude","Data.Field":"purescript-prelude","Data.EuclideanRing":"purescript-prelude","Prelude":"purescript-prelude","Data.Eq":"purescript-prelude","Data.Void":"purescript-prelude","Data.Unit":"purescript-prelude","Data.Ordering":"purescript-prelude","Control.Semigroupoid":"purescript-prelude","Control.Applicative":"purescript-prelude"},"compilerVersion":"0.11.3"}
1 change: 1 addition & 0 deletions tests/json-compat/v0.12.1/typelevel-prelude-3.0.0.json

Large diffs are not rendered by default.