From 05ad021c9923636d9682c1616f6ef3533067ab1c Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Sat, 7 Sep 2019 14:13:04 +0200 Subject: [PATCH] tests and benchmarks cleanup --- lish.cabal | 51 ++++++++++++++++++------------------ package.yaml | 1 + src-benchmark/Main.hs | 9 +++++-- src-test/Lish/Test/Parser.hs | 16 ++++++----- src-test/Main.hs | 5 ++-- src/Lib.hs | 24 ----------------- 6 files changed, 46 insertions(+), 60 deletions(-) delete mode 100644 src/Lib.hs diff --git a/lish.cabal b/lish.cabal index f0deaff..cea50b9 100644 --- a/lish.cabal +++ b/lish.cabal @@ -4,7 +4,7 @@ cabal-version: 1.12 -- -- see: https://github.com/sol/hpack -- --- hash: 3a261bc10b55766ddf87ee6ac6a456e51b1f7b79b7b6514d18b7dc4f51c4b8eb +-- hash: b92e83b0e38dda1f7f335624325151ef2a4f95fbe2676a6e77d7bbea14b7e930 name: lish version: 0.1.0.0 @@ -43,7 +43,6 @@ library , text exposed-modules: Data.Stack - Lib Lish.Balanced Lish.Core Lish.Eval @@ -76,30 +75,6 @@ executable lish , text default-language: Haskell2010 -test-suite lish-benchmark - type: exitcode-stdio-1.0 - main-is: Main.hs - other-modules: - Paths_lish - hs-source-dirs: - src-benchmark - ghc-options: -Wall -O2 -threaded -rtsopts -with-rtsopts=-N - build-depends: - base >=4.8 && <5 - , containers - , criterion >=1.1 - , data-fix - , haskeline - , lish - , parsec >=3 && <4 - , pipes - , pretty - , pretty-show - , process - , protolude - , text - default-language: Haskell2010 - test-suite lish-doctest type: exitcode-stdio-1.0 main-is: Main.hs @@ -152,3 +127,27 @@ test-suite lish-test Lish.Test.Parser Paths_lish default-language: Haskell2010 + +benchmark lish-benchmark + type: exitcode-stdio-1.0 + main-is: Main.hs + other-modules: + Paths_lish + hs-source-dirs: + src-benchmark + ghc-options: -Wall -O2 -threaded -rtsopts -with-rtsopts=-N + build-depends: + base >=4.8 && <5 + , containers + , criterion >=1.1 + , data-fix + , haskeline + , lish + , parsec >=3 && <4 + , pipes + , pretty + , pretty-show + , process + , protolude + , text + default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index 4653c3e..e48583d 100644 --- a/package.yaml +++ b/package.yaml @@ -59,6 +59,7 @@ tests: - doctest >=0.10 - Glob >= 0.7 - QuickCheck >= 2.5 +benchmarks: lish-benchmark: source-dirs: src-benchmark main: Main.hs diff --git a/src-benchmark/Main.hs b/src-benchmark/Main.hs index e69835d..6cc61ff 100644 --- a/src-benchmark/Main.hs +++ b/src-benchmark/Main.hs @@ -1,7 +1,12 @@ +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE OverloadedStrings #-} +import Protolude + import Criterion import Criterion.Main -import Lib (inc) +import Lish.Parser (parseCmd) main :: IO () -main = defaultMain [bench "inc 41" (whnf inc (41 :: Int))] +main = defaultMain [bench "parseCmd (foo \"bar\")" + (whnf parseCmd ("(foo \"bar\")" :: Text))] diff --git a/src-test/Lish/Test/Parser.hs b/src-test/Lish/Test/Parser.hs index eee14af..19686d0 100644 --- a/src-test/Lish/Test/Parser.hs +++ b/src-test/Lish/Test/Parser.hs @@ -14,13 +14,17 @@ import Test.Tasty.SmallCheck import Lish.Parser import Lish.Types -parseTests :: [TestTree] +parseTests :: TestTree parseTests = - [ testCase "simple commands" (simpleCommand "ls") - , testCase "simple commands" (simpleCommand "atom") - , testCase "simple commands" (simpleCommand "_foo") - , testCase "multiline command" - (parseCmd "(fn [x] ; comment \n (+ x 1))" @?= Right incExpr) + testGroup "simple commands" + [ testCase "ls" (simpleCommand "ls") + , testCase "atom" (simpleCommand "atom") + , testCase "_foo" (simpleCommand "_foo") + , testCase "multiline" + (parseCmd "(fn [x]\n (+ x 1))" @?= Right incExpr) + -- TODO: or not? support line comment + -- , testCase "multiline command with comment" + -- (parseCmd "(fn [x] ; comment \n (+ x 1))" @?= Right incExpr) , testProperty "simple" propAtom ] diff --git a/src-test/Main.hs b/src-test/Main.hs index 8bcef14..43392fa 100644 --- a/src-test/Main.hs +++ b/src-test/Main.hs @@ -2,17 +2,18 @@ import Test.Tasty import Test.Tasty.HUnit import Test.Tasty.SmallCheck -import Lib (inc) import Lish.Test.Parser main :: IO () main = defaultMain $ testGroup "all-tests" tests +inc = (+1) + tests :: [TestTree] tests = [ testGroup "SmallCheck" scTests , testGroup "Unit tests" huTests - , testGroup "Lish.Parser" parseTests + , parseTests ] scTests :: [TestTree] diff --git a/src/Lib.hs b/src/Lib.hs deleted file mode 100644 index 91fdc67..0000000 --- a/src/Lib.hs +++ /dev/null @@ -1,24 +0,0 @@ --- | Example of a library file. It is also used for testing the test suites. -module Lib - ( - -- * Exported functions - inc - ) where - --- | Increment one 'Num' value. --- --- >>> let answer = 42 :: Int --- >>> let prev = answer - 1 --- >>> inc prev --- 42 --- >>> succ . Prelude.last . Prelude.take prev . iterate inc $ 1 --- 42 --- --- Properties: --- --- prop> succ x == inc x --- prop> inc (negate x) == negate (pred x) --- -inc :: Num a => a -- ^ value to increment - -> a -- ^ result -inc x = x + 1