Skip to content

Commit

Permalink
Ignore deleted source files
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed May 15, 2018
1 parent b548e08 commit 1896db2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/


Expand Down
7 changes: 6 additions & 1 deletion src/Checkmate/Discover.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
60 changes: 40 additions & 20 deletions test/Checkmate/DiscoverSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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` []

0 comments on commit 1896db2

Please sign in to comment.