Use cabal integration for the test suite.
+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:
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
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 <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 $
+ ""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 <insert " ++
+ "the current president of the United States of America>. " ++
+ "“It’s OK—–he’s not a real doctor.”"
--- |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
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
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)
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"]
-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
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
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
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
-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