different way to avoid NUL in Arbitrary AssociatedFile

Test case has been intermittently failing, with an AssociatedFile that
somehow contains a NUL despite it being filtered out. My guess is
something to do with locales. This new approach should prevent any NUL
at all, although it does weigh the distribution a bit more toward
Nothing.
This commit is contained in:
Joey Hess 2019-12-30 12:27:45 -04:00
parent 6d10fecff4
commit 70395659db
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

5
Key.hs
View file

@ -81,10 +81,9 @@ instance Arbitrary KeyData where
-- AssociatedFile cannot be empty, and cannot contain a NUL
-- (but can be Nothing)
instance Arbitrary AssociatedFile where
arbitrary = (AssociatedFile . fmap mk <$> arbitrary)
arbitrary = (AssociatedFile . fmap toRawFilePath <$> arbitrary)
`suchThat` (/= AssociatedFile (Just S.empty))
where
mk = toRawFilePath . filter (/= '\NUL')
`suchThat` (\(AssociatedFile f) -> maybe True (S.notElem 0) f)
instance Arbitrary Key where
arbitrary = mkKey . const <$> arbitrary