Commit 34989bc2 authored by Oleg Grenrus's avatar Oleg Grenrus
Browse files

Use tree-diff in parser-(hackage-)tests

parent 2b201476
......@@ -43,31 +43,44 @@ extra-source-files:
tests/ParserTests/errors/range-ge-wild.cabal
tests/ParserTests/errors/range-ge-wild.errors
tests/ParserTests/ipi/transformers.cabal
tests/ParserTests/ipi/transformers.expr
tests/ParserTests/ipi/transformers.format
tests/ParserTests/regressions/Octree-0.5.cabal
tests/ParserTests/regressions/Octree-0.5.expr
tests/ParserTests/regressions/Octree-0.5.format
tests/ParserTests/regressions/common.cabal
tests/ParserTests/regressions/common.expr
tests/ParserTests/regressions/common.format
tests/ParserTests/regressions/common2.cabal
tests/ParserTests/regressions/common2.expr
tests/ParserTests/regressions/common2.format
tests/ParserTests/regressions/elif.cabal
tests/ParserTests/regressions/elif.expr
tests/ParserTests/regressions/elif.format
tests/ParserTests/regressions/elif2.cabal
tests/ParserTests/regressions/elif2.expr
tests/ParserTests/regressions/elif2.format
tests/ParserTests/regressions/encoding-0.8.cabal
tests/ParserTests/regressions/encoding-0.8.expr
tests/ParserTests/regressions/encoding-0.8.format
tests/ParserTests/regressions/generics-sop.cabal
tests/ParserTests/regressions/generics-sop.expr
tests/ParserTests/regressions/generics-sop.format
tests/ParserTests/regressions/haddock-api-2.18.1-check.cabal
tests/ParserTests/regressions/issue-774.cabal
tests/ParserTests/regressions/issue-774.expr
tests/ParserTests/regressions/issue-774.format
tests/ParserTests/regressions/leading-comma.cabal
tests/ParserTests/regressions/leading-comma.expr
tests/ParserTests/regressions/leading-comma.format
tests/ParserTests/regressions/nothing-unicode.cabal
tests/ParserTests/regressions/nothing-unicode.expr
tests/ParserTests/regressions/nothing-unicode.format
tests/ParserTests/regressions/shake.cabal
tests/ParserTests/regressions/shake.expr
tests/ParserTests/regressions/shake.format
tests/ParserTests/regressions/wl-pprint-indef.cabal
tests/ParserTests/regressions/wl-pprint-indef.expr
tests/ParserTests/regressions/wl-pprint-indef.format
tests/ParserTests/warnings/bom.cabal
tests/ParserTests/warnings/bool.cabal
......@@ -102,11 +115,6 @@ flag old-directory
description: Use directory < 1.2 and old-time
default: False
flag parsec-struct-diff
description: Use StructDiff in parsec tests. Affects only parsec tests.
default: False
manual: True
library
build-depends:
array >= 0.1 && < 0.6,
......@@ -454,9 +462,9 @@ test-suite parser-tests
type: exitcode-stdio-1.0
hs-source-dirs: tests
main-is: ParserTests.hs
build-depends: containers
build-depends:
base,
base-compat >=0.9.3 && <0.10,
bytestring,
filepath,
tasty,
......@@ -468,6 +476,12 @@ test-suite parser-tests
ghc-options: -Wall
default-language: Haskell2010
if impl(ghc >= 7.8)
build-depends:
tree-diff >= 0.0.1 && <0.1
other-modules:
TreeDiffInstances
test-suite check-tests
type: exitcode-stdio-1.0
hs-source-dirs: tests
......@@ -518,16 +532,11 @@ test-suite parser-hackage-tests
filepath,
Cabal
if flag(parsec-struct-diff)
if impl(ghc >= 7.8)
build-depends:
generics-sop >= 0.3.1.0 && <0.4,
these >=0.7.1 && <0.8,
singleton-bool >=0.1.1.0 && <0.2,
keys
tree-diff >= 0.0.1 && <0.1
other-modules:
DiffInstances
StructDiff
cpp-options: -DHAS_STRUCT_DIFF
TreeDiffInstances
ghc-options: -Wall -rtsopts
default-extensions: CPP
......
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -freduction-depth=0 -fno-warn-orphans #-}
module DiffInstances where
import Generics.SOP.TH
import StructDiff
-------------------------------------------------------------------------------
import Distribution.Compiler (CompilerFlavor)
import Distribution.License (License)
import Distribution.ModuleName (ModuleName)
import Distribution.Package
(Dependency, PackageIdentifier, PackageName)
import Distribution.Types.ForeignLib
import Distribution.Types.ForeignLibOption
import Distribution.Types.ForeignLibType
import Distribution.Types.IncludeRenaming (IncludeRenaming)
import Distribution.PackageDescription
import Distribution.Types.CondTree
import Distribution.Types.ExeDependency
import Distribution.Types.ExecutableScope
import Distribution.Types.LegacyExeDependency
import Distribution.Types.Mixin
import Distribution.Types.PkgconfigDependency
import Distribution.Types.UnqualComponentName
import Distribution.Version (Version, VersionRange)
import Language.Haskell.Extension
(Extension, KnownExtension, Language)
-------------------------------------------------------------------------------
-- instances
-------------------------------------------------------------------------------
deriveGeneric ''Benchmark
deriveGeneric ''BenchmarkInterface
deriveGeneric ''BenchmarkType
deriveGeneric ''BuildInfo
deriveGeneric ''BuildType
deriveGeneric ''CompilerFlavor
deriveGeneric ''CondBranch
deriveGeneric ''CondTree
deriveGeneric ''Dependency
deriveGeneric ''Executable
deriveGeneric ''Extension
deriveGeneric ''Flag
deriveGeneric ''ForeignLib
deriveGeneric ''ForeignLibOption
deriveGeneric ''ForeignLibType
deriveGeneric ''GenericPackageDescription
deriveGeneric ''IncludeRenaming
deriveGeneric ''KnownExtension
deriveGeneric ''Language
deriveGeneric ''Library
deriveGeneric ''License
deriveGeneric ''ModuleReexport
deriveGeneric ''ModuleRenaming
deriveGeneric ''PackageDescription
deriveGeneric ''PackageIdentifier
deriveGeneric ''PackageName
deriveGeneric ''RepoKind
deriveGeneric ''RepoType
deriveGeneric ''SetupBuildInfo
deriveGeneric ''SourceRepo
deriveGeneric ''TestSuite
deriveGeneric ''TestSuiteInterface
deriveGeneric ''TestType
deriveGeneric ''VersionRange
instance (Eq a, Show a) => Diff (Condition a) where diff = eqDiff
instance (Show a, Diff b, Diff c, Show b, Show c, Eq a, Eq c, Eq b) => Diff (CondTree a b c)
instance (Show a, Diff b, Diff c, Show b, Show c, Eq a, Eq c, Eq b) => Diff (CondBranch a b c)
instance Diff Benchmark
instance Diff BenchmarkInterface
instance Diff BenchmarkType
instance Diff BuildInfo
instance Diff BuildType
instance Diff CompilerFlavor
instance Diff Dependency
instance Diff ExeDependency where diff = eqDiff
instance Diff Executable
instance Diff ExecutableScope where diff = eqDiff
instance Diff Extension
instance Diff Flag
instance Diff FlagName where diff = eqDiff
instance Diff ForeignLib
instance Diff ForeignLibOption
instance Diff ForeignLibType
instance Diff GenericPackageDescription
instance Diff IncludeRenaming
instance Diff KnownExtension
instance Diff Language
instance Diff LegacyExeDependency where diff = eqDiff
instance Diff LibVersionInfo where diff = eqDiff
instance Diff Library
instance Diff License
instance Diff Mixin where diff = eqDiff
instance Diff ModuleName where diff = eqDiff
instance Diff ModuleReexport
instance Diff ModuleRenaming
instance Diff PackageDescription
instance Diff PackageIdentifier
instance Diff PackageName where diff = eqDiff
instance Diff PkgconfigDependency where diff = eqDiff
instance Diff RepoKind
instance Diff RepoType
instance Diff SetupBuildInfo
instance Diff SourceRepo
instance Diff TestSuite
instance Diff TestSuiteInterface
instance Diff TestType
instance Diff UnqualComponentName where diff = eqDiff
instance Diff Version where diff = eqDiff
instance Diff VersionRange
......@@ -41,9 +41,9 @@ import qualified Distribution.Types.Library.Lens as L
import qualified Distribution.Types.PackageDescription.Lens as L
import qualified Distribution.Types.SourceRepo.Lens as L
#ifdef HAS_STRUCT_DIFF
import DiffInstances ()
import StructDiff
#ifdef MIN_VERSION_tree_diff
import Data.TreeDiff (ansiWlEditExpr, ediff)
import TreeDiffInstances ()
#endif
parseIndex :: Monoid a => (FilePath -> BSL.ByteString -> IO a) -> IO a
......@@ -144,8 +144,8 @@ compareTest pfx fpath bsl
-- Compare two parse results
-- ixset-1.0.4 has invalid prof-options, it's the only exception!
unless (readp0 == parsec1 || fpath == "ixset/1.0.4/ixset.cabal") $ do
#if HAS_STRUCT_DIFF
prettyResultIO $ diff readp parsec
#ifdef MIN_VERSION_tree_diff
print $ ansiWlEditExpr $ ediff readp parsec
#else
putStrLn "<<<<<<"
print readp
......@@ -210,15 +210,14 @@ roundtripTest _ fpath bsl = do
unless (x == y || fpath == "ixset/1.0.4/ixset.cabal") $ do
putStrLn fpath
#if HAS_STRUCT_DIFF
prettyResultIO $ diff x y
#ifdef MIN_VERSION_tree_diff
print $ ansiWlEditExpr $ ediff x y
#else
putStrLn "<<<<<<"
print x
putStrLn "======"
print y
putStrLn ">>>>>>"
#endif
putStrLn bs'
exitFailure
......@@ -234,6 +233,7 @@ roundtripTest _ fpath bsl = do
traverse_ print errs
B.putStr c
fail "parse error"
main :: IO ()
main = do
args <- getArgs
......
{-# LANGUAGE CPP #-}
module Main
( main
) where
import Prelude ()
import Prelude.Compat
import Test.Tasty
import Test.Tasty.Golden.Advanced (goldenTest)
import Test.Tasty.HUnit
......@@ -28,6 +32,12 @@ import qualified Distribution.Types.PackageDescription.Lens as L
import qualified Distribution.InstalledPackageInfo as IPI
import qualified Distribution.ParseUtils as ReadP
#ifdef MIN_VERSION_tree_diff
import Data.TreeDiff (toExpr)
import Data.TreeDiff.Golden (ediffGolden)
import TreeDiffInstances ()
#endif
tests :: TestTree
tests = testGroup "parsec tests"
[ regressionTests
......@@ -128,6 +138,9 @@ regressionTest :: FilePath -> TestTree
regressionTest fp = testGroup fp
[ formatGoldenTest fp
, formatRoundTripTest fp
#ifdef MIN_VERSION_tree_diff
, treeDiffGoldenTest fp
#endif
]
formatGoldenTest :: FilePath -> TestTree
......@@ -146,6 +159,20 @@ formatGoldenTest fp = cabalGoldenTest "format" correct $ do
input = "tests" </> "ParserTests" </> "regressions" </> fp
correct = replaceExtension input "format"
#ifdef MIN_VERSION_tree_diff
treeDiffGoldenTest :: FilePath -> TestTree
treeDiffGoldenTest fp = ediffGolden goldenTest "expr" exprFile $ do
contents <- BS.readFile input
let res = parseGenericPackageDescription contents
let (_, errs, x) = runParseResult res
case x of
Just gpd | null errs -> pure (toExpr gpd)
_ -> fail $ unlines $ "ERROR" : map show errs
where
input = "tests" </> "ParserTests" </> "regressions" </> fp
exprFile = replaceExtension input "expr"
#endif
formatRoundTripTest :: FilePath -> TestTree
formatRoundTripTest fp = testCase "roundtrip" $ do
contents <- BS.readFile input
......@@ -183,6 +210,9 @@ ipiTest :: FilePath -> TestTree
ipiTest fp = testGroup fp
[ ipiFormatGoldenTest fp
, ipiFormatRoundTripTest fp
#ifdef MIN_VERSION_tree_diff
, ipiTreeDiffGoldenTest fp
#endif
]
ipiFormatGoldenTest :: FilePath -> TestTree
......@@ -198,6 +228,19 @@ ipiFormatGoldenTest fp = cabalGoldenTest "format" correct $ do
input = "tests" </> "ParserTests" </> "ipi" </> fp
correct = replaceExtension input "format"
#ifdef MIN_VERSION_tree_diff
ipiTreeDiffGoldenTest :: FilePath -> TestTree
ipiTreeDiffGoldenTest fp = ediffGolden goldenTest "expr" exprFile $ do
contents <- readFile input
let res = IPI.parseInstalledPackageInfo contents
case res of
ReadP.ParseFailed err -> fail $ "ERROR " ++ show err
ReadP.ParseOk _ws ipi -> pure (toExpr ipi)
where
input = "tests" </> "ParserTests" </> "ipi" </> fp
exprFile = replaceExtension input "expr"
#endif
ipiFormatRoundTripTest :: FilePath -> TestTree
ipiFormatRoundTripTest fp = testCase "roundtrip" $ do
contents <- readFile input
......
InstalledPackageInfo
{abiDepends = [`AbiDependency {depUnitId = UnitId "base-4.10.1.0", depAbiHash = AbiHash "35a7f6be752ee4f7385cb5bf28677879"}`],
abiHash = `AbiHash "e04579c0363c9229351d1a0b394bf2d5"`,
author = "Andy Gill, Ross Paterson",
category = "Control",
ccOptions = [],
compatPackageKey = "transformers-0.5.2.0",
copyright = "",
dataDir = "/opt/ghc/8.2.2/share/x86_64-linux-ghc-8.2.2/transformers-0.5.2.0",
depends = [`UnitId "base-4.10.1.0"`],
description = concat
["A portable library of functor and monad transformers, inspired by\n",
"the paper \\\"Functional Programming with Overloading and Higher-Order\n",
"Polymorphism\\\", by Mark P Jones,\n",
"in /Advanced School of Functional Programming/, 1995\n",
"(<http://web.cecs.pdx.edu/~mpj/pubs/springschool.html>).\n",
"\n",
"This package contains:\n",
"\n",
"* the monad transformer class (in \"Control.Monad.Trans.Class\")\n",
"and IO monad class (in \"Control.Monad.IO.Class\")\n",
"\n",
"* concrete functor and monad transformers, each with associated\n",
"operations and functions to lift operations associated with other\n",
"transformers.\n",
"\n",
"The package can be used on its own in portable Haskell code, in\n",
"which case operations need to be manually lifted through transformer\n",
"stacks (see \"Control.Monad.Trans.Class\" for some examples).\n",
"Alternatively, it can be used with the non-portable monad classes in\n",
"the @mtl@ or @monads-tf@ packages, which automatically lift operations\n",
"introduced by monad transformers through other transformers."],
exposed = True,
exposedModules = [`ExposedModule {exposedName = ModuleName ["Control","Applicative","Backwards"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Applicative","Lift"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Signatures"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","Class"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","Cont"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","Error"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","Except"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","Identity"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","List"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","Maybe"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","RWS"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","RWS","Lazy"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","RWS","Strict"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","Reader"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","State"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","State","Lazy"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","State","Strict"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","Writer"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","Writer","Lazy"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Control","Monad","Trans","Writer","Strict"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Data","Functor","Constant"], exposedReexport = Nothing}`,
`ExposedModule {exposedName = ModuleName ["Data","Functor","Reverse"], exposedReexport = Nothing}`],
extraGHCiLibraries = [],
extraLibraries = [],
frameworkDirs = [],
frameworks = [],
haddockHTMLs = ["/opt/ghc/8.2.2/share/doc/ghc-8.2.2/html/libraries/transformers-0.5.2.0"],
haddockInterfaces = ["/opt/ghc/8.2.2/share/doc/ghc-8.2.2/html/libraries/transformers-0.5.2.0/transformers.haddock"],
hiddenModules = [],
homepage = "",
hsLibraries = ["HStransformers-0.5.2.0"],
importDirs = ["/opt/ghc/8.2.2/lib/ghc-8.2.2/transformers-0.5.2.0"],
includeDirs = [],
includes = [],
indefinite = False,
installedComponentId_ = `ComponentId ""`,
installedUnitId = `UnitId "transformers-0.5.2.0"`,
instantiatedWith = [],
ldOptions = [],
libraryDirs = ["/opt/ghc/8.2.2/lib/ghc-8.2.2/transformers-0.5.2.0"],
libraryDynDirs = ["/opt/ghc/8.2.2/lib/ghc-8.2.2/transformers-0.5.2.0"],
license = BSD3,
maintainer = "Ross Paterson <R.Paterson@city.ac.uk>",
pkgRoot = Just "/opt/ghc/8.2.2/lib/ghc-8.2.2",
pkgUrl = "",
sourceLibName = Nothing,
sourcePackageId = PackageIdentifier
{pkgName = `PackageName "transformers"`,
pkgVersion = `mkVersion [0,5,2,0]`},
stability = "",
synopsis = "Concrete functor and monad transformers",
trusted = False}
This diff is collapsed.
GenericPackageDescription
{condBenchmarks = [],
condExecutables = [],
condForeignLibs = [],
condLibrary = Just
CondNode
{condTreeComponents = [],
condTreeConstraints = [Dependency
`PackageName "ghc-prim"` AnyVersion],
condTreeData = Library
{exposedModules = [`ModuleName ["ElseIf"]`],
libBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
buildable = True,
cSources = [],
ccOptions = [],
cmmOptions = [],
cmmSources = [],
cppOptions = [],
customFieldsBI = [],
cxxOptions = [],
cxxSources = [],
defaultExtensions = [],
defaultLanguage = Just Haskell2010,
extraBundledLibs = [],
extraFrameworkDirs = [],
extraGHCiLibs = [],
extraLibDirs = [],
extraLibFlavours = [],
extraLibs = [],
frameworks = [],
hsSourceDirs = [],
includeDirs = [],
includes = [],
installIncludes = [],
jsSources = [],
ldOptions = [],
mixins = [],
oldExtensions = [],
options = [],
otherExtensions = [],
otherLanguages = [],
otherModules = [],
pkgconfigDepends = [],
profOptions = [],
sharedOptions = [],
staticOptions = [],
targetBuildDepends = [Dependency
`PackageName "ghc-prim"`
AnyVersion],
virtualModules = []},
libExposed = True,
libName = Nothing,
reexportedModules = [],
signatures = []}},
condSubLibraries = [],
condTestSuites = [_×_
`UnqualComponentName "tests"`
CondNode
{condTreeComponents = [],
condTreeConstraints = [Dependency
`PackageName "HUnit"` AnyVersion],
condTreeData = TestSuite
{testBuildInfo = BuildInfo
{asmOptions = [],
asmSources = [],
autogenModules = [],
buildToolDepends = [],
buildTools = [],
buildable = True,
cSources = [],
ccOptions = [],
cmmOptions = [],
cmmSources = [],
cppOptions = [],
customFieldsBI = [],
cxxOptions = [],
cxxSources = [],
defaultExtensions = [],
defaultLanguage = Nothing,
extraBundledLibs = [],
extraFrameworkDirs = [],
extraGHCiLibs = [],
extraLibDirs = [],
extraLibFlavours = [],
extraLibs = [],
frameworks = [],
hsSourceDirs = [],
includeDirs = [],
includes = [],
installIncludes = [],
jsSources = [],
ldOptions = [],
mixins = [],
oldExtensions = [],
options = [],
otherExtensions = [],
otherLanguages = [],
otherModules = [],
pkgconfigDepends = [],
profOptions = [],
sharedOptions = [],
staticOptions = [],
targetBuildDepends = [Dependency
`PackageName "HUnit"`
AnyVersion],
virtualModules = []},
testInterface = TestSuiteExeV10
`mkVersion [1,0]` "Tests.hs",
testName = `UnqualComponentName ""`}}],
genPackageFlags = [],
packageDescription = PackageDescription
{author = "",
benchmarks = [],
bugReports = "",
buildDepends = [],
buildTypeRaw = Just Simple,
category = "",
copyright = "",
customFieldsPD = [],
dataDir = "",
dataFiles = [],
description = "",
executables = [],
extraDocFiles = [],
extraSrcFiles = [],
extraTmpFiles = [],
foreignLibs = [],
homepage = "",
library = Nothing,
license = UnspecifiedLicense,
licenseFiles = [],
maintainer = "",
package = PackageIdentifier
{pkgName = `PackageName "common"`,
pkgVersion = `mkVersion [0]`},
pkgUrl = "",
setupBuildInfo = Nothing,
sourceRepos = [SourceRepo
{repoBranch = Nothing,
repoKind = RepoHead,
repoLocation = Just "https://github.com/hvr/-.git",
repoModule = Nothing,
repoSubdir = Nothing,
repoTag = Nothing,
repoType = Just Git}],
specVersionRaw = Right (OrLaterVersion `mkVersion [1,10]`),
stability = "",
subLibraries = [],
synopsis = "Common-stanza demo demo",
testSuites = [],
testedWith = []}}
This diff is collapsed.
GenericPackageDescription
{condBenchmarks = [],
condExecutables = [],
condForeignLibs = [],
condLibrary = Just
CondNode
{condTreeComponents = [CondBranch
{condBranchCondition = `Var (OS Linux)`,
condBranchIfFalse = Nothing,
condBranchIfTrue = CondNode
{condTreeComponents = [],
condTreeConstraints = [Dependency
`PackageName "unix"`
AnyVersion],
condTreeData = Library
{exposedModules = [],