specup 0.2.0.1 → 0.2.0.2
raw patch · 5 files changed
+75/−11 lines, 5 filesdep +directorydep +processdep ~extra
Dependencies added: directory, process
Dependency ranges changed: extra
Files
- specup.cabal +10/−2
- test/Spec.hs +46/−9
- test/resources/example-from-readme/animal.yaml +4/−0
- test/resources/example-from-readme/output.txt +9/−0
- test/resources/example-from-readme/template.m +6/−0
specup.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: specup-version: 0.2.0.1+version: 0.2.0.2 author: Daniel Rolls maintainer: daniel.rolls.27@googlemail.com@@ -13,6 +13,10 @@ category: Documentation extra-doc-files: CHANGELOG.md+extra-source-files:+ test/resources/example-from-readme/*.yaml,+ test/resources/example-from-readme/*.m,+ test/resources/example-from-readme/*.txt source-repository head type: git@@ -46,7 +50,7 @@ yaml >= 0.11.11.1 && <0.12, stache >=2.3.3 && < 2.4, megaparsec >=9.2.2 && < 9.7,- extra >= 1.7.13 && < 1.8+ extra >= 1.7.13 && < 1.9 test-suite specup-test import: deps@@ -54,7 +58,11 @@ main-is: Spec.hs hs-source-dirs: test build-depends:+ directory >=1.3.7.1 && <1.4, hspec >=2.9.7 && <2.12, hspec-core >=2.9.7 && <2.12,+ process >= 1.6.18 && < 1.7,+ extra >= 1.7.14 && < 1.9, specup >=0+ build-tool-depends: specup:specup
test/Spec.hs view
@@ -1,27 +1,64 @@ import Prelude hiding (unlines)-import Test.Hspec (describe, hspec, it, shouldBe, expectationFailure)++import Control.Monad (when)+import Data.ByteString (hGetContents)+import Data.ByteString.Char8 (unpack)+import Data.List.Extra (splitOn) import Data.Text (Text, unlines)+import qualified Data.Text (unpack) import qualified Data.Text.Lazy as LazyText+import System.Directory (setCurrentDirectory)+import System.Environment (lookupEnv)+import System.Exit (ExitCode(ExitFailure, ExitSuccess))+import System.Process (StdStream(CreatePipe), createProcess, proc, std_err, std_out, waitForProcess)+import Test.Hspec (describe, expectationFailure, hspec, it, shouldBe) import SpecUp (invokeTemplateOnSpec) -main = hspec $ do+main = do+ runExtendedTests <- testVarSet+ hspec $ do - it "should pass new" $- invokeTemplateOnSpec testTmpl sampleTestYaml+ when runExtendedTests $+ it "should call the binary with the example in the README" $+ usingTestData "example-from-readme" $+ do res <- callSpecUpWithArgs "-s animal.yaml -t template.m"+ specupStandardErr res `shouldBe` ""+ (specupStandardOut res `shouldBe`) =<< readFile "output.txt"+ specupExitCode res `shouldBe` ExitSuccess++ it "should work with a template with a simple list" $+ invokeTemplateOnSpec "{{# .}}# {{{ fieldName }}}\n{{/ .}}"+ "- fieldName: value1\n- fieldName: value2" `shouldReturnMarkupOf` [ "# value1" , "# value2" ] -shouldReturnMarkupOf output expectedMarkup =+data SpecupResult = SpecupResult {+ specupStandardOut :: !String+, specupStandardErr :: !String+, specupExitCode :: !ExitCode+} deriving (Show, Eq)++output `shouldReturnMarkupOf` expectedMarkup = either (expectationFailure . ("expected Right but got Left " <>))- (`shouldBe` resultLines expectedMarkup)+ (`shouldBe` LazyText.unlines expectedMarkup) output -sampleTestYaml = "- fieldName: value1\n- fieldName: value2"+callSpecUpWithArgs :: String -> IO SpecupResult+callSpecUpWithArgs args =+ do (_,Just mOut, Just mErr, procHandle) <- createProcess $ (proc "specup" (splitOn " " args)) {std_out = CreatePipe, std_err = CreatePipe}+ SpecupResult <$> (unpack <$> hGetContents mOut)+ <*> (unpack <$> hGetContents mErr)+ <*> waitForProcess procHandle -testTmpl = "{{# .}}# {{{ fieldName }}}\n{{/ .}}"+testVarSet =+ (== Just "1") <$> lookupEnv "TEST_BINARY" -resultLines = LazyText.unlines+usingTestData testData payload =+ do setCurrentDirectory $ "test/resources/" <> testData+ res <- payload+ setCurrentDirectory "../.."+ return res
+ test/resources/example-from-readme/animal.yaml view
@@ -0,0 +1,4 @@+- animal: Dog+ class: mammal+- animal: Crocodile+ class: reptile
+ test/resources/example-from-readme/output.txt view
@@ -0,0 +1,9 @@+# Dog++Animal class: mammal++# Crocodile++Animal class: reptile++
+ test/resources/example-from-readme/template.m view
@@ -0,0 +1,6 @@+{{# . }}+# {{{ animal }}}++Animal class: {{{ class }}}++{{/ . }}