[commit: bytestring] master: Make the testHandlePutBuilder conditional and add char8 version (023e95f)
Ian Lynagh
igloo at earth.li
Wed Feb 22 21:58:34 CET 2012
Repository : ssh://darcs.haskell.org//srv/darcs/packages/bytestring
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/023e95ff9dac7d0ac30b6e8c8d8d2cff744b366f
>---------------------------------------------------------------
commit 023e95ff9dac7d0ac30b6e8c8d8d2cff744b366f
Author: Duncan Coutts <duncan at community.haskell.org>
Date: Wed Nov 16 23:29:20 2011 +0000
Make the testHandlePutBuilder conditional and add char8 version
The testHandlePutBuilder does not apply to older ghc with the pre-Unicode
Handles. Extra char8 test covers old ghc and should work with new too.
>---------------------------------------------------------------
.../builder/Data/ByteString/Lazy/Builder/Tests.hs | 41 ++++++++++++++++++++
1 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/tests/builder/Data/ByteString/Lazy/Builder/Tests.hs b/tests/builder/Data/ByteString/Lazy/Builder/Tests.hs
index 04fd7e7..2b6e67a 100644
--- a/tests/builder/Data/ByteString/Lazy/Builder/Tests.hs
+++ b/tests/builder/Data/ByteString/Lazy/Builder/Tests.hs
@@ -51,7 +51,10 @@ import Test.QuickCheck.Property (printTestCase)
tests :: [Test]
tests =
[ testBuilderRecipe
+#if MIN_VERSION_base(4,2,0)
, testHandlePutBuilder
+#endif
+ , testHandlePutBuilderChar8
, testPut
] ++
testsEncodingToBuilder ++
@@ -82,6 +85,7 @@ testBuilderRecipe =
, "diff : " ++ show (dropWhile (uncurry (==)) $ zip x1 x2)
]
+#if MIN_VERSION_base(4,2,0)
testHandlePutBuilder :: Test
testHandlePutBuilder =
testProperty "hPutBuilder" testRecipe
@@ -117,6 +121,43 @@ testHandlePutBuilder =
success = lbs == lbsRef
unless success (error msg)
return success
+#endif
+
+testHandlePutBuilderChar8 :: Test
+testHandlePutBuilderChar8 =
+ testProperty "char8 hPutBuilder" testRecipe
+ where
+ testRecipe :: (String, String, String, Recipe) -> Bool
+ testRecipe args@(before, between, after, recipe) = unsafePerformIO $ do
+ tempDir <- getTemporaryDirectory
+ (tempFile, tempH) <- openTempFile tempDir "TestBuilder"
+ -- switch to binary / latin1 encoding
+ hSetBinaryMode tempH True
+ -- output recipe with intermediate direct writing to handle
+ let b = fst $ recipeComponents recipe
+ hPutStr tempH before
+ hPutBuilder tempH b
+ hPutStr tempH between
+ hPutBuilder tempH b
+ hPutStr tempH after
+ hClose tempH
+ -- read file
+ lbs <- L.readFile tempFile
+ _ <- evaluate (L.length $ lbs)
+ removeFile tempFile
+ -- compare to pure builder implementation
+ let lbsRef = toLazyByteString $ mconcat
+ [string8 before, b, string8 between, b, string8 after]
+ -- report
+ let msg = unlines
+ [ "task: " ++ show args
+ , "via file: " ++ show lbs
+ , "direct : " ++ show lbsRef
+ -- , "diff : " ++ show (dropWhile (uncurry (==)) $ zip x1 x2)
+ ]
+ success = lbs == lbsRef
+ unless success (error msg)
+ return success
-- Recipes with which to test the builder functions
More information about the Cvs-libraries
mailing list