From d3d73db15317ad8a68abf38ef0e74d840f5d5af2 Mon Sep 17 00:00:00 2001 From: Bodigrim Date: Wed, 8 Sep 2021 19:04:49 +0100 Subject: [PATCH] Work around when getFileSystemEncoding is ASCII --- tests/Properties/ByteString.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/Properties/ByteString.hs b/tests/Properties/ByteString.hs index c014cb02a..b7189ca1d 100644 --- a/tests/Properties/ByteString.hs +++ b/tests/Properties/ByteString.hs @@ -23,6 +23,7 @@ #ifndef BYTESTRING_LAZY module Properties.ByteString (tests) where import qualified Data.ByteString as B +import GHC.IO.Encoding #else module Properties.ByteStringLazy (tests) where import qualified Data.ByteString.Lazy as B @@ -83,10 +84,16 @@ tests = \x -> ioProperty $ do r <- B.toFilePath x >>= B.fromFilePath pure (r === x) - , testProperty "fromFilePath >>= toFilePath" $ - \x -> ioProperty $ do - r <- B.fromFilePath x >>= B.toFilePath - pure (r === x) + , testProperty "fromFilePath >>= toFilePath" $ ioProperty $ do + let prop x = ioProperty $ do + r <- B.fromFilePath x >>= B.toFilePath + pure (r === x) + -- Normally getFileSystemEncoding returns one of Unicode encodings, + -- but if it is ASCII, we should not generate Unicode filenames. + enc <- getFileSystemEncoding + pure $ case textEncodingName enc of + "ASCII" -> property (prop . getASCIIString) + _ -> property prop #endif #endif