Skip to content
Snippets Groups Projects
Commit 14509f06 authored by Oleg Grenrus's avatar Oleg Grenrus
Browse files

Add golden tests for checkPackage

parent db8b858e
No related branches found
No related tags found
No related merge requests found
......@@ -392,6 +392,20 @@ test-suite parser-tests
ghc-options: -Wall
default-language: Haskell2010
test-suite check-tests
type: exitcode-stdio-1.0
hs-source-dirs: tests
main-is: CheckTests.hs
build-depends:
base,
bytestring,
filepath,
tasty,
tasty-golden >=2.3.1.1 && <2.4,
Cabal
ghc-options: -Wall
default-language: Haskell2010
test-suite parser-hackage-tests
type: exitcode-stdio-1.0
main-is: ParserHackageTests.hs
......
module Main
( main
) where
import Test.Tasty
import Test.Tasty.Golden (goldenVsString)
import Distribution.PackageDescription.Parsec (parseGenericPackageDescription)
import Distribution.PackageDescription.Check (checkPackage)
import Distribution.Parsec.Types.ParseResult (runParseResult)
import Distribution.Utils.Generic (toUTF8LBS)
import System.FilePath ((</>), replaceExtension)
import qualified Data.ByteString as BS
tests :: TestTree
tests = checkTests
-------------------------------------------------------------------------------
-- Regressions
-------------------------------------------------------------------------------
checkTests :: TestTree
checkTests = testGroup "regressions"
[ checkTest "nothing-unicode.cabal"
]
checkTest :: FilePath -> TestTree
checkTest fp = goldenVsString fp correct $ do
contents <- BS.readFile input
let res = parseGenericPackageDescription contents
let (_, errs, x) = runParseResult res
return $ toUTF8LBS $ case x of
Just gpd | null errs ->
unlines $ map show (checkPackage gpd Nothing)
_ ->
unlines $ "ERROR" : map show errs
where
input = "tests" </> "ParserTests" </> "regressions" </> fp
correct = replaceExtension input "check"
-------------------------------------------------------------------------------
-- Main
-------------------------------------------------------------------------------
main :: IO ()
main = defaultMain tests
......@@ -12,7 +12,7 @@ import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescriptio
import Distribution.Parsec.Types.Common (PWarnType (..), PWarning (..))
import Distribution.Parsec.Types.ParseResult (runParseResult)
import Distribution.Utils.Generic (toUTF8LBS)
import System.FilePath ((</>), (-<.>))
import System.FilePath ((</>), replaceExtension)
import qualified Data.ByteString as BS
......@@ -83,7 +83,7 @@ regressionTest fp = goldenVsString fp correct $ do
unlines $ "ERROR" : map show errs
where
input = "tests" </> "ParserTests" </> "regressions" </> fp
correct = input -<.> "golden"
correct = replaceExtension input "format"
-------------------------------------------------------------------------------
-- Main
......
No 'category' field.
No 'maintainer' field.
No 'description' field.
The 'license' field is missing.
Suspicious flag names: 無. To avoid ambiguity in command line interfaces, flag shouldn't start with a dash. Also for better compatibility, flag names shouldn't contain non-ascii characters.
Non ascii custom fields: x-無. For better compatibility, custom field names shouldn't contain non-ascii characters.
......@@ -98,7 +98,7 @@ if [ "x$CABAL_INSTALL_ONLY" != "xYES" ] ; then
# NB: Best to do everything for a single package together as it's
# more efficient (since new-build will uselessly try to rebuild
# Cabal otherwise).
timed cabal new-build $jobs -fparsec Cabal Cabal:unit-tests Cabal:parser-tests Cabal:parser-hackage-tests
timed cabal new-build $jobs -fparsec Cabal Cabal:unit-tests Cabal:check-tests Cabal:parser-tests Cabal:parser-hackage-tests
# Run haddock
(cd Cabal && timed cabal act-as-setup --build-type=Simple -- haddock --builddir=${CABAL_BDIR}) || exit $?
......
......@@ -13,11 +13,14 @@ ln -s $TRAVIS_BUILD_DIR $UPSTREAM_BUILD_DIR
# Run tests
(timed Cabal/unit-tests $TEST_OPTIONS) || exit $?
# Parser unit tests
(cd Cabal && timed ./parser-tests $TEST_OPTIONS) || exit $?
# Check tests
(cd Cabal && timed ./check-tests $TEST_OPTIONS) || exit $?
# Test we can parse Hackage
(cd Cabal && timed ./parser-hackage-tests $TEST_OPTIONS) | tail || exit $?
# Parser unit tests
(cd Cabal && timed ./parser-tests $TEST_OPTIONS) || exit $?
# Test we can parse Hackage
(cd Cabal && timed ./parser-hackage-tests $TEST_OPTIONS) | tail || exit $?
if [ "x$CABAL_LIB_ONLY" = "xYES" ]; then
exit 0;
......
......@@ -71,6 +71,7 @@ cp $TRAVIS_BUILD_DIR/travis-install.sh .
cp $TRAVIS_BUILD_DIR/travis-common.sh .
# The binaries to test (statically linked, of course!)
cp ${CABAL_BDIR}/c/unit-tests/build/unit-tests/unit-tests Cabal
cp ${CABAL_BDIR}/c/check-tests/build/check-tests/check-tests Cabal
cp ${CABAL_BDIR}/c/parser-tests/build/parser-tests/parser-tests Cabal
cp ${CABAL_BDIR}/c/parser-hackage-tests/build/parser-hackage-tests/parser-hackage-tests Cabal
if [ "x$CABAL_LIB_ONLY" != "xYES" ]; then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment