import Data.Functor.Identity (Identity (Identity)) import qualified Data.Map.Strict as M import Data.Monoid (mempty) import Data.Traversable (for) import System.IO.Error (isDoesNotExistError) import Test.Hspec import Test.Hspec.QuickCheck import Test.QuickCheck import Test.FileSystem.Fake main :: IO () main = hspec $ describe "Test.FileSystem.Fake" $ do let mhs = simplestMetaHandlers :: SimplestMetaHandlers String describe "readFileT and writeFileT" $ prop "written files are read as written" $ \(NonEmpty pathAndContents) -> do let action = for pathAndContents $ \(path, contents) -> do writeFileT path contents readFileT path runFileSystemM mhs mempty action `shouldBe` (M.map Identity $ M.fromList pathAndContents, Right $ map snd pathAndContents) describe "readFileT" $ prop "always throws a DoesNotExist error given empty file system" $ \path -> do let action = readFileT path (afterRun, Left err) = runFileSystemM mhs mempty action afterRun `shouldBe` mempty err `shouldSatisfy` isDoesNotExistError