-
Notifications
You must be signed in to change notification settings - Fork 704
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6865 from phadej/create-pipe
Use process createPipe
- Loading branch information
Showing
6 changed files
with
125 additions
and
44 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,56 @@ | ||
module UnitTests.Distribution.Compat.CreatePipe (tests) where | ||
|
||
import Control.Concurrent.Async (async, wait) | ||
import Control.DeepSeq (force) | ||
import Control.Exception (evaluate) | ||
import System.IO (hClose, hGetContents, hPutStr, hSetEncoding, localeEncoding) | ||
import Test.Tasty (TestTree) | ||
import Test.Tasty.HUnit (Assertion, assertEqual, testCase) | ||
|
||
import qualified Data.ByteString as BS | ||
|
||
import Distribution.Compat.CreatePipe | ||
import System.IO (hClose, hGetContents, hPutStr, hSetEncoding, localeEncoding) | ||
import Test.Tasty | ||
import Test.Tasty.HUnit | ||
|
||
tests :: [TestTree] | ||
tests = [testCase "Locale Encoding" case_Locale_Encoding] | ||
tests = | ||
[ testCase "Locale Encoding" case_Locale_Encoding | ||
, testCase "Binary ByteStrings are not affected" case_ByteString | ||
] | ||
|
||
case_Locale_Encoding :: Assertion | ||
case_Locale_Encoding = do | ||
let str = "\0252" | ||
let str = "\0252foobar" | ||
(r, w) <- createPipe | ||
hSetEncoding w localeEncoding | ||
out <- hGetContents r | ||
hPutStr w str | ||
hClose w | ||
hSetEncoding r localeEncoding | ||
|
||
ra <- async $ do | ||
out <- hGetContents r | ||
evaluate (force out) | ||
|
||
wa <- async $ do | ||
hPutStr w str | ||
hClose w | ||
|
||
out <- wait ra | ||
wait wa | ||
|
||
assertEqual "createPipe should support Unicode roundtripping" str out | ||
|
||
case_ByteString :: Assertion | ||
case_ByteString = do | ||
let bs = BS.pack[ 1..255] | ||
(r, w) <- createPipe | ||
|
||
ra <- async $ do | ||
out <- BS.hGetContents r | ||
evaluate (force out) | ||
|
||
wa <- async $ do | ||
BS.hPutStr w bs | ||
hClose w | ||
|
||
out <- wait ra | ||
wait wa | ||
|
||
assertEqual "createPipe should support Unicode roundtripping" bs out |