Skip to content

Commit d8a1fcc

Browse files
committed
Merge branch 'accessor-tests' into no-flatten-package-description
2 parents 928c836 + 1da8c79 commit d8a1fcc

File tree

422 files changed

+23714
-23860
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

422 files changed

+23714
-23860
lines changed

Cabal-tests/tests/ParserTests.hs

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,18 @@ import Control.Monad (unless, void)
1414
import Data.Algorithm.Diff (PolyDiff (..), getGroupedDiff)
1515
import Data.Maybe (isNothing)
1616
import Distribution.Fields (pwarning)
17-
import Distribution.PackageDescription (GenericPackageDescription)
18-
import Distribution.Types.GenericPackageDescription(condLibrary)
17+
import Distribution.PackageDescription
18+
( GenericPackageDescription
19+
, packageDescription
20+
, gpdScannedVersion
21+
, genPackageFlags
22+
, condLibrary
23+
, condSubLibraries
24+
, condForeignLibs
25+
, condExecutables
26+
, condTestSuites
27+
, condBenchmarks
28+
)
1929
import Distribution.PackageDescription.Parsec (parseGenericPackageDescription)
2030
import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription)
2131
import Distribution.Parsec (PWarnType (..), PWarning (..), showPErrorWithSource, showPWarningWithSource)
@@ -35,15 +45,13 @@ import qualified Distribution.InstalledPackageInfo as IPI
3545

3646
#ifdef MIN_VERSION_tree_diff
3747
import Data.TreeDiff (ansiWlEditExpr, ediff, toExpr)
38-
import Data.TreeDiff.Class (ToExpr)
3948
import Data.TreeDiff.Golden (ediffGolden)
4049
import Data.TreeDiff.Instances.Cabal ()
4150
#endif
4251

