Turn all tests into benchmarks

This commit is contained in:
Michael Walker 2018-06-24 10:48:38 +01:00
parent ccb4b9aa24
commit 38ee90cee8
3 changed files with 44 additions and 0 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

@ -76,3 +76,14 @@ executable dejafu-tests
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)