hspec-discover 2.1.3 → 2.1.4
raw patch · 3 files changed
+19/−2 lines, 3 files
Files
- hspec-discover.cabal +1/−1
- src/Run.hs +10/−1
- test/RunSpec.hs +8/−0
hspec-discover.cabal view
@@ -1,5 +1,5 @@ name: hspec-discover-version: 2.1.3+version: 2.1.4 license: MIT license-file: LICENSE copyright: (c) 2012-2014 Simon Hengel
src/Run.hs view
@@ -121,12 +121,21 @@ fileToSpec :: FilePath -> FilePath -> Maybe Spec fileToSpec dir file = case reverse $ splitDirectories file of x:xs -> case stripSuffix "Spec.hs" x <|> stripSuffix "Spec.lhs" x of- Just name | (not . null) name -> Just . Spec (dir </> file) $ (intercalate "." . reverse) (name : xs)+ Just name | isValidModuleName name && all isValidModuleName xs ->+ Just . Spec (dir </> file) $ (intercalate "." . reverse) (name : xs) _ -> Nothing _ -> Nothing where stripSuffix :: Eq a => [a] -> [a] -> Maybe [a] stripSuffix suffix str = reverse <$> stripPrefix (reverse suffix) (reverse str)++-- See `Cabal.Distribution.ModuleName` (http://git.io/bj34)+isValidModuleName :: String -> Bool+isValidModuleName [] = False+isValidModuleName (c:cs) = isUpper c && all isValidModuleChar cs++isValidModuleChar :: Char -> Bool+isValidModuleChar c = isAlphaNum c || c == '_' || c == '\'' getFilesRecursive :: FilePath -> IO [FilePath] getFilesRecursive baseDir = sort <$> go []
test/RunSpec.hs view
@@ -84,6 +84,14 @@ it "returns Nothing for invalid spec name" $ do fileToSpec "" "foo" `shouldBe` Nothing + context "when spec does not have a valid module name" $ do+ it "returns Nothing" $ do+ fileToSpec "" "flycheck_Spec.hs" `shouldBe` Nothing++ context "when any component of a hierarchical module name is not valid"$ do+ it "returns Nothing" $ do+ fileToSpec "" ("Valid" </> "invalid" </>"MiddleNamesSpec.hs") `shouldBe` Nothing+ context "when path has directory component" $ do it "converts path to spec name" $ do let file = "Foo" </> "Bar" </> "BazSpec.hs"