]> gitweb.michael.orlitzky.com - dead/halcyon.git/commitdiff
Use test-framework instead of bare HUnit for the test suite.
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 13 Jul 2013 22:20:48 +0000 (18:20 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sat, 13 Jul 2013 22:20:48 +0000 (18:20 -0400)
Use cabal integration for the test suite.

makefile
src/Html.hs
src/StringUtils.hs
src/Twitter/Status.hs
test/TestSuite.hs
twat.cabal

index abe71a3acbc7416c4048fb75885472bda361fb60..6ef9b5779c5e75b53be88d7d386e31bd16f88119 100644 (file)
--- a/makefile
+++ b/makefile
@@ -1,15 +1,22 @@
+BIN           = dist/build/twat/twat
+TESTSUITE_BIN = dist/build/testsuite/testsuite
+
 .PHONY : doc test
 
 .PHONY : doc test
 
-twat: src/*.hs src/Twitter/*.hs
+$(BIN): src/*.hs src/Twitter/*.hs
        runghc Setup.hs clean
        runghc Setup.hs configure --user
        runghc Setup.hs build
 
        runghc Setup.hs clean
        runghc Setup.hs configure --user
        runghc Setup.hs build
 
+$(TESTSUITE_BIN): src/*.hs test/TestSuite.hs
+       runghc Setup.hs configure --user --enable-tests
+       runghc Setup.hs build
+
 clean:
        runghc Setup.hs clean
 
 clean:
        runghc Setup.hs clean
 
-test:
-       runghc -i"src" test/TestSuite.hs
+test: $(BIN) $(TESTSUITE_BIN)
+       runghc Setup.hs test
 
 # Neither 'haddock' nor 'hscolour' seem to work properly.
 doc:
 
 # Neither 'haddock' nor 'hscolour' seem to work properly.
 doc:
index 1c9a4285541c720c2c413166f606cb15d5abdc46..2f9332522292d34bbed8f7d4abc8d8a890e09ea8 100644 (file)
@@ -1,7 +1,9 @@
 module Html
 where
 
 module Html
 where
 
-import Test.HUnit
+import Test.Framework (Test, testGroup)
+import Test.Framework.Providers.HUnit (testCase)
+import Test.HUnit (Assertion, assertEqual)
 import Text.HTML.TagSoup.Entity (lookupEntity)
 
 replace_entities :: String -> String
 import Text.HTML.TagSoup.Entity (lookupEntity)
 
 replace_entities :: String -> String
@@ -14,21 +16,26 @@ replace_entities ('&':xs) =
 replace_entities (x:xs) = x : replace_entities xs
 
 
 replace_entities (x:xs) = x : replace_entities xs
 
 
-html_tests :: [Test]
-html_tests = [ test_replace_entities ]
+html_tests :: Test
+html_tests =
+  testGroup "HTML Tests" [ tc1 ]
+  where
+    tc1 = testCase
+            "All entities are replaced correctly."
+            test_replace_entities
 
 
-test_replace_entities :: Test
+test_replace_entities :: Assertion
 test_replace_entities =
 test_replace_entities =
-    TestCase $ assertEqual description expected_text actual_text
-    where
-      description = "All entities are replaced correctly."
-      actual_text =
-        replace_entities $
-          "&quot;The moon is gay&#8230;&hellip;&quot; " ++
-          "said &lt;insert the current president of the " ++
-          "United States of America&gt;. &ldquo;It&#8217;s " ++
-          "OK&mdash;&ndash;he&#8217;s not a real doctor.&rdquo;"
-      expected_text =
-        "\"The moon is gay……\" said <insert " ++
-        "the current president of the United States of America>. " ++
-        "“It’s OK—–he’s not a real doctor.”"
+  assertEqual description expected_text actual_text
+  where
+    description = "All entities are replaced correctly."
+    actual_text =
+      replace_entities $
+        "&quot;The moon is gay&#8230;&hellip;&quot; " ++
+        "said &lt;insert the current president of the " ++
+        "United States of America&gt;. &ldquo;It&#8217;s " ++
+        "OK&mdash;&ndash;he&#8217;s not a real doctor.&rdquo;"
+    expected_text =
+      "\"The moon is gay……\" said <insert " ++
+      "the current president of the United States of America>. " ++
+      "“It’s OK—–he’s not a real doctor.”"
index b5feccb3f079a32755784ad2afc63b894802233b..55939680467bb314f24aae53e70485e693c6055d 100644 (file)
@@ -1,8 +1,10 @@
--- |Miscellaneous functions for manipulating string.
+-- | Miscellaneous functions for manipulating string.
 module StringUtils
 where
 
 module StringUtils
 where
 
-import Test.HUnit
+import Test.Framework (Test, testGroup)
+import Test.Framework.Providers.HUnit (testCase)
+import Test.HUnit (Assertion, assertEqual)
 
 
 -- | Takes a list of strings, call them string1, string2, etc. and
 
 
 -- | Takes a list of strings, call them string1, string2, etc. and
@@ -20,15 +22,20 @@ listify =
       show_with_dot x = (show x) ++ ". "
 
 
       show_with_dot x = (show x) ++ ". "
 
 
+--
+-- Tests
+--
 
 
-string_utils_tests :: [Test]
-string_utils_tests = [ test_listify ]
-
-
-test_listify :: Test
+test_listify :: Assertion
 test_listify =
 test_listify =
-    TestCase $ assertEqual description expected_items actual_items
-    where
-      description = "All items are numbered correctly."
-      actual_items = listify [ "item1", "item2" ]
-      expected_items = ["1. item1", "2. item2" ]
+  assertEqual description expected_items actual_items
+  where
+    description = "All items are numbered correctly."
+    actual_items = listify [ "item1", "item2" ]
+    expected_items = ["1. item1", "2. item2" ]
+
+string_utils_tests :: Test
+string_utils_tests =
+  testGroup "StringUtils Tests" [ tc1 ]
+  where
+    tc1 = testCase "All items are numbered correctly." test_listify
index 176619d0ed5a6e2d9f2720b13fe4abed61350cfd..191b8e85b734820bf73541ec9e55d621a0e0ba73 100644 (file)
@@ -16,7 +16,9 @@ import Data.Time.Clock (UTCTime)
 import Data.Time.Format (parseTime)
 import Data.Time.LocalTime (TimeZone, utcToZonedTime)
 import System.Locale (defaultTimeLocale, rfc822DateFormat)
 import Data.Time.Format (parseTime)
 import Data.Time.LocalTime (TimeZone, utcToZonedTime)
 import System.Locale (defaultTimeLocale, rfc822DateFormat)
-import Test.HUnit
+import Test.Framework (Test, testGroup)
+import Test.Framework.Providers.HUnit (testCase)
+import Test.HUnit (Assertion, assertEqual)
 import Text.Regex (matchRegex, mkRegex)
 
 import Html (replace_entities)
 import Text.Regex (matchRegex, mkRegex)
 
 import Html (replace_entities)
@@ -136,26 +138,30 @@ make_user_timeline_urls status =
     usernames = parse_usernames_from_status status
 
 
     usernames = parse_usernames_from_status status
 
 
-status_tests :: [Test]
-status_tests = [ test_parse_usernames ]
+status_tests :: Test
+status_tests =
+  testGroup "Status Tests" [ tc1 ]
+  where
+    tc1 = testCase "All usernames are parsed." test_parse_usernames
 
 
 
 
-test_parse_usernames :: Test
+test_parse_usernames :: Assertion
 test_parse_usernames =
 test_parse_usernames =
-    TestCase $
-      assertEqual
-      "All usernames are parsed."
-      expected_usernames
-      actual_usernames
-    where
-      dummy_user = User { screen_name = "nobody" }
-      dummy_status = Status { status_id = 1,
-                              created_at = Nothing,
-                              text = "Hypothesis: @donsbot and @bonus500 are two personalities belonging to the same person.",
-                              user = dummy_user,
-                              reply = False,
-                              retweeted = False
-                            }
-
-      actual_usernames = parse_usernames_from_status dummy_status
-      expected_usernames = ["donsbot", "bonus500"]
+  assertEqual
+    "All usernames are parsed."
+    expected_usernames
+    actual_usernames
+  where
+    dummy_user = User { screen_name = "nobody" }
+    dummy_text = "Hypothesis: @donsbot and @bonus500 are two " ++
+                 "personalities belonging to the same person."
+    dummy_status = Status { status_id = 1,
+                            created_at = Nothing,
+                            text = dummy_text,
+                            user = dummy_user,
+                            reply = False,
+                            retweeted = False
+                          }
+
+    actual_usernames = parse_usernames_from_status dummy_status
+    expected_usernames = ["donsbot", "bonus500"]
index 4fa222dfbfa1bd87dcf2f97bc80f82b33de5da56..036e61622e1df1d1d5a14ead79e25864088b9a47 100644 (file)
@@ -1,15 +1,16 @@
-import Test.HUnit
+import Test.Framework (
+  Test,
+  defaultMain,
+  )
 
 import StringUtils (string_utils_tests)
 import Twitter.Status(status_tests)
 import Html(html_tests)
 
 
 import StringUtils (string_utils_tests)
 import Twitter.Status(status_tests)
 import Html(html_tests)
 
--- The list of HUnit tests.
-test_suite = TestList (concat [html_tests, status_tests, string_utils_tests])
+tests :: [Test]
+tests = [ html_tests,
+          status_tests,
+          string_utils_tests ]
 
 main :: IO ()
 
 main :: IO ()
-main = do
-  putStrLn "HUnit"
-  putStrLn "-----"
-  runTestTT test_suite
-  return ()
+main = defaultMain tests
index 5e045868870d57a31bc3b74491615381260b8831..12c978ede25872d620e2baa1db72a6681b77ecdb 100644 (file)
@@ -3,6 +3,11 @@ version:        0.0
 cabal-version:  >= 1.8
 author:         Michael Orlitzky
 maintainer:    Michael Orlitzky <michael@orlitzky.com>
 cabal-version:  >= 1.8
 author:         Michael Orlitzky
 maintainer:    Michael Orlitzky <michael@orlitzky.com>
+license:        GPL-3
+license-file:   doc/LICENSE
+homepage:       http://michael.orlitzky.com/code/twat.php
+bug-reports:    mailto:michael@orlitzky.com
+category:       Math
 synopsis:
   Twat twats tweets so you don't have to twitter.
 build-type:     Simple
 synopsis:
   Twat twats tweets so you don't have to twitter.
 build-type:     Simple
@@ -24,8 +29,10 @@ executable twat
     regex-compat                == 0.*,
     tagsoup                     == 0.12.*,
     text                        == 0.11.*,
     regex-compat                == 0.*,
     tagsoup                     == 0.12.*,
     text                        == 0.11.*,
-    time                        == 1.*
-
+    time                        == 1.*,
+    -- Test deps
+    test-framework              == 0.8.*,
+    test-framework-hunit        == 0.3.*
 
   main-is:
     Main.hs
 
   main-is:
     Main.hs
@@ -33,6 +40,57 @@ executable twat
   hs-source-dirs:
     src/
 
   hs-source-dirs:
     src/
 
+  other-modules:
+    CommandLine
+    Configuration
+    ExitCodes
+    Html
+    Mail
+    StringUtils
+    Twitter.Http
+    Twitter.Status
+    Twitter.User
+
+  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
+    -optc-O3
+    -optc-march=native
+
+test-suite testsuite
+  type: exitcode-stdio-1.0
+  hs-source-dirs: src test
+  main-is: TestSuite.hs
+  build-depends:
+    aeson                       == 0.6.*,
+    authenticate-oauth          == 1.4.*,
+    base                        == 4.*,
+    bytestring                  == 0.10.*,
+    conduit                     == 1.*,
+    directory                   == 1.2.*,
+    HaXml                       == 1.24.*,
+    http-conduit                == 1.9.*,
+    HUnit                       == 1.2.*,
+    MissingH                    == 1.*,
+    process                     == 1.*,
+    old-locale                  == 1.*,
+    regex-compat                == 0.*,
+    tagsoup                     == 0.12.*,
+    text                        == 0.11.*,
+    time                        == 1.*,
+    -- Test deps
+    test-framework              == 0.8.*,
+    test-framework-hunit        == 0.3.*
+
+  -- It's not entirely clear to me why I have to reproduce all of this.
   ghc-options:
     -Wall
     -fwarn-hi-shadowing
   ghc-options:
     -Wall
     -fwarn-hi-shadowing
@@ -44,8 +102,10 @@ executable twat
     -fwarn-incomplete-record-updates
     -fwarn-monomorphism-restriction
     -fwarn-unused-do-bind
     -fwarn-incomplete-record-updates
     -fwarn-monomorphism-restriction
     -fwarn-unused-do-bind
-    -funbox-strict-fields
-    -fexcess-precision
-    -fno-spec-constr-count
     -optc-O3
     -optc-march=native
     -optc-O3
     -optc-march=native
+
+source-repository head
+  type: git
+  location: http://michael.orlitzky.com/git/twat.git
+  branch: master