Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor cache test code
  • Loading branch information
EMattfolk committed Jan 28, 2023
commit 2ad7cd7760bedd7c34a564e227a49f65a1952d1a
35 changes: 7 additions & 28 deletions tests/TestMake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -204,71 +204,50 @@ spec = do
writeFileWithTimestamp modulePath timestampA "module Module where\nfoo = 0\n"
compile [modulePath] `shouldReturn` moduleNames ["Module"]

cache <- readCacheDb
if M.keysSet cache == moduleNames ["Module"]
then return ()
else fail "Module not in cacheDb"
M.keysSet <$> readCacheDb `shouldReturn` moduleNames ["Module"]

it "removes old entry from cache when module is renamed" $ do
let modulePath = sourcesDir </> "Module.purs"

writeFileWithTimestamp modulePath timestampA "module Module where\nfoo = 0\n"
compile [modulePath] `shouldReturn` moduleNames ["Module"]

cache1 <- readCacheDb
if M.keysSet cache1 == moduleNames ["Module"]
then return ()
else fail "Module not in cacheDb"
M.keysSet <$> readCacheDb `shouldReturn` moduleNames ["Module"]

writeFileWithTimestamp modulePath timestampA "module Module2 where\nfoo = 0\n"
compile [modulePath] `shouldReturn` moduleNames ["Module2"]

cache2 <- readCacheDb
if M.keysSet cache2 == moduleNames ["Module2"]
then return ()
else fail "Module2 not in cacheDb"
M.keysSet <$> readCacheDb `shouldReturn` moduleNames ["Module2"]

it "removes old entry from cache when file and module is renamed" $ do
let modulePath1 = sourcesDir </> "Module1.purs"

writeFileWithTimestamp modulePath1 timestampA "module Module1 where\nfoo = 0\n"
compile [modulePath1] `shouldReturn` moduleNames ["Module1"]

cache1 <- readCacheDb
if M.keysSet cache1 == moduleNames ["Module1"]
then return ()
else fail "Module1 not in cacheDb"
M.keysSet <$> readCacheDb `shouldReturn` moduleNames ["Module1"]

removeFile modulePath1
let modulePath2 = sourcesDir </> "Module2.purs"

writeFileWithTimestamp modulePath2 timestampA "module Module2 where\nfoo = 0\n"
compile [modulePath2] `shouldReturn` moduleNames ["Module2"]

cache2 <- readCacheDb
if M.keysSet cache2 == moduleNames ["Module2"]
then return ()
else fail "Module2 not in cacheDb"
M.keysSet <$> readCacheDb `shouldReturn` moduleNames ["Module2"]

it "removes old entry from cache when file is deleted" $ do
let modulePath = sourcesDir </> "Module.purs"

writeFileWithTimestamp modulePath timestampA "module Module where\nfoo = 0\n"
compile [modulePath] `shouldReturn` moduleNames ["Module"]

cache1 <- readCacheDb
if M.keysSet cache1 == moduleNames ["Module"]
then return ()
else fail "Module not in cacheDb"
M.keysSet <$> readCacheDb `shouldReturn` moduleNames ["Module"]

removeFile modulePath

compile [] `shouldReturn` moduleNames []

cache2 <- readCacheDb
if M.null cache2
then return ()
else fail "Modules were not removed from cacheDb"
M.keysSet <$> readCacheDb `shouldReturn` moduleNames []

-- Note [Sleeping to avoid flaky tests]
--
Expand Down