Skip to content

Commit

Permalink
Modify test files
Browse files Browse the repository at this point in the history
  • Loading branch information
fendor committed Jun 18, 2019
1 parent 53aa595 commit 928e92f
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
84 changes: 84 additions & 0 deletions cabal-testsuite/PackageTests/ShowBuildInfo/Complex/bench.test.hs
Original file line number Diff line number Diff line change
@@ -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 '-' }
74 changes: 37 additions & 37 deletions cabal-testsuite/PackageTests/ShowBuildInfo/Complex/exe.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 928e92f

Please sign in to comment.