Hello community, here is the log from the commit of package hspec-setup for openSUSE:Factory checked in at 2017-04-14 13:32:23 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/hspec-setup (Old) and /work/SRC/openSUSE:Factory/.hspec-setup.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "hspec-setup" Fri Apr 14 13:32:23 2017 rev:2 rq:477473 version:0.2.1.0 Changes: -------- --- /work/SRC/openSUSE:Factory/hspec-setup/hspec-setup.changes 2017-02-25 00:52:22.539361590 +0100 +++ /work/SRC/openSUSE:Factory/.hspec-setup.new/hspec-setup.changes 2017-04-14 13:32:51.764587775 +0200 @@ -1,0 +2,5 @@ +Fri Feb 24 10:35:16 UTC 2017 - [email protected] + +- Update to version 0.2.1.0 with cabal2obs. + +------------------------------------------------------------------- Old: ---- hspec-setup-0.1.1.1.tar.gz New: ---- hspec-setup-0.2.1.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ hspec-setup.spec ++++++ --- /var/tmp/diff_new_pack.SYdv3q/_old 2017-04-14 13:32:52.432493385 +0200 +++ /var/tmp/diff_new_pack.SYdv3q/_new 2017-04-14 13:32:52.432493385 +0200 @@ -1,7 +1,7 @@ # # spec file for package hspec-setup # -# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -16,39 +16,92 @@ # -Name: hspec-setup -Version: 0.1.1.1 +%global pkg_name hspec-setup +%bcond_with tests +Name: %{pkg_name} +Version: 0.2.1.0 Release: 0 Summary: Add an hspec test-suite in one command License: MIT Group: Development/Languages/Other Url: https://hackage.haskell.org/package/%{name} Source0: https://hackage.haskell.org/package/%{name}-%{version}/%{name}-%{version}.tar.gz +BuildRequires: chrpath BuildRequires: ghc-Cabal-devel +BuildRequires: ghc-ansi-wl-pprint-devel BuildRequires: ghc-directory-devel +BuildRequires: ghc-directory-tree-devel BuildRequires: ghc-filepath-devel +BuildRequires: ghc-haskell-src-exts-devel +BuildRequires: ghc-pretty-devel BuildRequires: ghc-process-devel BuildRequires: ghc-projectroot-devel BuildRequires: ghc-rpm-macros +BuildRequires: ghc-split-devel +BuildRequires: ghc-strict-devel BuildRoot: %{_tmppath}/%{name}-%{version}-build +%if %{with tests} +BuildRequires: ghc-QuickCheck-devel +BuildRequires: ghc-bytestring-devel +BuildRequires: ghc-cryptohash-devel +BuildRequires: ghc-hspec-devel +BuildRequires: ghc-language-dockerfile-devel +%endif %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. +%package -n ghc-%{name} +Summary: Haskell %{name} library +Group: System/Libraries + +%description -n ghc-%{name} +This package provides the Haskell %{name} shared library. + +%package -n ghc-%{name}-devel +Summary: Haskell %{name} library development files +Group: Development/Libraries/Other +Requires: ghc-%{name} = %{version}-%{release} +Requires: ghc-compiler = %{ghc_version} +Requires(post): ghc-compiler = %{ghc_version} +Requires(postun): ghc-compiler = %{ghc_version} + +%description -n ghc-%{name}-devel +This package provides the Haskell %{name} library development files. + %prep %setup -q %build -%ghc_bin_build +%ghc_lib_build %install -%ghc_bin_install +%ghc_lib_install +%ghc_fix_rpath %{pkg_name}-%{version} + +%check +%cabal_test + +%post -n ghc-%{name}-devel +%ghc_pkg_recache + +%postun -n ghc-%{name}-devel +%ghc_pkg_recache %files %defattr(-,root,root,-) %doc LICENSE +%doc README.md %{_bindir}/%{name} +%files -n ghc-%{name} -f ghc-%{name}.files +%defattr(-,root,root,-) +%doc LICENSE + +%files -n ghc-%{name}-devel -f ghc-%{name}-devel.files +%defattr(-,root,root,-) +%doc README.md + %changelog ++++++ hspec-setup-0.1.1.1.tar.gz -> hspec-setup-0.2.1.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hspec-setup-0.1.1.1/README.md new/hspec-setup-0.2.1.0/README.md --- old/hspec-setup-0.1.1.1/README.md 1970-01-01 01:00:00.000000000 +0100 +++ new/hspec-setup-0.2.1.0/README.md 2015-12-20 16:21:54.000000000 +0100 @@ -0,0 +1,22 @@ +# hspec-setup +[](http://hackage.haskell.org/package/hspec-setup) +[](http://hackage.haskell.org/package/hspec-setup) +[](https://travis-ci.org/yamadapc/haskell-hspec-setup) +- - - +Add an hspec test-suite in one command + + + +## Installation +``` +$ stack install hspec-setup +``` + +## Usage +``` +$ hspec-setup +``` + +## License +This code is licensed under the MIT license. Please refer to the +[LICENSE](/LICENSEE) file for more information diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hspec-setup-0.1.1.1/bin/Main.hs new/hspec-setup-0.2.1.0/bin/Main.hs --- old/hspec-setup-0.1.1.1/bin/Main.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hspec-setup-0.2.1.0/bin/Main.hs 2016-08-19 15:34:39.000000000 +0200 @@ -0,0 +1,7 @@ +module Main + where + +import qualified Test.Hspec.Setup + +main :: IO () +main = Test.Hspec.Setup.main diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hspec-setup-0.1.1.1/hspec-setup.cabal new/hspec-setup-0.2.1.0/hspec-setup.cabal --- old/hspec-setup-0.1.1.1/hspec-setup.cabal 2016-06-14 18:59:12.000000000 +0200 +++ new/hspec-setup-0.2.1.0/hspec-setup.cabal 2016-08-22 23:44:28.000000000 +0200 @@ -1,32 +1,99 @@ -name: hspec-setup -version: 0.1.1.1 -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 -author: Pedro Tacla Yamada -maintainer: [email protected] -copyright: Copyright (c) 2015 Pedro Tacla Yamada -category: Development -build-type: Simple -cabal-version: >=1.10 +-- This file has been generated from package.yaml by hpack version 0.14.0. +-- +-- see: https://github.com/sol/hpack -tested-with: GHC >= 7.10 +name: hspec-setup +version: 0.2.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 +author: Pedro Tacla Yamada +maintainer: [email protected] +copyright: Copyright (c) 2015 Pedro Tacla Yamada +category: Development +build-type: Simple +cabal-version: >= 1.10 + +extra-source-files: + README.md source-repository head type: git location: git://github.com/yamadapc/haskell-hspec-setup +library + hs-source-dirs: + src + build-depends: + ansi-wl-pprint + , pretty >=1.1.2.0 + , base >=4 && <5 + , directory + , directory-tree + , filepath + , process >=1.2 + , projectroot >=0.2 + , haskell-src-exts >=1.18.2 && <1.19 + , split + , strict + exposed-modules: + Test.Hspec.Setup + System.Directory.Recursive + other-modules: + Paths_hspec_setup + default-language: Haskell2010 + executable hspec-setup - main-is: Main.hs - build-depends: base >=4 && <5 - , directory - , filepath - , process >= 1.2 - , projectroot >= 0.2 - hs-source-dirs: src - default-language: Haskell2010 + main-is: Main.hs + build-depends: + ansi-wl-pprint + , pretty >=1.1.2.0 + , base >=4 && <5 + , directory + , directory-tree + , filepath + , process >=1.2 + , projectroot >=0.2 + , haskell-src-exts >=1.18.2 && <1.19 + , split + , strict + , hspec-setup + hs-source-dirs: + bin + default-language: Haskell2010 + +test-suite hspec + main-is: Spec.hs + type: exitcode-stdio-1.0 + build-depends: + ansi-wl-pprint + , pretty >=1.1.2.0 + , base >=4 && <5 + , directory + , directory-tree + , filepath + , process >=1.2 + , projectroot >=0.2 + , haskell-src-exts >=1.18.2 && <1.19 + , split + , strict + , QuickCheck + , language-dockerfile >=0.3.4 + , base + , directory + , bytestring + , cryptohash + , hspec + , hspec-setup + other-modules: + SanitySpec + System.Directory.RecursiveSpec + Test.Hspec.SetupSpec + hs-source-dirs: + test + default-language: Haskell2010 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hspec-setup-0.1.1.1/src/Main.hs new/hspec-setup-0.2.1.0/src/Main.hs --- old/hspec-setup-0.1.1.1/src/Main.hs 2015-12-20 16:06:41.000000000 +0100 +++ new/hspec-setup-0.2.1.0/src/Main.hs 1970-01-01 01:00:00.000000000 +0100 @@ -1,76 +0,0 @@ -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 = 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 [ "" - , "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 :: String -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 - - 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 () diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hspec-setup-0.1.1.1/src/System/Directory/Recursive.hs new/hspec-setup-0.2.1.0/src/System/Directory/Recursive.hs --- old/hspec-setup-0.1.1.1/src/System/Directory/Recursive.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hspec-setup-0.2.1.0/src/System/Directory/Recursive.hs 2016-08-19 15:34:39.000000000 +0200 @@ -0,0 +1,41 @@ +module System.Directory.Recursive + ( + getDirectoryContentsRecursive + , isHaskellSource + , pretty + , putDoc + , module System.Directory.Tree + ) + where + +import Debug.Trace +import System.Directory +import System.Directory.Tree +import System.FilePath +import Text.PrettyPrint.ANSI.Leijen hiding ((<$>)) +import qualified Text.PrettyPrint.ANSI.Leijen ((<$>)) +-- import Text.PrettyPrint.HughesPJClass + +(<++>) = (Text.PrettyPrint.ANSI.Leijen.<$>) + +getDirectoryContentsRecursive + :: FilePath -> IO (AnchoredDirTree ()) +getDirectoryContentsRecursive = readDirectoryWith (const $ return ()) + +instance Pretty (DirTree a) where + pretty (Dir dn ds) = cyan (text dn) <$$> + vcat (map (hang 2 . (text (replicate 2 ' ') <>) . pretty) ds) + pretty (File fn _) = white (text fn) <> red (text " <-") + pretty (Failed fn e) = red (text fn <> text (show e)) + +isHaskellSource (File fn _) = + takeExtension fn == ".hs" +isHaskellSource (Dir _ []) = False +isHaskellSource (Dir ".stack-work" _) = False +isHaskellSource (Dir _ ds) = -- traceShow (ds, any isHaskellSource ds) $ + any isHaskellSource ds +isHaskellSource _ = False + +recursiveLink = undefined + +recursiveMirror = undefined diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hspec-setup-0.1.1.1/src/Test/Hspec/Setup.hs new/hspec-setup-0.2.1.0/src/Test/Hspec/Setup.hs --- old/hspec-setup-0.1.1.1/src/Test/Hspec/Setup.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hspec-setup-0.2.1.0/src/Test/Hspec/Setup.hs 2016-08-22 22:59:47.000000000 +0200 @@ -0,0 +1,209 @@ +{-# LANGUAGE LambdaCase #-} +module Test.Hspec.Setup + where + +import Prelude hiding (readFile) + +import Control.Monad +import Data.List +import Data.List.Split +import Data.Maybe +import Data.Monoid +import Language.Haskell.Exts +import System.Directory +import System.Directory.ProjectRoot +import System.Directory.Recursive +import System.Environment +import System.Exit +import System.FilePath +import System.IO hiding (readFile) +import System.IO.Strict (readFile) +import System.Process + +main :: IO () +main = do + mfp <- getData + case mfp of + Left e -> panic e + Right fp -> executeCommand fp + where + panic e = do + hPutStrLn stderr e + exitFailure + executeCommand (pr, fp) = do + as <- getArgs + case as of + ("--generate":rest) -> hspecGenerate pr (listToMaybe rest) + ("-g":rest) -> hspecGenerate pr (listToMaybe rest) + [] -> hspecSetup pr fp + _ -> error $ unlines [ "Usage: hspec-setup [-g|--generate]" + , " hspec-setup Adds a test-suite to your project" + , " hspec-setup --generate [fp] Generates tests for a certain module" + , " hspec-setup -g" + ] + +data ManifestFilePath = CabalFile FilePath + | HpackFile FilePath + +unManifestFilePath :: ManifestFilePath -> FilePath +unManifestFilePath (CabalFile fp) = fp +unManifestFilePath (HpackFile fp) = fp + +type Options = (FilePath, ManifestFilePath) + +getData :: IO (Either String Options) +getData = getProjectRootCurrent >>= + \case + Nothing -> return $ Left "Couldn't find the project root" + Just pr -> do + fs <- getDirectoryContents pr + case find ("package.yaml" ==) fs of + Just fp -> return $ Right (pr, HpackFile fp) + Nothing -> case find ((".cabal" ==) . takeExtension) fs of + Just fp -> return $ Right (pr, CabalFile fp) + Nothing -> return $ Left + "Couldn't find your package manifest file (package.yaml/*.cabal)" + + +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" + ] + +hspecHpackTestSuite :: String +hspecHpackTestSuite = unlines [ "" + , "tests:" + , " hspec:" + , " main: Spec.hs" + , " source-dirs: test" + , " dependencies:" + , " - base" + , " - hspec" + , " - QuickCheck" + ] + +hspecDiscoveryFile :: String +hspecDiscoveryFile = "{-# OPTIONS_GHC -F -pgmF hspec-discover #-}" + +hspecSanitySpec :: String +hspecSanitySpec = unlines [ "module SanitySpec where" + , "" + , "import Test.Hspec" + , "" + , "spec = describe \"when I have tests\" $" + , " it \"I have sanity\" $ True `shouldBe` True" + ] + +hspecGenerate :: FilePath -> Maybe FilePath -> IO () +hspecGenerate pr (Just target) = parseFile target >>= \case + ParseOk (Module _ (Just (ModuleHead _ (ModuleName _ moduleName) _ (Just (ExportSpecList _ exportSpecs)))) _ _ _) -> + go moduleName (exportsFromSpecs exportSpecs) + ParseOk (Module _ (Just (ModuleHead _ (ModuleName _ moduleName) _ Nothing)) _ _ moduleDecls) -> + go moduleName (exportsFromDecls moduleDecls) + ParseOk (Module l Nothing _ _ moduleDecls) -> error (target <> " needs a `module` name") + ParseOk h -> error ("Don't know how to generate code from" <> (show h)) + e -> error (show e) + where + exportsFromSpecs = mapMaybe mexportFromSpec + where + mexportFromSpec (EVar _ (UnQual _ n)) = Just (prettyPrint n) + mexportFromSpec _ = Nothing + exportsFromDecls = mapMaybe mexportFromDecl + where + mexportFromDecl (FunBind _ ((Match _ n _ _ _):_)) = Just (prettyPrint n) + mexportFromDecl _ = Nothing + go :: String -> [String] -> IO () + go moduleName moduleExports = do + let moduleNameFp = (foldl (</>) "./test" $ splitOn "." (moduleName <> "Spec")) <> ".hs" + moduleNameFallbackFp = (foldl (</>) "./test" $ splitOn "." (moduleName <> "AutogenSpec")) <> ".hs" + testSuite mn = init $ unlines $ + [ "module " <> mn <> " where" + , "" + , "import " <> moduleName + , "" + , "import Test.Hspec" + , "" + , "spec :: Spec" + , "spec = do" + ] <> concatMap decToDescribe moduleExports + + createDirectoryIfMissing True (takeDirectory moduleNameFp) + e <- doesFileExist moduleNameFp + + when e $ do + hPutStrLn stderr ("Refusing to overwrite " <> moduleNameFp) + hPutStrLn stderr "Wrote test-suite to:" + putStrLn moduleNameFallbackFp + writeFile moduleNameFallbackFp (testSuite (moduleName <> "AutogenSpec")) + exitSuccess + + writeFile moduleNameFp (testSuite (moduleName <> "Spec")) + where + decToDescribe decName = [ + " describe \"" <> decName <> "\" $ do" + , " it \"works\" pending\n" + ] +hspecGenerate pr Nothing = error "Interactive mode not implemented" + +hspecSetup :: FilePath -> ManifestFilePath -> IO () +hspecSetup pr mfp = do + let fp = unManifestFilePath mfp + + c <- getCurrentDirectory + + putStrLn $ "Adding test-suite to " <> makeRelative c fp <> "..." + + appendHspecSuite pr mfp + + 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 () + +appendHspecSuite :: FilePath -> ManifestFilePath -> IO () +appendHspecSuite pr (HpackFile fp) = do + hpackContents <- readFile (pr </> fp) + let hpackLines = lines hpackContents + mi = elemIndex "tests:" hpackLines + case mi of + Nothing -> do + when ("hspec:" `isInfixOf` hpackContents) $ do + hPutStrLn stderr "File already has test-suite. Exiting..." + exitFailure + appendFile (pr </> fp) hspecHpackTestSuite + Just i -> do + let (beforeTests, afterTests) = splitAt i hpackLines :: ([String], [String]) + writeFile (pr </> fp) $ unlines [ unlines beforeTests + , unlines (drop 1 (lines hspecHpackTestSuite)) + , unlines afterTests + ] +appendHspecSuite pr (CabalFile fp) = do + cabalContents <- readFile (pr </> fp) + + when ("type: exitcode-stdio-1.0" `isInfixOf` cabalContents) $ do + hPutStrLn stderr "File already has test-suite. Exiting..." + exitFailure + + appendFile (pr </> fp) hspecTestSuite + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hspec-setup-0.1.1.1/test/SanitySpec.hs new/hspec-setup-0.2.1.0/test/SanitySpec.hs --- old/hspec-setup-0.1.1.1/test/SanitySpec.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hspec-setup-0.2.1.0/test/SanitySpec.hs 2016-08-19 15:34:39.000000000 +0200 @@ -0,0 +1,7 @@ +module SanitySpec where + +import Test.Hspec + +spec :: Spec +spec = describe "when I have tests" $ + it "I have sanity" $ True `shouldBe` True diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hspec-setup-0.1.1.1/test/Spec.hs new/hspec-setup-0.2.1.0/test/Spec.hs --- old/hspec-setup-0.1.1.1/test/Spec.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hspec-setup-0.2.1.0/test/Spec.hs 2016-07-10 22:47:42.000000000 +0200 @@ -0,0 +1 @@ +{-# OPTIONS_GHC -F -pgmF hspec-discover #-} \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hspec-setup-0.1.1.1/test/System/Directory/RecursiveSpec.hs new/hspec-setup-0.2.1.0/test/System/Directory/RecursiveSpec.hs --- old/hspec-setup-0.1.1.1/test/System/Directory/RecursiveSpec.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hspec-setup-0.2.1.0/test/System/Directory/RecursiveSpec.hs 2016-08-21 18:09:44.000000000 +0200 @@ -0,0 +1,16 @@ +module System.Directory.RecursiveSpec where + +import System.Directory.Recursive + +import Test.Hspec + +spec :: Spec +spec = do + describe "getDirectoryContentsRecursive" $ do + it "works" pending + describe "isHaskellSource" $ do + it "works" pending + describe "pretty" $ do + it "works" pending + describe "putDoc" $ do + it "works" pending \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/hspec-setup-0.1.1.1/test/Test/Hspec/SetupSpec.hs new/hspec-setup-0.2.1.0/test/Test/Hspec/SetupSpec.hs --- old/hspec-setup-0.1.1.1/test/Test/Hspec/SetupSpec.hs 1970-01-01 01:00:00.000000000 +0100 +++ new/hspec-setup-0.2.1.0/test/Test/Hspec/SetupSpec.hs 2016-08-22 23:43:58.000000000 +0200 @@ -0,0 +1,104 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE PackageImports #-} +module Test.Hspec.SetupSpec + where + +import Control.Exception +import "cryptohash" Crypto.Hash +import qualified Data.ByteString.Char8 as ByteString (pack) +import Data.Maybe +import Data.Monoid +import Language.Dockerfile +import System.Directory +import System.Exit +import System.Process + +import Test.Hspec + +-- | An image with hspec-setup and an empty project +newProjectImage :: EDockerfileM () +newProjectImage = do + from "haskell:7.10.3" + run "cabal update" + + add "./hspec-setup.cabal" "/hspec-setup/" + workdir "/hspec-setup" + run "cabal install --only-dependencies -j" + + add "." "/hspec-setup" + run "cabal install -j" + + run "mkdir /app" + workdir "/app" + run "cabal init -m -n" + run "echo 'main = print 10' > /app/Main.hs" + run "touch /app/LICENSE" + run "stack init" + run "stack build" + +eitherToMaybe (Left _) = Nothing +eitherToMaybe (Right r) = r + +-- | Builds the image defined in this EDockerfileM block by writting it to a +-- temporary file +dockerBuild :: EDockerfileM () -> IO String +dockerBuild img = do + let imgPre = "hspec-setup-tests-autogen" + imgStr = toDockerfileStr img + imgHash = show (hash (ByteString.pack imgStr) :: Digest MD5) + imgName = imgPre <> ":" <> imgHash + imgFp = "./" <> imgPre <> "." <> imgHash <> ".dockerfile" + mimg <- eitherToMaybe <$> (try ( + fmap (take 2) . listToMaybe . map words . lines <$> + readCreateProcess (shell ("docker images | grep " <> imgPre)) "") :: IO (Either SomeException (Maybe [String]))) + :: IO (Maybe [String]) + + -- print mimg + -- print (Just [imgPre, imgHash]) + + if mimg == Just [imgPre, imgHash] + then return imgName + else do + bracket_ + (writeFile imgFp imgStr) + (removeFile imgFp) + (callCommand $ "docker build -t " <> imgName <> " -f " <> imgFp <> " .") + return imgName + +-- | Runs the image with the tag passed-in +dockerRun :: String -> IO () +dockerRun imgName = callCommand $ "docker run --rm " <> imgName + +withImage :: EDockerfileM () -> (String -> IO b) -> IO b +withImage img action = do + bracket + (dockerBuild img) + (const (return ())) + action + +spec :: Spec +spec = do + describe "given an empty cabal project" $ + it "works" pending + {- + $ do + let img = newProjectImage >> cmd "hspec-setup" + withImage img $ \tag -> + dockerRun tag + -} + + describe "given an empty hpack project" $ + it "works" pending + {- + $ do + let img = newProjectImage >> do + run "stack install hpack-convert" + run "hpack-convert" + run "rm *.cabal" + run "echo 'library:\\n dependencies:\\n - base' >> package.yaml" + run "cat package.yaml" + run "hspec-setup" + cmd "cat package.yaml | grep 'tests:'" + withImage img $ \tag -> + dockerRun tag + -}
