sensei 0.6.1 → 0.6.2
raw patch · 3 files changed
+38/−11 lines, 3 files
Files
- sensei.cabal +2/−2
- src/Util.hs +11/−6
- test/UtilSpec.hs +25/−3
sensei.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.5.+-- This file has been generated from package.yaml by hpack version 0.34.7. -- -- see: https://github.com/sol/hpack name: sensei-version: 0.6.1+version: 0.6.2 synopsis: Automatically run Hspec tests on file modifications category: Development homepage: https://github.com/hspec/sensei#readme
src/Util.hs view
@@ -10,6 +10,7 @@ #ifdef TEST , filterGitIgnoredFiles_+, gitCheckIgnoreFeedback , writableByOthers #endif ) where@@ -55,20 +56,24 @@ gitCheckIgnore :: [FilePath] -> IO (Feedback, [FilePath]) gitCheckIgnore files = do (_, ignoredFiles, err) <- readProcessWithExitCode "git" ["check-ignore", "--stdin", "-z"] $ join_ files- return (feedback err, split ignoredFiles)+ return (gitCheckIgnoreFeedback err, split ignoredFiles) where join_ = intercalate "\0" split = map T.unpack . T.split (== '\0') . T.pack- feedback err- | err == "fatal: not a git repository (or any of the parent directories): .git\n" = Just (Cyan, "warning: not a git repository - .gitignore support not available\n")- | err == "" = Nothing- | otherwise = Just (Red, err) +gitCheckIgnoreFeedback :: String -> Feedback+gitCheckIgnoreFeedback err+ | "fatal: not a git repository (or any " `isPrefixOf` err = notGitWarning+ | err == "" = Nothing+ | otherwise = Just (Red, err)+ where+ notGitWarning = Just (Cyan, "warning: not a git repository - .gitignore support not available\n")+ normalizeTypeSignatures :: String -> String normalizeTypeSignatures = normalize . concatMap replace where normalize = \case- xs | "\n :: " `isPrefixOf` xs -> normalizeTypeSignatures (drop 2 xs)+ '\n' : ' ' : ' ' : xs -> normalizeTypeSignatures (' ' : dropWhile (== ' ') xs) x : xs -> x : normalizeTypeSignatures xs [] -> []
test/UtilSpec.hs view
@@ -18,11 +18,14 @@ describe "normalizeTypeSignatures" $ do it "removes newlines from type signatures" $ do- normalizeTypeSignatures "foo\n :: Int" `shouldBe` "foo :: Int"+ let signature = "foo\n :: IO\n Int\n"+ normalizeTypeSignatures signature `shouldBe` "foo :: IO Int\n" it "replaces unicode characters" $ do normalizeTypeSignatures "head ∷ [a] → a" `shouldBe` "head :: [a] -> a" + let gitlessFeedback = Just (Cyan, "warning: not a git repository - .gitignore support not available\n")+ describe "filterGitIgnoredFiles_" $ do around_ inTempDirectory $ do it "discards files that are ignored by git" $ do@@ -32,8 +35,27 @@ context "when used outside of a git repository" $ do it "returns all files" $ do- let feedback = Just (Cyan, "warning: not a git repository - .gitignore support not available\n")- filterGitIgnoredFiles_ ["foo", "bar"] `shouldReturn` (feedback, ["foo", "bar"])+ filterGitIgnoredFiles_ ["foo", "bar"] `shouldReturn` (gitlessFeedback, ["foo", "bar"])++ describe "gitCheckIgnoreFeedback" $ do+ context "when git reports no repository" $ do+ it "returns gitless warning" $ do+ let err = "fatal: not a git repository (or any of the parent directories): .git\n"+ gitCheckIgnoreFeedback err `shouldBe` gitlessFeedback++ context "when git stops at a filesystem boundary" $ do+ it "returns gitless warning" $ do+ let err = "fatal: not a git repository (or any parent up to mount point /)\nStopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).\n"+ gitCheckIgnoreFeedback err `shouldBe` gitlessFeedback++ context "when git reports no error" $ do+ it "returns Nothing" $ do+ gitCheckIgnoreFeedback "" `shouldBe` Nothing++ context "when git reports any other error" $ do+ it "returns the error" $ do+ let err = "fatal: Unable to do such and such"+ gitCheckIgnoreFeedback err `shouldBe` Just (Red, err) describe "dotGhciWritableByOthers" $ do around_ inTempDirectory $ do