]> git.wincent.com - docvim.git/commitdiff
Make unit tests a little more real
authorGreg Hurrell <greg@hurrell.net>
Tue, 22 Mar 2016 15:58:06 +0000 (08:58 -0700)
committerGreg Hurrell <greg@hurrell.net>
Tue, 22 Mar 2016 15:58:06 +0000 (08:58 -0700)
Before going much further though I want to set up tasty-golden, so I can
take an input file, parse it, and compare the pretty-printed output.

Will need pretty printing before I do that though...

README.md
docvim.cabal
lib/Docvim/Parse.hs
tests/tasty.hs

index 5a0a3a95a4570d713d5dd2d84ed4299e06fcf7c0..1f81f176194b18a2f6c6edf4b0f58afcb2032545 100644 (file)
--- a/README.md
+++ b/README.md
@@ -28,6 +28,12 @@ cabal haddock --executables
 open dist/doc/html/docvim/docvim/index.html
 ```
 
+### Testing
+
+```
+cabal test
+```
+
 ### Linting
 
 ```
index 2869a0348c944c1f09db20cdc86496bfff4b0950..51544319fb4c511eefdd91fc38874aaf126eb797 100644 (file)
@@ -96,10 +96,13 @@ test-suite hlint
 
 test-suite tasty
   build-depends:    base >= 4 && < 5
+               ,    docvim
+               ,    filepath
+               ,    parsec
                ,    tasty
                ,    tasty-hunit
-             --,    docvim
   default-language: Haskell2010
   hs-source-dirs:   tests
+                ,   lib
   main-is:          Tasty.hs
   type:             exitcode-stdio-1.0
index ae986610153009b0850404600c40df3cf25701de..c56606b3e174fa7c6c1708cc26bf34637cded481 100644 (file)
@@ -1,6 +1,9 @@
 {-# LANGUAGE FlexibleContexts #-}
 
-module Docvim.Parse (p, parse) where
+module Docvim.Parse ( p
+                    , parse
+                    , parseUnit
+                    ) where
 
 import Control.Applicative ( (*>)
                            , (<$)
@@ -271,3 +274,6 @@ parse fileName = parseFromFile unit fileName >>= either report return
 -- import Parse (p)
 -- p "test"
 p = parseTest unit
+
+-- | To facilitate unit-testing.
+parseUnit = runParser unit () "(eval)"
index caa4b85c114b067d6f517cc2e9a8513d86438cc4..820e56259ade2220cb0d0863cc11733767e716ae 100644 (file)
@@ -1,13 +1,26 @@
 module Main (main) where
 
+import Docvim.Parse (parseUnit)
 import Test.Tasty
 import Test.Tasty.HUnit
 
+-- | Crude check to see if parse worked.
+parseSuccess :: Either a b -> Bool
+parseSuccess (Left _) = False
+parseSuccess _        = True
+
+parseFailure :: Either a b -> Bool
+parseFailure = not . parseSuccess
+
 suite :: TestTree
 suite = testGroup "Test suite"
   [ testGroup "Unit tests"
-    [ testCase "Equality" $ True @=? True
-    , testCase "Assertion" $ assert $ (length [1, 2, 3]) == 3
+    [ testCase "Parse empty unit" $ assert $ parseSuccess (parseUnit "")
+    , testCase "Bad input" $ assert $ parseFailure (parseUnit "bzzzzt")
+
+    -- Some example syntax:
+    -- , testCase "Equality" $ True @=? True
+    -- , testCase "Assertion" $ assert $ (length [1, 2, 3]) == 3
     ]
   ]