Skip to content

Commit 7e962d2

Browse files
jorisdralwenkokke
authored andcommitted
fs-sim utils for filtering Errors
1 parent 5f0cf15 commit 7e962d2

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

test/Test/Database/LSMTree/StateMachine.hs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ import qualified System.FS.Sim.Error as FSSim
117117
import System.FS.Sim.Error (Errors)
118118
import qualified System.FS.Sim.MockFS as MockFS
119119
import System.FS.Sim.MockFS (MockFS)
120-
import qualified System.FS.Sim.Stream as Stream
121120
import System.FS.Sim.Stream (Stream)
122121
import System.IO.Temp (createTempDirectory,
123122
getCanonicalTemporaryDirectory)
@@ -135,8 +134,8 @@ import qualified Test.QuickCheck.StateModel.Lockstep.Defaults as Lockstep.Defaul
135134
import qualified Test.QuickCheck.StateModel.Lockstep.Run as Lockstep.Run
136135
import Test.Tasty (TestTree, testGroup)
137136
import Test.Tasty.QuickCheck (testProperty)
138-
import Test.Util.FS (approximateEqStream, propNoOpenHandles,
139-
propNumOpenHandles)
137+
import Test.Util.FS (approximateEqStream, noRemoveDirectoryRecursiveE,
138+
propNoOpenHandles, propNumOpenHandles)
140139
import Test.Util.PrettyProxy
141140
import Test.Util.QLS
142141
import Test.Util.TypeFamilyWrappers (WrapBlob (..), WrapBlobRef (..),
@@ -1435,13 +1434,7 @@ arbitraryActionWithVars _ label ctx (ModelState st _stats) =
14351434
++ [ (1, fmap Some $ OpenSnapshot @k @v @b PrettyProxy <$>
14361435
genErrors <*> pure label <*> genUsedSnapshotName)
14371436
| not (null usedSnapshotNames)
1438-
, let genErrors = do
1439-
merrs <- QC.arbitrary
1440-
case merrs of
1441-
Nothing -> pure Nothing
1442-
Just errs -> pure . Just $ errs {
1443-
FSSim.removeDirectoryRecursiveE = Stream.empty
1444-
}
1437+
, let genErrors = fmap noRemoveDirectoryRecursiveE <$> QC.arbitrary
14451438
]
14461439

14471440
++ [ (1, fmap Some $ DeleteSnapshot <$> genUsedSnapshotName)

test/Test/Util/FS.hs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ module Test.Util.FS (
3232
-- * Corruption
3333
, flipFileBit
3434
, hFlipBit
35+
-- * Errors
36+
, noHCloseE
37+
, noRemoveFileE
38+
, noRemoveDirectoryRecursiveE
3539
-- * Arbitrary
3640
, FsPathComponent (..)
3741
, fsPathComponentFsPath
@@ -373,6 +377,19 @@ hFlipBit hfs h bitOffset = do
373377
void $ hPutBufExactlyAt hfs h buf bufOff count off
374378

375379

380+
{-------------------------------------------------------------------------------
381+
Errors
382+
-------------------------------------------------------------------------------}
383+
384+
noHCloseE :: Errors -> Errors
385+
noHCloseE errs = errs { hCloseE = Stream.empty }
386+
387+
noRemoveFileE :: Errors -> Errors
388+
noRemoveFileE errs = errs { removeFileE = Stream.empty }
389+
390+
noRemoveDirectoryRecursiveE :: Errors -> Errors
391+
noRemoveDirectoryRecursiveE errs = errs { removeDirectoryRecursiveE = Stream.empty }
392+
376393
{-------------------------------------------------------------------------------
377394
Arbitrary
378395
-------------------------------------------------------------------------------}
@@ -415,10 +432,11 @@ newtype NoCleanupErrors = NoCleanupErrors Errors
415432
deriving stock Show
416433

417434
mkNoCleanupErrors :: Errors -> NoCleanupErrors
418-
mkNoCleanupErrors errs = NoCleanupErrors $ errs {
419-
hCloseE = Stream.empty
420-
, removeFileE = Stream.empty
421-
}
435+
mkNoCleanupErrors errs = NoCleanupErrors $
436+
noHCloseE
437+
$ noRemoveFileE
438+
$ noRemoveDirectoryRecursiveE
439+
$ errs
422440

423441
instance Arbitrary NoCleanupErrors where
424442
arbitrary = do

0 commit comments

Comments
 (0)