Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions test/test.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
module Main where

import Control.Concurrent (threadDelay)
Expand All @@ -25,9 +26,16 @@ import Test.Tasty
import Test.Tasty.HUnit
import Test.Tasty.QuickCheck as QC

-- Needed to disable test case parallelism with tasty >= 1.5.4,
-- but not available (nor necessary) for tasty < 1.5.4
#if !MIN_VERSION_tasty(1,5,4)
inOrderTestGroup :: TestName -> [TestTree] -> TestTree
inOrderTestGroup = testGroup
#endif

main :: IO ()
main = defaultMain $ testGroup "socket"
[ testGroup "System.Socket"
[ inOrderTestGroup "System.Socket"
[ group00
, group01
, group02
Expand All @@ -50,8 +58,8 @@ port6 :: Inet6Port
port6 = 39000

group00 :: TestTree
group00 = testGroup "accept"
[ testGroup "Inet/Stream/TCP"
group00 = inOrderTestGroup "accept"
[ inOrderTestGroup "Inet/Stream/TCP"
[ testCase "cancel operation" $
-- | This is to test interruptability of (blocking) calls like
-- accept. The implementation may either run the call "safe"
Expand All @@ -77,7 +85,7 @@ group00 = testGroup "accept"
]

group01 :: TestTree
group01 = testGroup "connect" [ testGroup "Inet/Stream/TCP" t1 ]
group01 = inOrderTestGroup "connect" [ inOrderTestGroup "Inet/Stream/TCP" t1 ]
where
t1 =
[ testCase "connect to closed port on inetLoopback" $ bracket
Expand Down Expand Up @@ -160,8 +168,8 @@ group01 = testGroup "connect" [ testGroup "Inet/Stream/TCP" t1 ]
]

group02 :: TestTree
group02 = testGroup "listen"
[ testGroup "Inet/Datagram/UDP"
group02 = inOrderTestGroup "listen"
[ inOrderTestGroup "Inet/Datagram/UDP"
[ testCase "listen on bound socket" $ bracket
( socket :: IO (Socket Inet Datagram UDP) ) close $ \sock-> do
bind sock (SocketAddressInet inetLoopback port)
Expand All @@ -170,7 +178,7 @@ group02 = testGroup "listen"
_ | e == eOperationNotSupported -> return ()
_ -> assertFailure "expected eOperationNotSupported"
]
, testGroup "Inet/Stream/TCP"
, inOrderTestGroup "Inet/Stream/TCP"
[ testCase "listen on bound socket" $ bracket
( socket :: IO (Socket Inet Stream TCP) ) close $ \sock-> do
bind sock (SocketAddressInet inetLoopback port)
Expand All @@ -180,8 +188,8 @@ group02 = testGroup "listen"
]

group03 :: TestTree
group03 = testGroup "send/receive"
[ testGroup "Inet/Stream/TCP"
group03 = inOrderTestGroup "send/receive"
[ inOrderTestGroup "Inet/Stream/TCP"
[ testCase "send and receive a chunk" $ bracket
( do
server <- socket :: IO (Socket Inet Stream TCP)
Expand Down Expand Up @@ -264,7 +272,7 @@ group03 = testGroup "send/receive"
Left e -> unless (e == ePipe) (throwIO e)
)
]
, testGroup "Inet/Datagram/UDP"
, inOrderTestGroup "Inet/Datagram/UDP"
[ testCase "send and receive a datagram" $ bracket
( do
server <- socket :: IO (Socket Inet Datagram UDP)
Expand Down Expand Up @@ -292,8 +300,8 @@ group03 = testGroup "send/receive"
]

group07 :: TestTree
group07 = testGroup "sendAll/receiveAll"
[ testGroup "Inet/Stream/TCP"
group07 = inOrderTestGroup "sendAll/receiveAll"
[ inOrderTestGroup "Inet/Stream/TCP"
[ testCase "sendAll and receiveAll a 128MB chunk" $ bracket
( do
server <- socket :: IO (Socket Inet Stream TCP)
Expand Down Expand Up @@ -382,7 +390,7 @@ group07 = testGroup "sendAll/receiveAll"
]

group80 :: TestTree
group80 = testGroup "setSocketOption" [ testGroup "V6Only"
group80 = inOrderTestGroup "setSocketOption" [ inOrderTestGroup "V6Only"
[ testCase "present" $ bracket
( do
server <- socket :: IO (Socket Inet6 Datagram UDP)
Expand Down Expand Up @@ -433,7 +441,7 @@ group80 = testGroup "setSocketOption" [ testGroup "V6Only"
]

group98 :: TestTree
group98 = testGroup "getAddress" [
group98 = inOrderTestGroup "getAddress" [

testCase "getAddress after bind" $ bracket
( socket :: IO (Socket Inet Stream Default) ) close
Expand All @@ -446,7 +454,7 @@ group98 = testGroup "getAddress" [
]

group99 :: TestTree
group99 = testGroup "getAddrInfo" [
group99 = inOrderTestGroup "getAddrInfo" [

testCase "getAddrInfo \"127.0.0.1\" \"80\"" $ do
ais <- getAddressInfo
Expand Down