diff options
author | Will Thompson <will@willthompson.co.uk> | 2012-01-16 15:26:41 +0000 |
---|---|---|
committer | Will Thompson <will@willthompson.co.uk> | 2012-01-16 15:26:41 +0000 |
commit | 01d56daf6b8759bf26c934e82417cc70fa8fc2b8 (patch) | |
tree | 64ba825c7602a9a40d5c66d7f2a86b53d5b6bd8a | |
parent | 6bdc99ace562cdf678fe100372129917349f0658 (diff) |
HUnit-ify the Renderer test, and rename it.
-rw-r--r-- | Test/Participants.hs | 38 | ||||
-rw-r--r-- | Test/Renderer.hs | 41 | ||||
-rw-r--r-- | bustle.cabal | 7 |
3 files changed, 46 insertions, 40 deletions
diff --git a/Test/Participants.hs b/Test/Participants.hs deleted file mode 100644 index f65fa15..0000000 --- a/Test/Participants.hs +++ /dev/null @@ -1,38 +0,0 @@ --- Tests that services visible in a log are listed as participants even if they --- disconnect from the bus before the end of the log. This is a regression test --- for a bug I almost introduced. -module Main where - -import Control.Monad (when) -import qualified Data.Set as Set -import System.Exit (exitFailure) - -import Bustle.Types -import Bustle.Renderer - -activeService = UniqueName ":1.1" -swaddle = map (\m -> DetailedMessage 0 m Nothing) -sessionLog = - [ Connected activeService - , Signal (U activeService) Nothing $ Member "/" Nothing "Hello" - ] -sessionLogWithDisconnect = sessionLog ++ [ Disconnected activeService ] -expectedParticipants = [ (activeService, Set.empty) ] - -assertEquals expected actual = - when (expected /= actual) $ do - putStrLn "Expected:" - print expected - putStrLn "Got:" - print actual - exitFailure - -test l expected = do - let rr = process (swaddle l) [] - ps = sessionParticipants (rrApplications rr) - - assertEquals expected ps - -main = do - test sessionLog expectedParticipants - test sessionLogWithDisconnect expectedParticipants diff --git a/Test/Renderer.hs b/Test/Renderer.hs new file mode 100644 index 0000000..ce62257 --- /dev/null +++ b/Test/Renderer.hs @@ -0,0 +1,41 @@ +module Main where + +import Test.Framework (defaultMain, testGroup) +import Test.Framework.Providers.HUnit + +import Test.HUnit + +import Control.Monad (when) +import qualified Data.Set as Set +import System.Exit (exitFailure) + +import Bustle.Types +import Bustle.Renderer + +main = defaultMain tests + where + tests = [ testGroup "Disconnections don't affect participants" + [ testCase "One participant, no disconnection" test_participants + , testCase "One participant, which disconnects" test_participants_with_disconnect + ] + ] + +-- Tests that services visible in a log are listed as participants even if they +-- disconnect from the bus before the end of the log. This is a regression test +-- for a bug I almost introduced. +activeService = UniqueName ":1.1" +swaddle = map (\m -> DetailedMessage 0 m Nothing) +sessionLog = + [ Connected activeService + , Signal (U activeService) Nothing $ Member "/" Nothing "Hello" + ] +sessionLogWithDisconnect = sessionLog ++ [ Disconnected activeService ] +expectedParticipants = [ (activeService, Set.empty) ] + +test_ l expected = expected @=? ps + where + rr = process (swaddle l) [] + ps = sessionParticipants (rrApplications rr) + +test_participants = test_ sessionLog expectedParticipants +test_participants_with_disconnect = test_ sessionLogWithDisconnect expectedParticipants diff --git a/bustle.cabal b/bustle.cabal index b7b9070..ae80023 100644 --- a/bustle.cabal +++ b/bustle.cabal @@ -150,9 +150,9 @@ Test-suite test-regions Build-Depends: base , QuickCheck -Test-suite test-participants +Test-suite test-renderer type: exitcode-stdio-1.0 - main-is: Test/Participants.hs + main-is: Test/Renderer.hs other-modules: Bustle.Renderer Build-Depends: base , cairo @@ -163,3 +163,6 @@ Test-suite test-participants , gtk , mtl , pango + , test-framework + , test-framework-hunit + , HUnit |