Skip to content
Open
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
79 changes: 57 additions & 22 deletions Cabal-tests/tests/ParserTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@ import Test.Tasty
import Test.Tasty.Golden.Advanced (goldenTest)
import Test.Tasty.HUnit

import Control.Monad (unless, void)
import Control.Monad (void)
import Data.Algorithm.Diff (PolyDiff (..), getGroupedDiff)
import Data.Maybe (isNothing)
import Distribution.Fields (pwarning)
import Distribution.PackageDescription (GenericPackageDescription)
import Distribution.PackageDescription
( GenericPackageDescription
, packageDescription
, gpdScannedVersion
, genPackageFlags
, condLibrary
, condSubLibraries
, condForeignLibs
, condExecutables
, condTestSuites
, condBenchmarks
)
import Distribution.PackageDescription.Parsec (parseGenericPackageDescription)
import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription)
import Distribution.Parsec (PWarnType (..), PWarning (..), showPErrorWithSource, showPWarningWithSource)
Expand Down Expand Up @@ -233,12 +244,22 @@ formatGoldenTest fp = cabalGoldenTest "format" correct $ do
#ifdef MIN_VERSION_tree_diff
treeDiffGoldenTest :: FilePath -> TestTree
treeDiffGoldenTest fp = ediffGolden goldenTest "expr" exprFile $ do
contents <- BS.readFile input
let res = withSource (PCabalFile (fp, contents)) $ parseGenericPackageDescription contents
let (_, x) = runParseResult res
case x of
Right gpd -> pure (toExpr gpd)
Left (_, errs) -> fail $ unlines $ "ERROR" : map (showPErrorWithSource . fmap renderCabalFileSource) (NE.toList errs)
contents <- BS.readFile input
let res = withSource (PCabalFile (fp, contents)) $ parseGenericPackageDescription contents
let (_, x) = runParseResult res
case x of
Right gpd -> pure $ toExpr
( packageDescription gpd
, gpdScannedVersion gpd
, genPackageFlags gpd
, condLibrary gpd
, condSubLibraries gpd
, condForeignLibs gpd
, condExecutables gpd
, condTestSuites gpd
, condBenchmarks gpd
)
Left (_, errs) -> fail $ unlines $ "ERROR" : map (showPErrorWithSource . fmap renderCabalFileSource) (NE.toList errs)
where
input = "tests" </> "ParserTests" </> "regressions" </> fp
exprFile = replaceExtension input "expr"
Expand All @@ -250,24 +271,38 @@ formatRoundTripTest fp = testCase "roundtrip" $ do
x <- parse contents
let contents' = showGenericPackageDescription x
y <- parse (toUTF8BS contents')
-- previously we mangled licenses a bit
let y' = y

let checkField field =
field x == field y @?
{- FOURMOLU_DISABLE -}
unless (x == y') $
#ifdef MIN_VERSION_tree_diff
assertFailure $ unlines
[ "re-parsed doesn't match"
, show $ ansiWlEditExpr $ ediff x y
]
unlines
[ "re-parsed doesn't match"
, show $ ansiWlEditExpr $ ediff x y
]
#else
assertFailure $ unlines
[ "re-parsed doesn't match"
, "expected"
, show x
, "actual"
, show y
]
unlines
[ "re-parsed doesn't match"
, "expected"
, show x
, "actual"
, show y
]
#endif
-- Due to the imports being merged, the structural comparison will fail
-- Instead, we check the equality after merging
sequence_
[ checkField packageDescription
, checkField gpdScannedVersion
, checkField genPackageFlags
, checkField condLibrary
, checkField condSubLibraries
, checkField condForeignLibs
, checkField condExecutables
, checkField condTestSuites
, checkField condBenchmarks
]

where
parse :: BS.ByteString -> IO GenericPackageDescription
parse c = do
Expand Down
31 changes: 15 additions & 16 deletions Cabal-tests/tests/ParserTests/regressions/Octree-0.5.expr
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
GenericPackageDescription {
packageDescription =
`(,,,,,,,,)`
PackageDescription {
specVersion = CabalSpecV1_8,
package = PackageIdentifier {
Expand Down Expand Up @@ -67,10 +66,10 @@ GenericPackageDescription {
extraSrcFiles = [],
extraTmpFiles = [],
extraDocFiles = [],
extraFiles = []},
gpdScannedVersion = Nothing,
genPackageFlags = [],
condLibrary = Just
extraFiles = []}
Nothing
[]
(Just
CondNode {
condTreeData = Library {
libName = LMainLibName,
Expand All @@ -86,11 +85,11 @@ GenericPackageDescription {
buildTools = [],
buildToolDepends = [],
cppOptions = [],
jsppOptions = [],
asmOptions = [],
cmmOptions = [],
ccOptions = [],
cxxOptions = [],
jsppOptions = [],
ldOptions = [],
hsc2hsOptions = [],
pkgconfigDepends = [],
Expand Down Expand Up @@ -178,11 +177,11 @@ GenericPackageDescription {
(OrLaterVersion
(mkVersion [2, 4, 0]))
mainLibSet],
condTreeComponents = []},
condSubLibraries = [],
condForeignLibs = [],
condExecutables = [],
condTestSuites = [
condTreeComponents = []})
[]
[]
[]
[
_×_
(UnqualComponentName
"test_Octree")
Expand All @@ -199,11 +198,11 @@ GenericPackageDescription {
buildTools = [],
buildToolDepends = [],
cppOptions = [],
jsppOptions = [],
asmOptions = [],
cmmOptions = [],
ccOptions = [],
cxxOptions = [],
jsppOptions = [],
ldOptions = [],
hsc2hsOptions = [],
pkgconfigDepends = [],
Expand Down Expand Up @@ -303,11 +302,11 @@ GenericPackageDescription {
buildTools = [],
buildToolDepends = [],
cppOptions = [],
jsppOptions = [],
asmOptions = [],
cmmOptions = [],
ccOptions = [],
cxxOptions = [],
jsppOptions = [],
ldOptions = [],
hsc2hsOptions = [],
pkgconfigDepends = [],
Expand Down Expand Up @@ -400,5 +399,5 @@ GenericPackageDescription {
(PackageName "markdown-unlit")
(OrLaterVersion (mkVersion [0]))
mainLibSet],
condTreeComponents = []}],
condBenchmarks = []}
condTreeComponents = []}]
[]
25 changes: 12 additions & 13 deletions Cabal-tests/tests/ParserTests/regressions/anynone.expr
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
GenericPackageDescription {
packageDescription =
`(,,,,,,,,)`
PackageDescription {
specVersion = CabalSpecV3_0,
package = PackageIdentifier {
Expand Down Expand Up @@ -33,10 +32,10 @@ GenericPackageDescription {
extraSrcFiles = [],
extraTmpFiles = [],
extraDocFiles = [],
extraFiles = []},
gpdScannedVersion = Nothing,
genPackageFlags = [],
condLibrary = Just
extraFiles = []}
Nothing
[]
(Just
CondNode {
condTreeData = Library {
libName = LMainLibName,
Expand All @@ -52,11 +51,11 @@ GenericPackageDescription {
buildTools = [],
buildToolDepends = [],
cppOptions = [],
jsppOptions = [],
asmOptions = [],
cmmOptions = [],
ccOptions = [],
cxxOptions = [],
jsppOptions = [],
ldOptions = [],
hsc2hsOptions = [],
pkgconfigDepends = [],
Expand Down Expand Up @@ -113,9 +112,9 @@ GenericPackageDescription {
(PackageName "base")
(OrLaterVersion (mkVersion [0]))
mainLibSet],
condTreeComponents = []},
condSubLibraries = [],
condForeignLibs = [],
condExecutables = [],
condTestSuites = [],
condBenchmarks = []}
condTreeComponents = []})
[]
[]
[]
[]
[]
25 changes: 12 additions & 13 deletions Cabal-tests/tests/ParserTests/regressions/big-version.expr
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
GenericPackageDescription {
packageDescription =
`(,,,,,,,,)`
PackageDescription {
specVersion = CabalSpecV3_0,
package = PackageIdentifier {
Expand Down Expand Up @@ -35,10 +34,10 @@ GenericPackageDescription {
extraSrcFiles = [],
extraTmpFiles = [],
extraDocFiles = [],
extraFiles = []},
gpdScannedVersion = Nothing,
genPackageFlags = [],
condLibrary = Just
extraFiles = []}
Nothing
[]
(Just
CondNode {
condTreeData = Library {
libName = LMainLibName,
Expand All @@ -53,11 +52,11 @@ GenericPackageDescription {
buildTools = [],
buildToolDepends = [],
cppOptions = [],
jsppOptions = [],
asmOptions = [],
cmmOptions = [],
ccOptions = [],
cxxOptions = [],
jsppOptions = [],
ldOptions = [],
hsc2hsOptions = [],
pkgconfigDepends = [],
Expand Down Expand Up @@ -106,9 +105,9 @@ GenericPackageDescription {
targetBuildDepends = [],
mixins = []}},
condTreeConstraints = [],
condTreeComponents = []},
condSubLibraries = [],
condForeignLibs = [],
condExecutables = [],
condTestSuites = [],
condBenchmarks = []}
condTreeComponents = []})
[]
[]
[]
[]
[]
Loading
Loading