git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1970 from kRITZCREEK/better-psc-publish-error

Better error message for psc-publish tests

commit406695a8bb51d9e0e691d9242196fbe3c542f787 authorPhil Freeman <paf31@cantab.net> dateWed 23 Mar 2016, 11:17 (11 years ago) parente6784521b17b5c
6 files changed+47−19
psc-publish/Main.hs+2−2 src/Language/PureScript/Publish.hs+9−3 src/Language/PureScript/Publish/BoxesHelpers.hs+3 src/Language/PureScript/Publish/ErrorsWarnings.hs+4 tests/TestDocs.hs+11−8 tests/TestPscPublish.hs+18−6
psc-publish/Main.hs+2−2
@@ -38,8 +38,8 @@ publish :: Bool -> IO ()
3838publish isDryRun =
3939 if isDryRun
4040 then do
41− _ <- preparePackage dryRunOptions
41+ _ <- unsafePreparePackage dryRunOptions
4242 putStrLn "Dry run completed, no errors."
4343 else do
44− pkg <- preparePackage defaultPublishOptions
44+ pkg <- unsafePreparePackage defaultPublishOptions
4545 BL.putStrLn (A.encode pkg)
src/Language/PureScript/Publish.hs+9−3
@@ -6,6 +6,7 @@
66module Language.PureScript.Publish
77 ( preparePackage
88 , preparePackage'
9+ , unsafePreparePackage
910 , PrepareM()
1011 , runPrepareM
1112 , warn
@@ -79,11 +80,16 @@ defaultPublishOptions = PublishOptions
7980
8081-- | Attempt to retrieve package metadata from the current directory.
8182-- Calls exitFailure if no package metadata could be retrieved.
82−preparePackage :: PublishOptions -> IO D.UploadedPackage
83+unsafePreparePackage :: PublishOptions -> IO D.UploadedPackage
84+unsafePreparePackage opts = either (\e -> printError e >> exitFailure) pure =<< preparePackage opts
85+
86+-- | Attempt to retrieve package metadata from the current directory.
87+-- Returns a PackageError on failure
88+preparePackage :: PublishOptions -> IO (Either PackageError D.UploadedPackage)
8389preparePackage opts =
8490 runPrepareM (preparePackage' opts)
85− >>= either (\e -> printError e >> exitFailure)
86− handleWarnings
91+ >>= either (pure . Left) (fmap Right . handleWarnings)
92+
8793 where
8894 handleWarnings (result, warns) = do
8995 printWarnings warns
src/Language/PureScript/Publish/BoxesHelpers.hs+3
@@ -36,3 +36,6 @@ bulletedList f = map (indented . para . ("* " ++) . f)
3636
3737printToStderr :: Boxes.Box -> IO ()
3838printToStderr = hPutStr stderr . Boxes.render
39+
40+printToStdout :: Boxes.Box -> IO ()
41+printToStdout = putStr . Boxes.render
src/Language/PureScript/Publish/ErrorsWarnings.hs+4
@@ -10,6 +10,7 @@ module Language.PureScript.Publish.ErrorsWarnings
1010 , RepositoryFieldError(..)
1111 , JSONSource(..)
1212 , printError
13+ , printErrorToStdout
1314 , renderError
1415 , printWarnings
1516 , renderWarnings
@@ -88,6 +89,9 @@ data OtherError
8889printError :: PackageError -> IO ()
8990printError = printToStderr . renderError
9091
92+printErrorToStdout :: PackageError -> IO ()
93+printErrorToStdout = printToStdout . renderError
94+
9195renderError :: PackageError -> Box
9296renderError err =
9397 case err of
tests/TestDocs.hs+11−8
@@ -18,6 +18,7 @@ import System.Exit
1818import qualified Language.PureScript as P
1919import qualified Language.PureScript.Docs as Docs
2020import qualified Language.PureScript.Publish as Publish
21+import qualified Language.PureScript.Publish.ErrorsWarnings as Publish
2122
2223import TestUtils
2324
@@ -29,16 +30,18 @@ publishOpts = Publish.defaultPublishOptions
2930 where testVersion = ("v999.0.0", Version [999,0,0] [])
3031
3132main :: IO ()
32−main = do
33− pushd "examples/docs" $ do
34− Docs.Package{..} <- Publish.preparePackage publishOpts
35− forM_ testCases $ \(P.moduleNameFromString -> mn, pragmas) ->
36− let mdl = takeJust ("module not found in docs: " ++ P.runModuleName mn)
37− (find ((==) mn . Docs.modName) pkgModules)
38− in forM_ pragmas (flip runAssertionIO mdl)
33+main = pushd "examples/docs" $ do
34+ res <- Publish.preparePackage publishOpts
35+ case res of
36+ Left e -> Publish.printErrorToStdout e >> exitFailure
37+ Right Docs.Package{..} ->
38+ forM_ testCases $ \(P.moduleNameFromString -> mn, pragmas) ->
39+ let mdl = takeJust ("module not found in docs: " ++ P.runModuleName mn)
40+ (find ((==) mn . Docs.modName) pkgModules)
41+ in forM_ pragmas (flip runAssertionIO mdl)
3942
4043takeJust :: String -> Maybe a -> a
41−takeJust msg = maybe (error msg) id
44+takeJust msg = fromMaybe (error msg)
4245
4346data Assertion
4447 -- | Assert that a particular declaration is documented with the given
tests/TestPscPublish.hs+18−6
@@ -19,12 +19,12 @@ import Data.Version
1919
2020import Language.PureScript.Docs
2121import Language.PureScript.Publish
22+import Language.PureScript.Publish.ErrorsWarnings as Publish
2223
2324import TestUtils
2425
2526main :: IO ()
26−main = do
27− testPackage "tests/support/prelude"
27+main = testPackage "tests/support/prelude"
2828
2929data TestResult
3030 = ParseFailed String
@@ -53,10 +53,11 @@ testRunOptions = defaultPublishOptions
5353-- | Given a directory which contains a package, produce JSON from it, and then
5454-- | attempt to parse it again, and ensure that it doesn't change.
5555testPackage :: String -> IO ()
56−testPackage dir = do
57− pushd dir $ do
58− r <- roundTrip <$> preparePackage testRunOptions
59− case r of
56+testPackage dir = pushd dir $ do
57+ res <- preparePackage testRunOptions
58+ case res of
59+ Left e -> preparePackageError e
60+ Right package -> case roundTrip package of
6061 Pass _ -> do
6162 putStrLn ("psc-publish test passed for: " ++ dir)
6263 pure ()
@@ -64,3 +65,14 @@ testPackage dir = do
6465 putStrLn ("psc-publish tests failed on " ++ dir ++ ":")
6566 putStrLn (show other)
6667 exitFailure
68+ where
69+ preparePackageError e@(UserError BowerJSONNotFound) = do
70+ Publish.printErrorToStdout e
71+ putStrLn ""
72+ putStrLn "=========================================="
73+ putStrLn "Did you forget to update the submodules?"
74+ putStrLn "$ git submodule sync; git submodule update"
75+ putStrLn "=========================================="
76+ putStrLn ""
77+ exitFailure
78+ preparePackageError e = Publish.printErrorToStdout e >> exitFailure