From 4cc476a2714260980899ca5358196bbf5226b3c2 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 13 Jul 2013 18:20:48 -0400 Subject: [PATCH] Use test-framework instead of bare HUnit for the test suite. Use cabal integration for the test suite. --- makefile | 13 ++++++-- src/Html.hs | 41 ++++++++++++++----------- src/StringUtils.hs | 31 +++++++++++-------- src/Twitter/Status.hs | 48 ++++++++++++++++------------- test/TestSuite.hs | 17 ++++++----- twat.cabal | 70 +++++++++++++++++++++++++++++++++++++++---- 6 files changed, 154 insertions(+), 66 deletions(-) diff --git a/makefile b/makefile index abe71a3..6ef9b57 100644 --- a/makefile +++ b/makefile @@ -1,15 +1,22 @@ +BIN = dist/build/twat/twat +TESTSUITE_BIN = dist/build/testsuite/testsuite + .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 +$(TESTSUITE_BIN): src/*.hs test/TestSuite.hs + runghc Setup.hs configure --user --enable-tests + runghc Setup.hs build + 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: diff --git a/src/Html.hs b/src/Html.hs index 1c9a428..2f93325 100644 --- a/src/Html.hs +++ b/src/Html.hs @@ -1,7 +1,9 @@ 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 @@ -14,21 +16,26 @@ 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 = - TestCase $ assertEqual description expected_text actual_text - where - description = "All entities are replaced correctly." - actual_text = - replace_entities $ - ""The moon is gay……" " ++ - "said <insert the current president of the " ++ - "United States of America>. “It’s " ++ - "OK—–he’s not a real doctor.”" - expected_text = - "\"The moon is gay……\" said . " ++ - "“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 $ + ""The moon is gay……" " ++ + "said <insert the current president of the " ++ + "United States of America>. “It’s " ++ + "OK—–he’s not a real doctor.”" + expected_text = + "\"The moon is gay……\" said . " ++ + "“It’s OK—–he’s not a real doctor.”" diff --git a/src/StringUtils.hs b/src/StringUtils.hs index b5feccb..5593968 100644 --- a/src/StringUtils.hs +++ b/src/StringUtils.hs @@ -1,8 +1,10 @@ --- |Miscellaneous functions for manipulating string. +-- | Miscellaneous functions for manipulating string. 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 @@ -20,15 +22,20 @@ listify = show_with_dot x = (show x) ++ ". " +-- +-- Tests +-- -string_utils_tests :: [Test] -string_utils_tests = [ test_listify ] - - -test_listify :: Test +test_listify :: Assertion 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 diff --git a/src/Twitter/Status.hs b/src/Twitter/Status.hs index 176619d..191b8e8 100644 --- a/src/Twitter/Status.hs +++ b/src/Twitter/Status.hs @@ -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 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) @@ -136,26 +138,30 @@ make_user_timeline_urls 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 = - 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"] diff --git a/test/TestSuite.hs b/test/TestSuite.hs index 4fa222d..036e616 100644 --- a/test/TestSuite.hs +++ b/test/TestSuite.hs @@ -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) --- 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 = do - putStrLn "HUnit" - putStrLn "-----" - runTestTT test_suite - return () +main = defaultMain tests diff --git a/twat.cabal b/twat.cabal index 5e04586..12c978e 100644 --- a/twat.cabal +++ b/twat.cabal @@ -3,6 +3,11 @@ version: 0.0 cabal-version: >= 1.8 author: Michael Orlitzky maintainer: Michael Orlitzky +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 @@ -24,8 +29,10 @@ executable twat 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 @@ -33,6 +40,57 @@ executable twat 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 @@ -44,8 +102,10 @@ executable twat -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 + +source-repository head + type: git + location: http://michael.orlitzky.com/git/twat.git + branch: master -- 2.44.2