summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-01-04 21:05:31 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-01-04 21:05:31 -0400
commit759e860e4b6c514b74cafb2c0dd9c52c4d59316b (patch)
treeea09994423b910f2f1f91d46f9e84085f7088c8f
parentf1b747e6d9fae2b365f65fd43c6295da503218bd (diff)
add testcoverage target using hpc
added a test for key read and show
-rw-r--r--.gitignore2
-rw-r--r--Makefile9
-rw-r--r--TypeInternals.hs18
-rw-r--r--test.hs3
4 files changed, 31 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index d2f4c2b74..f68d1d0ad 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,5 @@ git-annex.1
git-annex-shell.1
doc/.ikiwiki
html
+*.tix
+.hpc
diff --git a/Makefile b/Makefile
index 2f1fd05b9..8d124f143 100644
--- a/Makefile
+++ b/Makefile
@@ -33,6 +33,13 @@ test:
$(GHCMAKE) test
./test
+testcoverage:
+ rm -f test.tix test
+ ghc -odir build/test -hidir build/test $(GHCFLAGS) --make -fhpc test
+ ./test
+ hpc report test --exclude=Main --exclude=QC
+ hpc markup test --exclude=Main --exclude=QC --destdir=.hpc
+
# If ikiwiki is available, build static html docs suitable for being
# shipped in the software package.
ifeq ($(shell which ikiwiki),)
@@ -49,7 +56,7 @@ docs: $(mans)
--exclude='news/.*'
clean:
- rm -rf build $(bins) $(mans) test configure SysConfig.hs
+ rm -rf build $(bins) $(mans) test configure SysConfig.hs *.tix .hpc
rm -rf doc/.ikiwiki html
.PHONY: $(bins) test install
diff --git a/TypeInternals.hs b/TypeInternals.hs
index 9acc06bb3..fe6e562f9 100644
--- a/TypeInternals.hs
+++ b/TypeInternals.hs
@@ -12,6 +12,7 @@ module TypeInternals where
import Control.Monad.State (StateT)
import Data.String.Utils
import qualified Data.Map as M
+import Test.QuickCheck
import qualified GitRepo as Git
import qualified GitQueue
@@ -57,6 +58,23 @@ instance Read Key where
b = head l
k = join ":" $ drop 1 l
+-- for quickcheck
+instance Arbitrary Key where
+ arbitrary = do
+ backendname <- arbitrary
+ keyname <- arbitrary
+ return $ Key (backendname, keyname)
+
+prop_idempotent_key_read_show :: Key -> Bool
+prop_idempotent_key_read_show k
+ -- filter out empty key or backend names
+ -- also backend names will not contain colons
+ | null kname || null bname || elem ':' bname = True
+ | otherwise = k == (read $ show k)
+ where
+ bname = backendName k
+ kname = keyName k
+
backendName :: Key -> BackendName
backendName (Key (b,_)) = b
keyName :: Key -> KeyName
diff --git a/test.hs b/test.hs
index 9d64e9260..28b54b78b 100644
--- a/test.hs
+++ b/test.hs
@@ -4,14 +4,17 @@ import Test.HUnit.Tools
import GitRepo
import Locations
import Utility
+import TypeInternals
alltests :: [Test]
alltests = [
qctest "prop_idempotent_deencode" prop_idempotent_deencode,
qctest "prop_idempotent_fileKey" prop_idempotent_fileKey,
+ qctest "prop_idempotent_key_read_show" prop_idempotent_key_read_show,
qctest "prop_idempotent_shellescape" prop_idempotent_shellescape,
qctest "prop_idempotent_shellescape_multiword" prop_idempotent_shellescape_multiword
]
main :: IO (Counts, Int)
main = runVerboseTests (TestList alltests)
+