-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
147 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
cabal-testsuite/PackageTests/ShowBuildInfo/Complex/bench.test.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 '-' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters