fix test suite fail in LANG=C
This was caused by 23e9d3bb77
an Arbitrary String is not necessarily encoded using the filesystem
encoding, and in a non-utf8 locale, encodeBS throws an exception on such a
string. All I could think to do is limit test data to ascii.
This shouldn't be a problem in practice, because the all Strings in
git-annex that are not generated by Arbitrary should be loaded in a way
that does apply the filesystem encoding.
This commit is contained in:
parent
f7b57c5f6b
commit
4e4e11849a
3 changed files with 20 additions and 4 deletions
|
@ -270,10 +270,16 @@ instance Arbitrary MetaData where
|
||||||
legal k _v = legalField $ fromMetaField k
|
legal k _v = legalField $ fromMetaField k
|
||||||
|
|
||||||
instance Arbitrary MetaValue where
|
instance Arbitrary MetaValue where
|
||||||
arbitrary = MetaValue <$> arbitrary <*> arbitrary
|
arbitrary = MetaValue
|
||||||
|
<$> arbitrary
|
||||||
|
-- Avoid non-ascii metavalues because fully arbitrary
|
||||||
|
-- strings may not be encoded using the filesystem
|
||||||
|
-- encoding, which is norally applied to all input.
|
||||||
|
<*> arbitrary `suchThat` all isAscii
|
||||||
|
|
||||||
instance Arbitrary MetaField where
|
instance Arbitrary MetaField where
|
||||||
arbitrary = MetaField . CI.mk <$> arbitrary `suchThat` legalField
|
arbitrary = MetaField . CI.mk
|
||||||
|
<$> arbitrary `suchThat` legalField
|
||||||
|
|
||||||
prop_metadata_sane :: MetaData -> MetaField -> MetaValue -> Bool
|
prop_metadata_sane :: MetaData -> MetaField -> MetaValue -> Bool
|
||||||
prop_metadata_sane m f v = and
|
prop_metadata_sane m f v = and
|
||||||
|
|
|
@ -10,11 +10,13 @@
|
||||||
|
|
||||||
module Utility.Base64 (toB64, fromB64Maybe, fromB64, prop_b64_roundtrips) where
|
module Utility.Base64 (toB64, fromB64Maybe, fromB64, prop_b64_roundtrips) where
|
||||||
|
|
||||||
|
import Utility.FileSystemEncoding
|
||||||
|
|
||||||
import qualified "sandi" Codec.Binary.Base64 as B64
|
import qualified "sandi" Codec.Binary.Base64 as B64
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import Data.ByteString.UTF8 (fromString, toString)
|
import Data.ByteString.UTF8 (fromString, toString)
|
||||||
import Utility.FileSystemEncoding
|
import Data.Char
|
||||||
|
|
||||||
toB64 :: String -> String
|
toB64 :: String -> String
|
||||||
toB64 = toString . B64.encode . L.toStrict . encodeBS
|
toB64 = toString . B64.encode . L.toStrict . encodeBS
|
||||||
|
@ -28,5 +30,9 @@ fromB64 = fromMaybe bad . fromB64Maybe
|
||||||
where
|
where
|
||||||
bad = error "bad base64 encoded data"
|
bad = error "bad base64 encoded data"
|
||||||
|
|
||||||
|
-- Only ascii strings are tested, because an arbitrary string may contain
|
||||||
|
-- characters not encoded using the FileSystemEncoding.
|
||||||
prop_b64_roundtrips :: String -> Bool
|
prop_b64_roundtrips :: String -> Bool
|
||||||
prop_b64_roundtrips s = s == fromB64 (toB64 s)
|
prop_b64_roundtrips s
|
||||||
|
| all (isAscii) s = s == fromB64 (toB64 s)
|
||||||
|
| otherwise = True
|
||||||
|
|
|
@ -68,6 +68,10 @@ withFilePath fp f = Encoding.getFileSystemEncoding
|
||||||
- only allows doing this conversion with CStrings, and the CString buffer
|
- only allows doing this conversion with CStrings, and the CString buffer
|
||||||
- is allocated, used, and deallocated within the call, with no side
|
- is allocated, used, and deallocated within the call, with no side
|
||||||
- effects.
|
- effects.
|
||||||
|
-
|
||||||
|
- If the FilePath contains a value that is not legal in the filesystem
|
||||||
|
- encoding, this may throw an exception. For example, "\226" is not valid
|
||||||
|
- in the C locale, but is in utf locales.
|
||||||
-}
|
-}
|
||||||
{-# NOINLINE _encodeFilePath #-}
|
{-# NOINLINE _encodeFilePath #-}
|
||||||
_encodeFilePath :: FilePath -> String
|
_encodeFilePath :: FilePath -> String
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue