From 928e92f5e6fb2770c506099eb1776e64a3fc4f16 Mon Sep 17 00:00:00 2001 From: fendor Date: Tue, 18 Jun 2019 17:19:48 +0200 Subject: [PATCH] Modify test files --- .../ShowBuildInfo/Complex/Complex.cabal | 6 +- .../ShowBuildInfo/Complex/bench.test.hs | 84 +++++++++++++++++++ .../ShowBuildInfo/Complex/exe.test.hs | 74 ++++++++-------- .../ShowBuildInfo/Complex/func-test.test.hs | 4 +- .../ShowBuildInfo/Complex/unit-test.test.hs | 42 +++++----- 5 files changed, 147 insertions(+), 63 deletions(-) create mode 100644 cabal-testsuite/PackageTests/ShowBuildInfo/Complex/bench.test.hs diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal index 0f1d5ca0e81..93947142a95 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/Complex.cabal @@ -30,13 +30,13 @@ executable Complex test-suite unit-test type: exitcode-stdio-1.0 hs-source-dirs: test - build-depends: test-framework + build-depends: test-framework == 0.8.1.1 main-is: Main.hs test-suite func-test type: exitcode-stdio-1.0 hs-source-dirs: test - build-depends: test-framework + build-depends: test-framework == 0.8.1.1 main-is: Main.hs benchmark complex-benchmarks @@ -49,6 +49,6 @@ benchmark complex-benchmarks ghc-options: -Wall -rtsopts -threaded -with-rtsopts=-N build-depends: base - , criterion + , criterion == 1.1.4.0 , Complex default-language: Haskell2010 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/bench.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/bench.test.hs new file mode 100644 index 00000000000..e8c59683dfb --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/bench.test.hs @@ -0,0 +1,84 @@ +{-# LANGUAGE DeriveGeneric #-} +import Test.Cabal.Prelude + +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Data.Aeson +import GHC.Generics + +main = cabalTest $ withRepo "repo" $ do + r <- cabal' "new-show-build-info" ["--enable-benchmarks", "bench:complex-benchmarks", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly one" 1 (length buildInfos) + let [buildInfo] = buildInfos + assertEqual "Cabal Version" "3.0.0.0" (cabalVersion buildInfo) + assertEqual "Compiler flavour" "ghc" (flavour $ compiler buildInfo) + assertBool "Compiler id" (and $ zipWith (==) "ghc" (compilerId $ compiler buildInfo)) + assertBool "Compiler path non-empty" (not . null . path $ compiler buildInfo) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "benchmark" (componentType component) + assertEqual "Component name" "bench:complex-brenchmarks" (componentName component) + assertEqual "Component unit-id" "Complex-0.1.0.0-inplace-Complex" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertBool "Component ghc-options contains all specified in .cabal" + (all + (`elem` componentCompilerArgs component) + [ "-threaded" + , "-rtsopts" + , "-with-rtsopts=-N" + , "-with-rtsopts=-T" + , "-Wredundant-constraints" + ] + ) + assertBool "Component ghc-options does not contain -Wall" + (all + (`notElem` componentCompilerArgs component) + [ "-Wall" + ] + ) + assertEqual "Component modules" ["Paths_complex"] (componentModules component) + assertEqual "Component source files" ["Main.lhs"] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + return () + +data BuildInfo = BuildInfo + { cabalVersion :: String + , compiler :: CompilerInfo + , components :: [ComponentInfo] + } deriving (Generic, Show) + +data CompilerInfo = CompilerInfo + { flavour :: String + , compilerId :: String + , path :: String + } deriving (Generic, Show) + +data ComponentInfo = ComponentInfo + { componentType :: String + , componentName :: String + , componentUnitId :: String + , componentCompilerArgs :: [String] + , componentModules :: [String] + , componentSrcFiles :: [String] + , componentSrcDirs :: [String] + } deriving (Generic, Show) + +instance ToJSON BuildInfo where + toEncoding = genericToEncoding defaultOptions +instance FromJSON BuildInfo where + parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = camelTo2 '-' } + + +instance ToJSON CompilerInfo where + toEncoding = genericToEncoding defaultOptions +instance FromJSON CompilerInfo where + parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = camelTo2 '-' } + +instance ToJSON ComponentInfo where + toEncoding = genericToEncoding defaultOptions +instance FromJSON ComponentInfo where + parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = drop 10 . camelTo2 '-' } \ No newline at end of file diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs index 91c2cec1429..43250743de8 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs @@ -7,43 +7,43 @@ import Data.Aeson import GHC.Generics main = cabalTest $ do - r <- cabal' "new-show-build-info" ["exe:Complex", "-v0"] - let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] - case buildInfoEither of - Left err -> fail $ "Could not parse build-info command" ++ err - Right buildInfos -> do - assertEqual "Build Infos, exactly one" 1 (length buildInfos) - let [buildInfo] = buildInfos - assertEqual "Cabal Version" "3.0.0.0" (cabalVersion buildInfo) - assertEqual "Compiler flavour" "ghc" (flavour $ compiler buildInfo) - assertBool "Compiler id" (and $ zipWith (==) "ghc" (compilerId $ compiler buildInfo)) - assertBool "Compiler path non-empty" (not . null . path $ compiler buildInfo) - assertEqual "Components, exactly one" 1 (length $ components buildInfo) - let [component] = components buildInfo - assertEqual "Component type" "exe" (componentType component) - assertEqual "Component name" "exe:Complex" (componentName component) - assertEqual "Component unit-id" "Complex-0.1.0.0-inplace-Complex" (componentUnitId component) - assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) - assertBool "Component ghc-options contains all specified in .cabal" - (all - (`elem` componentCompilerArgs component) - [ "-threaded" - , "-rtsopts" - , "-with-rtsopts=-N" - , "-with-rtsopts=-T" - , "-Wredundant-constraints" - ] - ) - assertBool "Component ghc-options does not contain -Wall" - (all - (`notElem` componentCompilerArgs component) - [ "-Wall" - ] - ) - assertEqual "Component modules" ["Paths_complex"] (componentModules component) - assertEqual "Component source files" ["Main.lhs"] (componentSrcFiles component) - assertEqual "Component source directories" ["src"] (componentSrcDirs component) - return () + r <- cabal' "new-show-build-info" ["exe:Complex", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly one" 1 (length buildInfos) + let [buildInfo] = buildInfos + assertEqual "Cabal Version" "3.0.0.0" (cabalVersion buildInfo) + assertEqual "Compiler flavour" "ghc" (flavour $ compiler buildInfo) + assertBool "Compiler id" (and $ zipWith (==) "ghc" (compilerId $ compiler buildInfo)) + assertBool "Compiler path non-empty" (not . null . path $ compiler buildInfo) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "exe" (componentType component) + assertEqual "Component name" "exe:Complex" (componentName component) + assertEqual "Component unit-id" "Complex-0.1.0.0-inplace-Complex" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertBool "Component ghc-options contains all specified in .cabal" + (all + (`elem` componentCompilerArgs component) + [ "-threaded" + , "-rtsopts" + , "-with-rtsopts=-N" + , "-with-rtsopts=-T" + , "-Wredundant-constraints" + ] + ) + assertBool "Component ghc-options does not contain -Wall" + (all + (`notElem` componentCompilerArgs component) + [ "-Wall" + ] + ) + assertEqual "Component modules" ["Paths_complex"] (componentModules component) + assertEqual "Component source files" ["Main.lhs"] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + return () data BuildInfo = BuildInfo { cabalVersion :: String diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs index adbbabf1559..f12dd74c6c9 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/func-test.test.hs @@ -7,7 +7,7 @@ import Data.Aeson import GHC.Generics main = cabalTest $ withRepo "repo" $ do - r <- cabal' "new-show-build-info" ["--enable-tests", "lib:Complex", "-v0"] + r <- cabal' "new-show-build-info" ["--enable-tests", ":func-test", "-v0"] let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] case buildInfoEither of Left err -> fail $ "Could not parse build-info command" ++ err @@ -21,7 +21,7 @@ main = cabalTest $ withRepo "repo" $ do assertEqual "Components, exactly one" 1 (length $ components buildInfo) let [component] = components buildInfo assertEqual "Component type" "test" (componentType component) - assertEqual "Component name" "test:unit" (componentName component) + assertEqual "Component name" "test:func" (componentName component) assertEqual "Component unit-id" "Complex-0.1.0.0-inplace" (componentUnitId component) assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) assertEqual "Component modules" ["Lib", "Paths_complex"] (componentModules component) diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs index e2280b47ab8..4bbe2a81034 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/Complex/unit-test.test.hs @@ -7,27 +7,27 @@ import Data.Aeson import GHC.Generics main = cabalTest $ withRepo "repo" $ do - r <- cabal' "new-show-build-info" ["--enable-tests", "lib:Complex", "-v0"] - let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] - case buildInfoEither of - Left err -> fail $ "Could not parse build-info command" ++ err - Right buildInfos -> do - assertEqual "Build Infos, exactly one" 1 (length buildInfos) - let [buildInfo] = buildInfos - assertEqual "Cabal Version" "3.0.0.0" (cabalVersion buildInfo) - assertEqual "Compiler flavour" "ghc" (flavour $ compiler buildInfo) - assertBool "Compiler id" (and $ zipWith (==) "ghc" (compilerId $ compiler buildInfo)) - assertBool "Compiler path non-empty" (not . null . path $ compiler buildInfo) - assertEqual "Components, exactly one" 1 (length $ components buildInfo) - let [component] = components buildInfo - assertEqual "Component type" "test" (componentType component) - assertEqual "Component name" "test:unit" (componentName component) - assertEqual "Component unit-id" "Complex-0.1.0.0-inplace" (componentUnitId component) - assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) - assertEqual "Component modules" ["Lib", "Paths_complex"] (componentModules component) - assertEqual "Component source files" [] (componentSrcFiles component) - assertEqual "Component source directories" ["src"] (componentSrcDirs component) - return () + r <- cabal' "new-show-build-info" ["--enable-tests", ":unit-test", "-v0"] + let buildInfoEither = eitherDecodeStrict (T.encodeUtf8 . T.pack $ resultOutput r) :: Either String [BuildInfo] + case buildInfoEither of + Left err -> fail $ "Could not parse build-info command" ++ err + Right buildInfos -> do + assertEqual "Build Infos, exactly one" 1 (length buildInfos) + let [buildInfo] = buildInfos + assertEqual "Cabal Version" "3.0.0.0" (cabalVersion buildInfo) + assertEqual "Compiler flavour" "ghc" (flavour $ compiler buildInfo) + assertBool "Compiler id" (and $ zipWith (==) "ghc" (compilerId $ compiler buildInfo)) + assertBool "Compiler path non-empty" (not . null . path $ compiler buildInfo) + assertEqual "Components, exactly one" 1 (length $ components buildInfo) + let [component] = components buildInfo + assertEqual "Component type" "test" (componentType component) + assertEqual "Component name" "test:unit" (componentName component) + assertEqual "Component unit-id" "Complex-0.1.0.0-inplace" (componentUnitId component) + assertBool "Component compiler args are non-empty" (not . null $ componentCompilerArgs component) + assertEqual "Component modules" ["Lib", "Paths_complex"] (componentModules component) + assertEqual "Component source files" [] (componentSrcFiles component) + assertEqual "Component source directories" ["src"] (componentSrcDirs component) + return () data BuildInfo = BuildInfo { cabalVersion :: String