mirror of
https://github.com/barrucadu/dejafu.git
synced 2024-11-23 14:14:36 +03:00
Merge pull request #273 from barrucadu/99-benchmarks
Turn all the tests into benchmarks
This commit is contained in:
commit
8d6735b7c8
8
.weeder.yaml
Normal file
8
.weeder.yaml
Normal 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
|
@ -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
|
||||
|
25
dejafu-tests/exe/MainBench.hs
Normal file
25
dejafu-tests/exe/MainBench.hs
Normal 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
8
dejafu-tests/exe/MainTest.hs
Executable 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
10
dejafu-tests/exe/Main.hs → dejafu-tests/exe/Util.hs
Executable file → Normal 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"
|
Loading…
Reference in New Issue
Block a user