on master help sign in
Test buffering
e20e07eBryan O'Sullivan
tests/Properties.hs+19−9
@@ -626,6 +626,13 @@ instance Arbitrary NewlineMode where
626 [ noNewlineTranslation, universalNewlineMode, nativeNewlineMode,
626 [ noNewlineTranslation, universalNewlineMode, nativeNewlineMode,
627 windowsNewlineMode ]
627 windowsNewlineMode ]
628
628
629+instance Arbitrary BufferMode where
630+ arbitrary = oneof [ return NoBuffering,
631+ return LineBuffering,
632+ return (BlockBuffering Nothing),
633+ (BlockBuffering . Just . fromIntegral) `fmap` arb16 ]
634+ where arb16 = arbitrary :: Gen Word16
635+
629-- This test harness is complex! What property are we checking?
636-- This test harness is complex! What property are we checking?
630--
637--
631-- Reading after writing a multi-line file should give the same
638-- Reading after writing a multi-line file should give the same
@@ -637,17 +644,20 @@ instance Arbitrary NewlineMode where
637-- sometimes contain line endings.)
644-- sometimes contain line endings.)
638-- * Encoding.
645-- * Encoding.
639-- * Newline translation mode.
646-- * Newline translation mode.
647+-- * Buffering.
640−write_read unline filt writer reader (E _ e) m ts =
648+write_read unline filt writer reader (E _ enc) nl buf ts =
641 monadicIO $ assert . (==t) =<< run act
649 monadicIO $ assert . (==t) =<< run act
642 where t = unline . map (filt (not . (`elem` "\r\n"))) $ ts
650 where t = unline . map (filt (not . (`elem` "\r\n"))) $ ts
643 act = withTempFile $ \path h -> do
651 act = withTempFile $ \path h -> do
644− hSetEncoding h e
652+ hSetEncoding h enc
645− hSetNewlineMode h m
653+ hSetNewlineMode h nl
654+ hSetBuffering h buf
646 () <- writer h t
655 () <- writer h t
647 hClose h
656 hClose h
648 bracket (openFile path ReadMode) hClose $ \h' -> do
657 bracket (openFile path ReadMode) hClose $ \h' -> do
649− hSetEncoding h' e
658+ hSetEncoding h' enc
650− hSetNewlineMode h' m
659+ hSetNewlineMode h' nl
660+ hSetBuffering h' buf
651 r <- reader h'
661 r <- reader h'
652 r `deepseq` return r
662 r `deepseq` return r
653
663
@@ -660,10 +670,10 @@ tl_put_get = write_read TL.unlines TL.filter put get
660t_write_read = write_read T.unlines T.filter T.hPutStr T.hGetContents
670t_write_read = write_read T.unlines T.filter T.hPutStr T.hGetContents
661tl_write_read = write_read TL.unlines TL.filter TL.hPutStr TL.hGetContents
671tl_write_read = write_read TL.unlines TL.filter TL.hPutStr TL.hGetContents
662
672
663−t_write_read_line e m t = write_read head T.filter T.hPutStrLn
673+t_write_read_line e m b t = write_read head T.filter T.hPutStrLn
664− T.hGetLine e m [t]
674+ T.hGetLine e m b [t]
665−tl_write_read_line e m t = write_read head TL.filter TL.hPutStrLn
675+tl_write_read_line e m b t = write_read head TL.filter TL.hPutStrLn
666− TL.hGetLine e m [t]
676+ TL.hGetLine e m b [t]
667
677
668-- Low-level.
678-- Low-level.
669
679