From 91f4cfbc5214ad3a6db8dba09001639b905cab02 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 20 Dec 2013 15:35:35 -0500 Subject: [PATCH] Add a Tasty test suite. --- htsn.cabal | 45 +++++++++++++++++++++++++++++++++++++++++++ makefile | 7 ++++++- src/TSN/Xml.hs | 31 ++++++++++++++++++++++++++--- test/TestSuite.hs | 9 +++++++++ test/xml/19908216.xml | 1 + test/xml/19908217.xml | 1 + test/xml/19908245.xml | 1 + test/xml/19908246.xml | 1 + test/xml/19908247.xml | 1 + 9 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 test/TestSuite.hs create mode 100644 test/xml/19908216.xml create mode 100644 test/xml/19908217.xml create mode 100644 test/xml/19908245.xml create mode 100644 test/xml/19908246.xml create mode 100644 test/xml/19908247.xml diff --git a/htsn.cabal b/htsn.cabal index ed97657..30bdb9b 100644 --- a/htsn.cabal +++ b/htsn.cabal @@ -24,6 +24,8 @@ executable htsn filepath == 1.3.*, hxt == 9.3.*, network == 2.4.*, + tasty == 0.5.*, + tasty-hunit == 0.4.*, transformers == 0.3.*, unix == 2.6.* @@ -55,3 +57,46 @@ executable htsn -auto-all -caf-all + + +test-suite testsuite + type: exitcode-stdio-1.0 + hs-source-dirs: src test + main-is: TestSuite.hs + build-depends: + ansi-terminal == 0.6.*, + base == 4.*, + cmdargs >= 0.10.6, + configurator == 0.2.*, + directory == 1.2.*, + filepath == 1.3.*, + hxt == 9.3.*, + network == 2.4.*, + tasty == 0.5.*, + tasty-hunit == 0.4.*, + transformers == 0.3.*, + unix == 2.6.* + + -- It's not entirely clear to me why I have to reproduce all of this. + ghc-options: + -Wall + -fwarn-hi-shadowing + -fwarn-missing-signatures + -fwarn-name-shadowing + -fwarn-orphans + -fwarn-type-defaults + -fwarn-tabs + -fwarn-incomplete-record-updates + -fwarn-monomorphism-restriction + -fwarn-unused-do-bind + -rtsopts + -threaded + -optc-O3 + -optc-march=native + -O2 + + +source-repository head + type: git + location: http://michael.orlitzky.com/git/htsn.git + branch: master diff --git a/makefile b/makefile index 2b7f6c9..dfc3d1d 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,5 @@ BIN = dist/build/htsn/htsn +TESTSUITE_BIN = dist/build/testsuite/testsuite .PHONY : dist hlint @@ -23,7 +24,11 @@ clean: runghc Setup.hs clean -test: $(BIN) +$(TESTSUITE_BIN): src/*.hs test/TestSuite.hs + runghc Setup.hs configure --user --enable-tests + runghc Setup.hs build + +test: $(BIN) $(TESTSUITE_BIN) runghc Setup.hs test dist: diff --git a/src/TSN/Xml.hs b/src/TSN/Xml.hs index ead8015..ddde728 100644 --- a/src/TSN/Xml.hs +++ b/src/TSN/Xml.hs @@ -3,11 +3,14 @@ -- module TSN.Xml ( parse_xmlfid, - xml_prologue ) + xml_prologue, + xml_tests ) where -import Data.Maybe (listToMaybe, mapMaybe) -import Text.Read (readMaybe) +import Data.Maybe ( listToMaybe, mapMaybe ) +import Test.Tasty ( TestTree, testGroup ) +import Test.Tasty.HUnit ( (@?=), Assertion, testCase ) +import Text.Read ( readMaybe ) import Text.XML.HXT.Core ( (>>>), (/>), @@ -35,3 +38,25 @@ parse_xmlfid = -- | The opening "tag" for the XML prologue. xml_prologue :: String xml_prologue = " Assertion + check xmlfid = do + xml <- readFile ("test/xml/" ++ xmlfid ++ ".xml") + let actual = parse_xmlfid xml + let expected = readMaybe xmlfid + actual @?= expected diff --git a/test/TestSuite.hs b/test/TestSuite.hs new file mode 100644 index 0000000..f5d6d3c --- /dev/null +++ b/test/TestSuite.hs @@ -0,0 +1,9 @@ +import Test.Tasty ( TestTree, defaultMain ) + +import TSN.Xml ( xml_tests ) + +tests :: TestTree +tests = xml_tests + +main :: IO () +main = defaultMain tests diff --git a/test/xml/19908216.xml b/test/xml/19908216.xml new file mode 100644 index 0000000..b04b661 --- /dev/null +++ b/test/xml/19908216.xml @@ -0,0 +1 @@ + 19908216 BC-ABi+070:090* 0 0 0 4373 4373 Scores NFL Tennessee TN USA Jacksonville FL USA Regular Tennessee Jacksonville 0 0 0 Qtr Jacksonville - Wide receiver Geno Hayes (12/20, kneeLB) is questionable for Sunday's game against Tennessee. December 20, 2013, at 02:59 PM ET \ No newline at end of file diff --git a/test/xml/19908217.xml b/test/xml/19908217.xml new file mode 100644 index 0000000..a7bcf12 --- /dev/null +++ b/test/xml/19908217.xml @@ -0,0 +1 @@ + 19908217 BC-ABi+070:090* 0 0 0 4373 4373 Scores NFL Tennessee TN USA Jacksonville FL USA Regular Tennessee Jacksonville 0 0 0 Qtr Jacksonville - Running back Maurice Jones-Drew (12/20, hamstring) is questionable for Sunday's game against Tennessee. December 20, 2013, at 02:59 PM ET \ No newline at end of file diff --git a/test/xml/19908245.xml b/test/xml/19908245.xml new file mode 100644 index 0000000..513622c --- /dev/null +++ b/test/xml/19908245.xml @@ -0,0 +1 @@ + 19908245 BC-HBC December 20, 2013, at 03:10 PM ET \ No newline at end of file diff --git a/test/xml/19908246.xml b/test/xml/19908246.xml new file mode 100644 index 0000000..764d86e --- /dev/null +++ b/test/xml/19908246.xml @@ -0,0 +1 @@ + 19908246 BC-HBC December 20, 2013, at 03:10 PM ET \ No newline at end of file diff --git a/test/xml/19908247.xml b/test/xml/19908247.xml new file mode 100644 index 0000000..bdb042e --- /dev/null +++ b/test/xml/19908247.xml @@ -0,0 +1 @@ + 19908247 BC-CZJ JFILE SOC-NPSL 1287 1287 Regular 12/20/2013 07:05 PM Baltimore Pennsylvania 0 0 7:05 PM December 20, 2013, at 03:10 PM ET \ No newline at end of file -- 2.44.2