packages feed

hspec-setup 0.1.0.0 → 0.1.1.0

raw patch · 2 files changed

+32/−9 lines, 2 filesdep ~projectroot

Dependency ranges changed: projectroot

Files

hspec-setup.cabal view
@@ -1,6 +1,10 @@ name:                hspec-setup-version:             0.1.0.0+version:             0.1.1.0 synopsis:            Add an hspec test-suite in one command+description: @hspec-setup@ is a command-line tool for adding an hspec+             test-suite with minimal work. See the+             <https://github.com/yamadapc/haskell-hspec-setup GitHub README>+             for more information. homepage:            https://github.com/yamadapc/haskell-hspec-setup license:             MIT license-file:        LICENSE@@ -11,12 +15,18 @@ build-type:          Simple cabal-version:       >=1.10 +tested-with: GHC >= 7.10++source-repository head+  type: git+  location: git://github.com/yamadapc/haskell-hspec-setup+ executable hspec-setup   main-is:             Main.hs   build-depends:       base >=4.8 && <4.9                      , directory                      , filepath                      , process >= 1.2.3.0-                     , projectroot+                     , projectroot >= 0.2   hs-source-dirs:      src   default-language:    Haskell2010
src/Main.hs view
@@ -12,13 +12,13 @@ import           System.Process  main :: IO ()-main = do-    pr <- getProjectRootCurrent-    fs <- getDirectoryContents pr-    case find ((".cabal" ==) . takeExtension) fs of-        Nothing -> error "Couldn't find your cabal file."-        Just fp -> do-            hspecSetup pr (pr </> fp)+main = getProjectRootCurrent >>= \mpr -> case mpr of+    Nothing -> error "Couldn't find the project root"+    Just pr -> do+        fs <- getDirectoryContents pr+        case find ((".cabal" ==) . takeExtension) fs of+            Nothing -> error "Couldn't find your cabal file."+            Just fp -> hspecSetup pr (pr </> fp)  hspecTestSuite :: String hspecTestSuite = unlines [ ""@@ -35,6 +35,7 @@ hspecDiscoveryFile :: String hspecDiscoveryFile = "{-# OPTIONS_GHC -F -pgmF hspec-discover #-}" +hspecSanitySpec :: String hspecSanitySpec = unlines [ "module SanitySpec where"                           , ""                           , "import Test.Hspec"@@ -46,18 +47,30 @@ hspecSetup :: FilePath -> FilePath -> IO () hspecSetup pr fp = do     c <- getCurrentDirectory+     putStrLn $ "Adding test-suite to " <> makeRelative c fp <> "..."     cabalContents <- readFile fp+     when ("type: exitcode-stdio-1.0" `isInfixOf` cabalContents) $ do         hPutStrLn stderr "File already has test-suite. Exiting..."         exitFailure     appendFile fp hspecTestSuite+     putStrLn "Creating test directory..."     createDirectoryIfMissing False (pr </> "test")+     putStrLn "Creating test/Spec.hs discovery file..."     writeFile (pr </> "test" </> "Spec.hs") hspecDiscoveryFile+     putStrLn "Creating test/SanitySpec.hs..."     writeFile (pr </> "test" </> "SanitySpec.hs") hspecSanitySpec++    stackInited <- doesFileExist (pr </> "stack.yaml")+    unless stackInited $ do+        putStrLn "No `stack.yaml` found. Running `stack init` for you..."+        callCommand "stack init"+     putStrLn "Running tests for the first time..."     callCommand "stack test"+     return ()