hspec-setup (empty) → 0.1.0.0
raw patch · 4 files changed
+107/−0 lines, 4 filesdep +basedep +directorydep +filepathsetup-changed
Dependencies added: base, directory, filepath, process, projectroot
Files
- LICENSE +20/−0
- Setup.hs +2/−0
- hspec-setup.cabal +22/−0
- src/Main.hs +63/−0
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2015 Pedro Tacla Yamada++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hspec-setup.cabal view
@@ -0,0 +1,22 @@+name: hspec-setup+version: 0.1.0.0+synopsis: Add an hspec test-suite in one command+homepage: https://github.com/yamadapc/haskell-hspec-setup+license: MIT+license-file: LICENSE+author: Pedro Tacla Yamada+maintainer: tacla.yamada@gmail.com+copyright: Copyright (c) 2015 Pedro Tacla Yamada+category: Development+build-type: Simple+cabal-version: >=1.10++executable hspec-setup+ main-is: Main.hs+ build-depends: base >=4.8 && <4.9+ , directory+ , filepath+ , process >= 1.2.3.0+ , projectroot+ hs-source-dirs: src+ default-language: Haskell2010
+ src/Main.hs view
@@ -0,0 +1,63 @@+module Main+ where++import Control.Monad+import Data.List+import Data.Monoid+import System.Directory+import System.Directory.ProjectRoot+import System.Exit+import System.FilePath+import System.IO+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)++hspecTestSuite :: String+hspecTestSuite = unlines [ ""+ , "test-suite hspec"+ , " main-is: Spec.hs"+ , " type: exitcode-stdio-1.0"+ , " build-depends: base"+ , " , hspec"+ , " , QuickCheck"+ , " hs-source-dirs: test"+ , " default-language: Haskell2010"+ ]++hspecDiscoveryFile :: String+hspecDiscoveryFile = "{-# OPTIONS_GHC -F -pgmF hspec-discover #-}"++hspecSanitySpec = unlines [ "module SanitySpec where"+ , ""+ , "import Test.Hspec"+ , ""+ , "spec = describe \"when I have tests\" $"+ , " it \"I have sanity\" $ True `shouldBe` True"+ ]++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+ putStrLn "Running tests for the first time..."+ callCommand "stack test"+ return ()