4352
tests :: TestTree
4453
tests = testGroup "parsec tests"
4554
[ regressionTests
46-
, accessorsTests
4755
, warningTests
4856
, errorTests
4957
, ipiTests
@@ -153,40 +161,6 @@ errorTest fp = cabalGoldenTest fp correct $ do
153161
input = "tests" </> "ParserTests" </> "errors" </> fp
154162
correct = replaceExtension input "errors"
155163

156-
-------------------------------------------------------------------------------
157-
-- Merging accessors tests
158-
-------------------------------------------------------------------------------
159-
160-
accessorsTests :: TestTree
161-
accessorsTests = testGroup "accessors"
162-
[
163-
#ifdef MIN_VERSION_tree_diff
164-
accessorsGoldenTestCondLibrary
165-
[ "library-merging.cabal"
166-
]
167-
#endif
168-
]
169-
170-
#ifdef MIN_VERSION_tree_diff
171-
accessorsGoldenTestCondLibrary :: [FilePath] -> TestTree
172-
accessorsGoldenTestCondLibrary = testGroup "condLibrary" . map (accessorsGoldenTest condLibrary)
173-
174-
accessorsGoldenTest
175-
:: ToExpr a
176-
=> (GenericPackageDescription -> a)
177-
-> FilePath -> TestTree
178-
accessorsGoldenTest f fp = ediffGolden goldenTest fp exprFile $ do
179-
contents <- BS.readFile input
180-
let res = withSource (PCabalFile (fp, contents)) $ parseGenericPackageDescription contents
181-
let (_, x) = runParseResult res
182-
case x of
183-
Right gpd -> pure . toExpr $ f gpd
184-
Left (_, errs) -> fail $ unlines $ "ERROR" : map (showPErrorWithSource . fmap renderCabalFileSource) (NE.toList errs)
185-
where
186-
input = "tests" </> "ParserTests" </> "accessors" </> fp
187-
exprFile = replaceExtension input "expr"
188-
#endif
189-
190164
-------------------------------------------------------------------------------
191165
-- Regressions
192166
-------------------------------------------------------------------------------
@@ -270,16 +244,29 @@ formatGoldenTest fp = cabalGoldenTest "format" correct $ do
270244

271245
#ifdef MIN_VERSION_tree_diff
272246
treeDiffGoldenTest :: FilePath -> TestTree
273-
treeDiffGoldenTest fp = ediffGolden goldenTest "expr" exprFile $ do
274-
contents <- BS.readFile input
275-
let res = withSource (PCabalFile (fp, contents)) $ parseGenericPackageDescription contents
276-
let (_, x) = runParseResult res
277-
case x of
278-
Right gpd -> pure (toExpr gpd)
279-
Left (_, errs) -> fail $ unlines $ "ERROR" : map (showPErrorWithSource . fmap renderCabalFileSource) (NE.toList errs)
280-
where
281-
input = "tests" </> "ParserTests" </> "regressions" </> fp
282-
exprFile = replaceExtension input "expr"
247+
treeDiffGoldenTest fp =
248+
let go label f = ediffGolden goldenTest label exprFile $ do
249+
contents <- BS.readFile input
250+
let res = withSource (PCabalFile (fp, contents)) $ parseGenericPackageDescription contents
251+
let (_, x) = runParseResult res
252+
case x of
253+
Right gpd -> pure (toExpr $ f gpd)
254+
Left (_, errs) -> fail $ unlines $ "ERROR" : map (showPErrorWithSource . fmap renderCabalFileSource) (NE.toList errs)
255+
where
256+
input = "tests" </> "ParserTests" </> "regressions" </> fp
257+
exprFile = replaceExtension input (label <> ".expr")
258+
in testGroup "expr"
259+
[ go "packageDescription" packageDescription
260+
, go "gpdScannedVersion" gpdScannedVersion
261+
, go "genPackageFlags" genPackageFlags
262+
-- Test accessors because they encapsulate the merging behaviour
263+
, go "condLibrary" condLibrary
264+
, go "condSubLibraries" condSubLibraries
265+
, go "condForeignLibs" condForeignLibs
266+
, go "condExecutables" condExecutables
267+
, go "condTestSuites" condTestSuites
268+
, go "condBenchmarks" condBenchmarks
269+
]
283270
#endif
284271

285272
formatRoundTripTest :: FilePath -> TestTree
@@ -288,24 +275,38 @@ formatRoundTripTest fp = testCase "roundtrip" $ do
288275
x <- parse contents
289276
let contents' = showGenericPackageDescription x
290277
y <- parse (toUTF8BS contents')
291-
-- previously we mangled licenses a bit
292-
let y' = y
278+
279+
let checkField field =
280+
unless (field x == field y) $
293281
{- FOURMOLU_DISABLE -}
294-
unless (x == y') $
295282
#ifdef MIN_VERSION_tree_diff
296-
assertFailure $ unlines
297-
[ "re-parsed doesn't match"
298-
, show $ ansiWlEditExpr $ ediff x y
299-
]
283+
assertFailure $ unlines
284+
[ "re-parsed doesn't match"
285+
, show $ ansiWlEditExpr $ ediff x y
286+
]
300287
#else
301-
assertFailure $ unlines
302-
[ "re-parsed doesn't match"
303-
, "expected"
304-
, show x
305-
, "actual"
306-
, show y
307-
]
288+
assertFailure $ unlines
289+
[ "re-parsed doesn't match"
290+
, "expected"
291+
, show x
292+
, "actual"
293+
, show y
294+
]
308295
#endif
296+
-- Due to the imports being merged, the structural comparison will fail
297+
-- Instead, we check the equality after merging
298+
sequence_
299+
[ checkField packageDescription
300+
, checkField gpdScannedVersion
301+
, checkField genPackageFlags
302+
, checkField condLibrary
303+
, checkField condSubLibraries
304+
, checkField condForeignLibs
305+
, checkField condExecutables
306+
, checkField condTestSuites
307+
, checkField condBenchmarks
308+
]
309+
309310
where
310311
parse :: BS.ByteString -> IO GenericPackageDescription
311312
parse c = do
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
Just
2+
CondNode {
3+
condTreeData = Library {
4+
libName = LMainLibName,
5+
exposedModules = [
6+
ModuleName "Data.Octree"],
7+
reexportedModules = [],
8+
signatures = [],
9+
libExposed = True,
10+
libVisibility =
11+
LibraryVisibilityPublic,
12+
libBuildInfo = BuildInfo {
13+
buildable = True,
14+
buildTools = [],
15+
buildToolDepends = [],
16+
cppOptions = [],
17+
asmOptions = [],
18+
cmmOptions = [],
19+
ccOptions = [],
20+
cxxOptions = [],
21+
jsppOptions = [],
22+
ldOptions = [],
23+
hsc2hsOptions = [],
24+
pkgconfigDepends = [],
25+
frameworks = [],
26+
extraFrameworkDirs = [],
27+
asmSources = [],
28+
cmmSources = [],
29+
cSources = [],
30+
cxxSources = [],
31+
jsSources = [],
32+
hsSourceDirs = [],
33+
otherModules = [
34+
ModuleName
35+
"Data.Octree.Internal"],
36+
virtualModules = [],
37+
autogenModules = [],
38+
defaultLanguage = Nothing,
39+
otherLanguages = [],
40+
defaultExtensions = [],
41+
otherExtensions = [],
42+
oldExtensions = [
43+
EnableExtension
44+
ScopedTypeVariables],
45+
extraLibs = [],
46+
extraLibsStatic = [],
47+
extraGHCiLibs = [],
48+
extraBundledLibs = [],
49+
extraLibFlavours = [],
50+
extraDynLibFlavours = [],
51+
extraLibDirs = [],
52+
extraLibDirsStatic = [],
53+
includeDirs = [],
54+
includes = [],
55+
autogenIncludes = [],
56+
installIncludes = [],
57+
options = PerCompilerFlavor
58+
[]
59+
[],
60+
profOptions = PerCompilerFlavor
61+
[]
62+
[],
63+
sharedOptions =
64+
PerCompilerFlavor [] [],
65+
profSharedOptions =
66+
PerCompilerFlavor [] [],
67+
staticOptions =
68+
PerCompilerFlavor [] [],
69+
customFieldsBI = [],
70+
targetBuildDepends = [
71+
Dependency
72+
(PackageName "base")
73+
(IntersectVersionRanges
74+
(OrLaterVersion
75+
(mkVersion [4, 0]))
76+
(EarlierVersion
77+
(mkVersion [4, 7])))
78+
mainLibSet,
79+
Dependency
80+
(PackageName "AC-Vector")
81+
(OrLaterVersion
82+
(mkVersion [2, 3, 0]))
83+
mainLibSet,
84+
Dependency
85+
(PackageName "QuickCheck")
86+
(OrLaterVersion
87+
(mkVersion [2, 4, 0]))
88+
mainLibSet],
89+
mixins = []}},
90+
condTreeConstraints = [
91+
Dependency
92+
(PackageName "base")
93+
(IntersectVersionRanges
94+
(OrLaterVersion
95+
(mkVersion [4, 0]))
96+
(EarlierVersion
97+
(mkVersion [4, 7])))
98+
mainLibSet,
99+
Dependency
100+
(PackageName "AC-Vector")
101+
(OrLaterVersion
102+
(mkVersion [2, 3, 0]))
103+
mainLibSet,
104+
Dependency
105+
(PackageName "QuickCheck")
106+
(OrLaterVersion
107+
(mkVersion [2, 4, 0]))
108+
mainLibSet],
109+
condTreeComponents = []}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

0 commit comments

Comments
 (0)