tests: limit the size of list for OutputName, StorePath name generators

This commit is contained in:
sorki 2023-12-05 17:03:12 +01:00
parent 72de93d260
commit 225b4d3f5a
2 changed files with 14 additions and 8 deletions

View File

@ -6,14 +6,17 @@ import System.Nix.OutputName (OutputName)
import qualified Data.Text
import qualified System.Nix.OutputName
import Test.QuickCheck (Arbitrary(arbitrary), elements, listOf)
import Test.QuickCheck (Arbitrary(arbitrary), choose, elements, vectorOf)
instance Arbitrary OutputName where
arbitrary =
either (error . show) id
. System.Nix.OutputName.mkOutputName
. Data.Text.pack <$> ((:) <$> s1 <*> listOf sn)
. Data.Text.pack <$> ((:) <$> s1 <*> limited sn)
where
alphanum = ['a' .. 'z'] <> ['A' .. 'Z'] <> ['0' .. '9']
s1 = elements $ alphanum <> "+-_?="
sn = elements $ alphanum <> "+-._?="
s1 = elements $ alphanum <> "+-_?="
sn = elements $ alphanum <> "+-._?="
limited n = do
k <- choose (0, 210)
vectorOf k n

View File

@ -15,7 +15,7 @@ import System.Nix.StorePath (StoreDir(..)
)
import qualified System.Nix.StorePath
import Test.QuickCheck (Arbitrary(arbitrary), elements, listOf, oneof)
import Test.QuickCheck (Arbitrary(arbitrary), choose, elements, oneof, vectorOf)
instance Arbitrary StoreDir where
arbitrary =
@ -33,11 +33,14 @@ instance Arbitrary StorePathName where
arbitrary =
either undefined id
. System.Nix.StorePath.mkStorePathName
. Data.Text.pack <$> ((:) <$> s1 <*> listOf sn)
. Data.Text.pack <$> ((:) <$> s1 <*> limited sn)
where
alphanum = ['a' .. 'z'] <> ['A' .. 'Z'] <> ['0' .. '9']
s1 = elements $ alphanum <> "+-_?="
sn = elements $ alphanum <> "+-._?="
s1 = elements $ alphanum <> "+-_?="
sn = elements $ alphanum <> "+-._?="
limited n = do
k <- choose (0, 210)
vectorOf k n
instance Arbitrary StorePathHashPart where
arbitrary =