From e8c958d3ea0e80028b00f061a201536e6f052826 Mon Sep 17 00:00:00 2001 From: Pascal Hof Date: Sat, 19 Nov 2016 11:35:07 +0100 Subject: [PATCH] created cabal file offers building the test program (executable) --- source/src/BNFC/Backend/Haskell/CFtoCabal.hs | 45 ++++++++++++++------ testing/src/HaskellCabalTests.hs | 3 +- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/source/src/BNFC/Backend/Haskell/CFtoCabal.hs b/source/src/BNFC/Backend/Haskell/CFtoCabal.hs index bb5b901e..9b64894f 100644 --- a/source/src/BNFC/Backend/Haskell/CFtoCabal.hs +++ b/source/src/BNFC/Backend/Haskell/CFtoCabal.hs @@ -38,32 +38,49 @@ buildPackageDescription opt = emptyPackageDescription PackageIdentifier { pkgName = PackageName (lang opt) , pkgVersion = Version [0,1] []} - , library = - Just mempty - { exposedModules = exposedMods opt - , libExposed = True - , libBuildInfo = emptyBuildInfo - { buildable = True - , hsSourceDirs = ["."] - , targetBuildDepends = dependencies opt - } - } + , library = Just (createLibrary opt) + , executables = [createExecutable opt] , extraSrcFiles = [ happyFile opt, alexFile opt ] , buildType = Just Simple , license = AllRightsReserved + , specVersionRaw = Right (orLaterVersion $ Version [1,22] []) } dependencies :: SharedOptions -> [Dependency] dependencies opt = - [ Dependency (PackageName "base") (laterVersion $ Version [4] []) + [ Dependency (PackageName "base") (orLaterVersion $ Version [4] []) , Dependency (PackageName "array") anyVersion ] ++ [ Dependency (PackageName "mtl") anyVersion | TargetHaskellGadt == target opt ] +createLibrary :: SharedOptions -> Library +createLibrary opt = mempty + { exposedModules = exposedLibMods opt + , libExposed = True + , libBuildInfo = emptyBuildInfo + { buildable = True + , hsSourceDirs = ["."] + , targetBuildDepends = dependencies opt + } + } + +createExecutable :: SharedOptions -> Executable +createExecutable opt = Executable name mainIs buildInfo where + name :: String + name = "Test" ++ lang opt + + mainIs :: FilePath + mainIs = tFile opt + + buildInfo :: BuildInfo + buildInfo = mempty + { targetBuildDepends = dependencies opt + , otherModules = exposedLibMods opt + } --- |returns a list of all exposed modules -exposedMods :: SharedOptions -> [ModuleName] -exposedMods opt = map fromString $ +-- |returns a list of all modules the library exposes +exposedLibMods :: SharedOptions -> [ModuleName] +exposedLibMods opt = map fromString $ [absFileM opt ,errFileM opt ,printerFileM opt diff --git a/testing/src/HaskellCabalTests.hs b/testing/src/HaskellCabalTests.hs index 6dd06cc4..d4da7fa6 100644 --- a/testing/src/HaskellCabalTests.hs +++ b/testing/src/HaskellCabalTests.hs @@ -30,12 +30,13 @@ mkTest target desc bnfcParams = makeShellyTest description $ withTmpDir $ \tmp -> do cd tmp writefile "Test.cf" $ unlines - [ "Start. S ::= S \"a\" ;" + [ "Start. S ::= S \"parseMe\" ;" , "End. S ::= ;" ] run_ "bnfc" args assertFileExists "Test.cabal" cmd "cabal" "configure" cmd "cabal" "build" + cmd "echo" "parseMe" -|- cmd "cabal" "run" where args :: [Text] args = target:"--cabal":bnfcParams ++ ["Test.cf"]