spy 0.5 → 0.6
raw patch · 4 files changed
+32/−9 lines, 4 files
Files
- spy.cabal +1/−1
- src/Main.hs +3/−3
- src/Spy/Watcher.hs +6/−3
- tests/Tests.hs +22/−2
spy.cabal view
@@ -1,5 +1,5 @@ name: spy-version: 0.5+version: 0.6 license: BSD3 license-file: LICENSE author: Stefan Saasen
src/Main.hs view
@@ -3,10 +3,11 @@ import System.Console.CmdArgs import System.Directory (canonicalizePath)+import System.FilePath (addTrailingPathSeparator) import Spy.Watcher version :: String-version = "spy v0.5, (C) Stefan Saasen"+version = "spy v0.6, (C) Stefan Saasen" hiddenOpts x = x &= help "Set to true if hidden files/directories should be included" &= name "i" &= typ "BOOL" @@ -41,6 +42,5 @@ main = do config <- cmdArgsRun mode canonicalizedDir <- canonicalizePath $ dir config- spy config { dir = canonicalizedDir }+ spy config { dir = addTrailingPathSeparator canonicalizedDir } putStrLn "No eyes on the target"-
src/Spy/Watcher.hs view
@@ -18,9 +18,10 @@ import System.IO (stderr, hPrint) import System.FilePath.GlobPattern import System.FilePath (splitDirectories, takeFileName)-import Filesystem.Path.CurrentOS (encodeString, decodeString)+import Filesystem.Path.CurrentOS+ (encodeString, decodeString, commonPrefix, stripPrefix) import Data.Time.Clock(UTCTime)-import Data.Maybe (fromMaybe, maybeToList)+import Data.Maybe (fromMaybe, maybeToList, fromJust) import Text.JSON -- | The output format when Spy prints out changes to STDOUT@@ -92,8 +93,10 @@ skipEvent :: Spy -> FilePath -> Bool skipEvent config path = skipHidden || skipNonMatchingGlob where skipHidden = let includeHiddenfiles = hidden config- in not includeHiddenfiles && containsHiddenPathElement path+ in not includeHiddenfiles && containsHiddenPathElement relPath skipNonMatchingGlob = maybe False (not . matchesFile path) $ glob config+ relPath = encodeString . fromJust $ stripPrefix prefix (decodeString path)+ prefix = commonPrefix (map decodeString [dir config, path]) eventTime :: Event -> UTCTime eventTime (Added _ t) = t
tests/Tests.hs view
@@ -23,13 +23,29 @@ "Skip path if hidden directory and showing hidden files is not enabled" (skipEvent (mockWatch {hidden = False}) "/a/b/.git/refs") +test_dontSkipEventOnMatchingGlob = H.assertBool+ "Don't skip path if the glob matches"+ (not $ skipEvent (mockWatch {glob = Just "*.hs"}) "/a/b/Main.hs")++test_skipEventOnMatchingGlob = H.assertBool+ "Skip path if the glob pattern doesn't match the file path"+ (skipEvent (mockWatch {glob = Just "*.hs"}) "/a/b/Main.sh")+ test_containsHiddenPathElement = H.assertBool "Should identify hidden directory" (containsHiddenPathElement "/a/b/.git/info/exclude") +test_containsHiddenPathElementFirst = H.assertBool+ "Should identify hidden directory"+ (containsHiddenPathElement ".git/info/exclude")++test_containsNoHiddenPathElement = H.assertBool+ "Should not identify hidden directory"+ (not $ containsHiddenPathElement "info/exclude")+ -- =========================================================== mockWatch :: Spy-mockWatch = Watch { dir = ".", glob = Nothing, format = Nothing, hidden = False }+mockWatch = Watch { dir = "foo/bar", glob = Nothing, format = Nothing, hidden = False } -- =========================================================== -- Test harness@@ -47,7 +63,11 @@ testGroup "Watcher opts" [ testCase "watcher/optHidden" test_skipEventHidden,- testCase "watcher/containsHiddenPathElement" test_containsHiddenPathElement+ testCase "watcher/dontSkipEventOnMatchingGlob" test_dontSkipEventOnMatchingGlob,+ testCase "watcher/skipEventOnMatchingGlob" test_skipEventOnMatchingGlob,+ testCase "watcher/containsHiddenPathElement" test_containsHiddenPathElement,+ testCase "watcher/containsHiddenPathElementFirst" test_containsHiddenPathElementFirst,+ testCase "watcher/containsNoHiddenPathElement" test_containsNoHiddenPathElement ] ]