diff --git a/CHANGELOG.md b/CHANGELOG.md index 959caf5..159227d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ To be released. - The officially distributed executable binaries for Linux became dependent on [glibc]. + - Fixed a bug that it had failed to scan if any file in a change set is + deleted. + [glibc]: https://www.gnu.org/software/libc/ diff --git a/src/Checkmate/Discover.hs b/src/Checkmate/Discover.hs index a2cf4c8..849cca6 100644 --- a/src/Checkmate/Discover.hs +++ b/src/Checkmate/Discover.hs @@ -6,6 +6,8 @@ module Checkmate.Discover , parseDiff ) where +import System.IO.Error + import Control.Monad.Parallel as P import Data.Range.Range as Range import Data.Set as S @@ -69,7 +71,10 @@ discoverFile _ FileDelta { fileDeltaContent = Binary } = return S.empty discoverFile baseDirPath FileDelta { fileDeltaContent = Hunks hunks , fileDeltaDestFile = filePathT } = do - result <- parseSourceFile filePath + result <- catchIOError (parseSourceFile filePath) $ \ e -> + if isDoesNotExistError e + then return $ Right S.empty + else ioError e return $ case result of Left _ -> S.empty Right checklist -> fromList diff --git a/test/Checkmate/DiscoverSpec.hs b/test/Checkmate/DiscoverSpec.hs index c36a48d..95b22ab 100644 --- a/test/Checkmate/DiscoverSpec.hs +++ b/test/Checkmate/DiscoverSpec.hs @@ -112,9 +112,12 @@ jsChecklistFixture d = jsPath :: FilePath jsPath = d "subdir" "inner_sample.js" +withTempDir :: (FilePath -> IO a) -> IO a +withTempDir = withSystemTempDirectory "checkmate-test" + withFixtureDir :: (FilePath -> IO a) -> IO a withFixtureDir action = - withSystemTempDirectory "checkmate-test" $ \ dirPath -> do + withTempDir $ \ dirPath -> do forM_ fixtures $ \ (filePath, contents) -> do let path = dirPath filePath parent = takeDirectory path @@ -125,22 +128,39 @@ withFixtureDir action = spec :: Spec spec = do - specify "discover" $ - withFixtureDir $ \ dirPath -> do - checklist <- discover dirPath diffFixture - let expected = subdirChecklistFixture dirPath - `union` pyChecklistFixture dirPath - `union` jsChecklistFixture dirPath - checklist `shouldBe` expected - specify "discoverDirectory" $ - withFixtureDir $ \ dirPath -> do - subdirChecks <- discoverDirectory dirPath "subdir" - subdirChecks `shouldBe` subdirChecklistFixture dirPath - rootChecks <- discoverDirectory dirPath "." - rootChecks `shouldBe` rootChecklistFixture dirPath - specify "discoverFile" $ - withFixtureDir $ \ dirPath -> do - pyChecks <- discoverFile dirPath $ Prelude.head diffFixture - pyChecks `shouldBe` pyChecklistFixture dirPath - jsChecks <- discoverFile dirPath $ Prelude.last diffFixture - jsChecks `shouldBe` jsChecklistFixture dirPath + describe "discover" $ do + it "scans all relative checks" $ + withFixtureDir $ \ dirPath -> do + checklist <- discover dirPath diffFixture + let expected = subdirChecklistFixture dirPath + `union` pyChecklistFixture dirPath + `union` jsChecklistFixture dirPath + checklist `shouldBe` expected + it "ignores files/directories that do not exist" $ + withTempDir $ \ dirPath -> do + checklist <- discover dirPath diffFixture + checklist `shouldBe` [] + describe "discoverDirectory" $ do + it "lists files in the given path" $ + withFixtureDir $ \ dirPath -> do + subdirChecks <- discoverDirectory dirPath "subdir" + subdirChecks `shouldBe` subdirChecklistFixture dirPath + rootChecks <- discoverDirectory dirPath "." + rootChecks `shouldBe` rootChecklistFixture dirPath + it "ignores files/directories that do not exist" $ + withTempDir $ \ dirPath -> do + checks <- discoverDirectory + (dirPath "dir-do-not-exist") + "dir-do-not-exist" + checks `shouldBe` [] + describe "discoverFile" $ do + it "scans all relative checks" $ + withFixtureDir $ \ dirPath -> do + pyChecks <- discoverFile dirPath $ Prelude.head diffFixture + pyChecks `shouldBe` pyChecklistFixture dirPath + jsChecks <- discoverFile dirPath $ Prelude.last diffFixture + jsChecks `shouldBe` jsChecklistFixture dirPath + it "ignores files/directories that do not exist" $ + withTempDir $ \ dirPath -> do + checklist <- discoverFile dirPath $ Prelude.head diffFixture + checklist `shouldBe` []