-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test and remove warnings of undefined behaviour #375
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3de2213
Test and remove warnings of undefined behaviour
eborden da141cd
Add consistent spacing between specs
eborden 40ef8be
Use return instead of pure for backwards compat
eborden cd01980
Break up specs so they are interface focused
eborden 065947a
Remove redudant import and Werror
eborden 23a95a6
Import Test.Hspec
eborden 3699bb3
Remove throw tests for getContents
eborden 7826707
Remove unnecessary CPP pragma
eborden 4a7d5fe
Remove unnecessary ScopedTypeVariables
eborden 54843ca
Fix inconsistent indentation
eborden a2806eb
Disable getContents tests on darwin
eborden 9f4d11d
Enable CPP
eborden ce1bc23
Catch exceptions on shutdown
eborden 286f559
Use catchIOError instead of onException
eborden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module Network.Socket.ByteString.LazySpec (main, spec) where | ||
|
||
import Prelude hiding (getContents) | ||
|
||
import qualified Data.ByteString.Lazy as L | ||
import Network.Socket | ||
import Network.Socket.ByteString.Lazy | ||
import Network.Test.Common | ||
import Control.Monad | ||
|
||
import Test.Hspec | ||
|
||
main :: IO () | ||
main = hspec spec | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "send" $ do | ||
it "works well" $ do | ||
let server sock = recv sock 1024 `shouldReturn` lazyTestMsg | ||
client sock = send sock lazyTestMsg | ||
tcpTest client server | ||
|
||
it "throws when closed" $ do | ||
let server _ = return () | ||
client sock = do | ||
close sock | ||
send sock lazyTestMsg `shouldThrow` anyException | ||
tcpTest client server | ||
|
||
describe "sendAll" $ do | ||
it "works well" $ do | ||
let server sock = recv sock 1024 `shouldReturn` lazyTestMsg | ||
client sock = sendAll sock lazyTestMsg | ||
tcpTest client server | ||
|
||
it "throws when closed" $ do | ||
let server _ = return () | ||
client sock = do | ||
close sock | ||
sendAll sock lazyTestMsg `shouldThrow` anyException | ||
tcpTest client server | ||
|
||
describe "getContents" $ do | ||
it "works well" $ do | ||
let server sock = getContents sock `shouldReturn` lazyTestMsg | ||
client sock = do | ||
void $ send sock lazyTestMsg | ||
shutdown sock ShutdownSend | ||
tcpTest client server | ||
|
||
it "returns empty string at EOF" $ do | ||
let client s = getContents s `shouldReturn` L.empty | ||
server s = shutdown s ShutdownSend | ||
tcpTest client server | ||
|
||
describe "recv" $ do | ||
it "works well" $ do | ||
let server sock = recv sock 1024 `shouldReturn` lazyTestMsg | ||
client sock = send sock lazyTestMsg | ||
tcpTest client server | ||
|
||
it "throws when closed" $ do | ||
let server sock = do | ||
close sock | ||
recv sock 1024 `shouldThrow` anyException | ||
client sock = send sock lazyTestMsg | ||
tcpTest client server | ||
|
||
it "can treat overflow" $ do | ||
let server sock = do | ||
seg1 <- recv sock (L.length lazyTestMsg - 3) | ||
seg2 <- recv sock 1024 | ||
let msg = L.append seg1 seg2 | ||
msg `shouldBe` lazyTestMsg | ||
client sock = send sock lazyTestMsg | ||
tcpTest client server | ||
|
||
it "returns empty string at EOF" $ do | ||
let client s = recv s 4096 `shouldReturn` L.empty | ||
server s = shutdown s ShutdownSend | ||
tcpTest client server |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is better, thanks! For example:
vs.