]> gitweb.michael.orlitzky.com - dead/htsn.git/commitdiff
Add a Tasty test suite.
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 20 Dec 2013 20:35:35 +0000 (15:35 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 20 Dec 2013 20:35:35 +0000 (15:35 -0500)
htsn.cabal
makefile
src/TSN/Xml.hs
test/TestSuite.hs [new file with mode: 0644]
test/xml/19908216.xml [new file with mode: 0644]
test/xml/19908217.xml [new file with mode: 0644]
test/xml/19908245.xml [new file with mode: 0644]
test/xml/19908246.xml [new file with mode: 0644]
test/xml/19908247.xml [new file with mode: 0644]

index ed97657a6ce55d4471514145ff76bde32a2cce77..30bdb9bcca5d90180def22df1d9e93340d1ac102 100644 (file)
@@ -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
index 2b7f6c92ba38937ae1fc084538b4333c8c4dd50d..dfc3d1df795431bf5959d0d4a8d26a0eebc83675 100644 (file)
--- 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:
index ead8015de509481f31ca9ec3b4e23ac89b0fadc5..ddde728afa9c76727a427c849ee14a0d4a140100 100644 (file)
@@ -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 = "<?xml "
+
+
+-- * Tasty Tests
+xml_tests :: TestTree
+xml_tests =
+  testGroup
+    "XML tests"
+    [ xml_file_id_tests ]
+
+
+xml_file_id_tests :: TestTree
+xml_file_id_tests =
+  testCase "XML_File_ID is parsed correctly" $ do
+    let xmlfids = ["19908216", "19908216", "19908245", "19908246", "19908247"]
+    mapM_ check xmlfids
+  where
+    check :: String -> 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 (file)
index 0000000..f5d6d3c
--- /dev/null
@@ -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 (file)
index 0000000..b04b661
--- /dev/null
@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no" ?>\r<!DOCTYPE message PUBLIC "-//TSN//DTD Scores 1.0/EN" "scoresxml.dtd">\r<message>\r<XML_File_ID>19908216</XML_File_ID>\r<heading>BC-ABi+070:090*  0  0 0</heading>\r<game_id>4373</game_id>\r<schedule_id>4373</schedule_id>\r<category>Scores</category>\r<sport>NFL</sport>\r<location>\r<city>Tennessee</city>\r<state>TN</state>\r<country>USA</country>\r</location>\r<location>\r<city>Jacksonville</city>\r<state>FL</state>\r<country>USA</country>\r</location>\r<seasontype>Regular</seasontype>\r<game>\r<vteam id="070">Tennessee</vteam>\r<hteam id="090">Jacksonville</hteam>\r<vscore>0</vscore>\r<hscore>0</hscore>\r<status numeral="0" type="i">0 Qtr</status>\r<notes>Jacksonville - Wide receiver Geno Hayes (12/20, kneeLB) is questionable for \r  Sunday's game against Tennessee.</notes>\r</game>\r<time_stamp> December 20, 2013, at 02:59 PM ET </time_stamp>\r</message>\r
\ No newline at end of file
diff --git a/test/xml/19908217.xml b/test/xml/19908217.xml
new file mode 100644 (file)
index 0000000..a7bcf12
--- /dev/null
@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no" ?>\r<!DOCTYPE message PUBLIC "-//TSN//DTD Scores 1.0/EN" "scoresxml.dtd">\r<message>\r<XML_File_ID>19908217</XML_File_ID>\r<heading>BC-ABi+070:090*  0  0 0</heading>\r<game_id>4373</game_id>\r<schedule_id>4373</schedule_id>\r<category>Scores</category>\r<sport>NFL</sport>\r<location>\r<city>Tennessee</city>\r<state>TN</state>\r<country>USA</country>\r</location>\r<location>\r<city>Jacksonville</city>\r<state>FL</state>\r<country>USA</country>\r</location>\r<seasontype>Regular</seasontype>\r<game>\r<vteam id="070">Tennessee</vteam>\r<hteam id="090">Jacksonville</hteam>\r<vscore>0</vscore>\r<hscore>0</hscore>\r<status numeral="0" type="i">0 Qtr</status>\r<notes>Jacksonville - Running back Maurice Jones-Drew (12/20, hamstring) is \r  questionable for Sunday's game against Tennessee.</notes>\r</game>\r<time_stamp> December 20, 2013, at 02:59 PM ET </time_stamp>\r</message>\r
\ No newline at end of file
diff --git a/test/xml/19908245.xml b/test/xml/19908245.xml
new file mode 100644 (file)
index 0000000..513622c
--- /dev/null
@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no" ?>\r<!DOCTYPE message PUBLIC "-//TSN//DTD Heartbeat 1.0/EN" "Heartbeat.dtd">\r<message>\r<XML_File_ID>19908245</XML_File_ID>\r<heading>BC-HBC</heading>\r<time_stamp> December 20, 2013, at 03:10 PM ET </time_stamp>\r</message>\r
\ No newline at end of file
diff --git a/test/xml/19908246.xml b/test/xml/19908246.xml
new file mode 100644 (file)
index 0000000..764d86e
--- /dev/null
@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no" ?>\r<!DOCTYPE message PUBLIC "-//TSN//DTD Heartbeat 1.0/EN" "Heartbeat.dtd">\r<message>\r<XML_File_ID>19908246</XML_File_ID>\r<heading>BC-HBC</heading>\r<time_stamp> December 20, 2013, at 03:10 PM ET </time_stamp>\r</message>\r
\ No newline at end of file
diff --git a/test/xml/19908247.xml b/test/xml/19908247.xml
new file mode 100644 (file)
index 0000000..bdb042e
--- /dev/null
@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no" ?>\r<!DOCTYPE message PUBLIC "-//TSN//DTD Scores 1.0/EN" "jfilexml.dtd">\r<message>\r<XML_File_ID>19908247</XML_File_ID>\r<heading>BC-CZJ</heading>\r<category>JFILE</category>\r<sport>SOC-NPSL</sport>\r<gamelist>\r<game>\r<game_id>1287</game_id>\r<schedule_id>1287</schedule_id>\r<Odds_Info>\r<ListDate></ListDate>\r<HomeTeamID></HomeTeamID>\r<AwayTeamID></AwayTeamID>\r<HomeAbbr></HomeAbbr>\r<AwayAbbr></AwayAbbr>\r<HomeTeamName></HomeTeamName>\r<AwayTeamName></AwayTeamName>\r<HStarter></HStarter>\r<AStarter></AStarter>\r<GameDate></GameDate>\r<HGameKey></HGameKey>\r<AGameKey></AGameKey>\r<CurrentTimeStamp></CurrentTimeStamp>\r<Live></Live>\r<Notes1></Notes1>\r<Notes2></Notes2>\r<Notes3></Notes3>\r<Notes4></Notes4>\r<Notes5></Notes5>\r</Odds_Info>\r<seasontype>Regular</seasontype>\r<Game_Date>12/20/2013</Game_Date>\r<Game_Time>07:05 PM</Game_Time>\r<vteam teamid="226" abbr="BAL">Baltimore</vteam>\r<hteam teamid="ZX5" abbr="PEN">Pennsylvania</hteam>\r<vscore>0</vscore>\r<hscore>0</hscore>\r<status numeral="0">7:05 PM</status>\r</game>\r</gamelist>\r<time_stamp>December 20, 2013, at 03:10 PM ET </time_stamp>\r</message>\r
\ No newline at end of file