2022-09-08 23:01:16 +03:00
|
|
|
```ucm:hide
|
|
|
|
.> builtins.mergeio
|
|
|
|
```
|
|
|
|
|
|
|
|
```unison
|
|
|
|
directory = "unison-src/transcripts-using-base/serialized-cases/"
|
|
|
|
|
|
|
|
availableCases : '{IO,Exception} [Text]
|
|
|
|
availableCases _ =
|
|
|
|
l = filter (contains ".ser") (directoryContents directory)
|
|
|
|
map (t -> Text.take (drop (Text.size t) 4) t) l
|
|
|
|
|
|
|
|
gen : Nat -> Nat -> (Nat, Nat)
|
|
|
|
gen seed k =
|
|
|
|
c = 1442695040888963407
|
|
|
|
a = 6364136223846793005
|
|
|
|
(mod seed k, a * seed + c)
|
|
|
|
|
|
|
|
shuffle : Nat -> [a] -> [a]
|
|
|
|
shuffle =
|
|
|
|
pick acc seed = cases
|
|
|
|
l | lteq (List.size l) 1 -> acc ++ l
|
2022-09-12 17:11:27 +03:00
|
|
|
| otherwise -> match gen seed (size l) with
|
2022-09-08 23:01:16 +03:00
|
|
|
(k, seed) -> match (take k l, drop k l) with
|
|
|
|
(pre, x +: post) -> pick (acc :+ x) seed (pre ++ post)
|
2023-01-13 18:16:07 +03:00
|
|
|
(pre, []) -> pick acc seed pre
|
2022-09-08 23:01:16 +03:00
|
|
|
|
|
|
|
pick []
|
|
|
|
|
2022-09-13 00:45:54 +03:00
|
|
|
runTestCase : Text ->{Exception,IO} (Text, Test.Result)
|
2022-09-08 23:01:16 +03:00
|
|
|
runTestCase name =
|
|
|
|
sfile = directory ++ name ++ ".ser"
|
2023-09-08 19:54:22 +03:00
|
|
|
lsfile = directory ++ name ++ ".lser"
|
2022-09-08 23:01:16 +03:00
|
|
|
ofile = directory ++ name ++ ".out"
|
|
|
|
hfile = directory ++ name ++ ".hash"
|
|
|
|
|
|
|
|
p@(f, i) = loadSelfContained sfile
|
2023-09-08 19:54:22 +03:00
|
|
|
pl@(fl, il) = loadSelfContained lsfile
|
2022-09-08 23:01:16 +03:00
|
|
|
o = fromUtf8 (readFile ofile)
|
|
|
|
h = readFile hfile
|
|
|
|
|
2022-09-13 00:45:54 +03:00
|
|
|
result =
|
2023-09-08 19:54:22 +03:00
|
|
|
if not (f i == o)
|
|
|
|
then Fail (name ++ " output mismatch")
|
|
|
|
else if not (toBase32 (crypto.hash Sha3_512 p) == h)
|
|
|
|
then Fail (name ++ " hash mismatch")
|
|
|
|
else if not (fl il == f i)
|
|
|
|
then Fail (name ++ " legacy mismatch")
|
|
|
|
else Ok name
|
2022-09-13 00:45:54 +03:00
|
|
|
(name, result)
|
2022-09-08 23:01:16 +03:00
|
|
|
|
|
|
|
serialTests : '{IO,Exception} [Test.Result]
|
|
|
|
serialTests = do
|
|
|
|
l = !availableCases
|
|
|
|
cs = shuffle (toRepresentation !systemTimeMicroseconds) l
|
2022-09-13 00:45:54 +03:00
|
|
|
List.map snd (bSort (List.map runTestCase cs))
|
2022-09-08 23:01:16 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```ucm
|
|
|
|
.> add
|
|
|
|
.> io.test serialTests
|
|
|
|
```
|