Merge pull request #273 from barrucadu/99-benchmarks

Turn all the tests into benchmarks
This commit is contained in:
Michael Walker 2018-06-24 12:16:39 +01:00 committed by GitHub
commit 8d6735b7c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 8 deletions

8
.weeder.yaml Normal file
View File

@ -0,0 +1,8 @@
- package:
- name: dejafu-tests
- section:
- name: exe:dejafu-bench exe:dejafu-tests
- message:
- name: Module reused between components
- module:
- Util

View File

@ -68,11 +68,22 @@ library
ghc-options: -Wall
executable dejafu-tests
main-is: Main.hs
main-is: MainTest.hs
other-modules: Util
build-depends: base
, dejafu-tests
, tasty
hs-source-dirs: exe
default-language: Haskell2010
ghc-options: -Wall -threaded -rtsopts
executable dejafu-bench
main-is: MainBench.hs
other-modules: Util
build-depends: base
, criterion
, dejafu-tests
, tasty
hs-source-dirs: exe
default-language: Haskell2010
ghc-options: -Wall -threaded -rtsopts

View File

@ -0,0 +1,25 @@
module Main where
import qualified Criterion.Main as C
import Data.Monoid (mempty)
import qualified Test.Tasty.Options as T
import qualified Test.Tasty.Providers as T
import qualified Test.Tasty.Runners as T
import Util
main :: IO ()
main = C.defaultMain (T.foldTestTree mkBench mempty tests)
-- | Turn a test tree into a list of benchmarks.
mkBench :: T.TreeFold [C.Benchmark]
mkBench = T.trivialFold
{ T.foldSingle = \opts lbl t -> [C.bench lbl (benchTest opts t)]
, T.foldGroup = \lbl bs -> [C.bgroup lbl bs]
}
-- | Turn a test into a benchmark.
benchTest :: T.IsTest t => T.OptionSet -> t -> C.Benchmarkable
benchTest opts t = C.nfIO $ do
res <- T.run opts t (\_ -> pure ())
pure (show (T.resultOutcome res), T.resultTime res)

8
dejafu-tests/exe/MainTest.hs Executable file
View File

@ -0,0 +1,8 @@
module Main where
import Test.Tasty (defaultMainWithIngredients)
import Util
main :: IO ()
main = defaultMainWithIngredients ingredients tests

10
dejafu-tests/exe/Main.hs → dejafu-tests/exe/Util.hs Executable file → Normal file
View File

@ -1,17 +1,15 @@
module Main where
module Util (ingredients, tests) where
import qualified Test.Tasty as T
import qualified Test.Tasty.Options as T
import qualified Test.Tasty.Runners as T
import qualified Examples as E
import qualified Integration as I
import qualified Unit as U
main :: IO ()
main =
let ingredients = T.includingOptions options : T.defaultIngredients
runner = T.defaultMainWithIngredients ingredients
in runner tests
ingredients :: [T.Ingredient]
ingredients = T.includingOptions options : T.defaultIngredients
tests :: T.TestTree
tests = T.testGroup "Tests"