hspec-jenkins (empty) → 0.1.0
raw patch · 7 files changed
+194/−0 lines, 7 filesdep +basedep +blaze-markupdep +hspecsetup-changed
Dependencies added: base, blaze-markup, hspec
Files
- LICENSE.txt +22/−0
- Setup.hs +2/−0
- example/example.cabal +23/−0
- example/lib/Example.hs +10/−0
- example/test/test.hs +42/−0
- hspec-jenkins.cabal +29/−0
- lib/Test/Hspec/Formatters/Jenkins.hs +66/−0
+ LICENSE.txt view
@@ -0,0 +1,22 @@+Copyright (c) 2013 Kohei Suzuki++MIT License++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
+ example/example.cabal view
@@ -0,0 +1,23 @@+name: example+version: 0.1.0+author: eagletmt+maintainer: eagletmt@gmail.com+build-type: Simple+cabal-version: >= 1.8++library+ build-depends: base == 4.*+ hs-source-dirs: lib+ ghc-options: -Wall -W+ exposed-modules: Example++test-suite test+ build-depends:+ base == 4.*+ , example+ , hspec+ , hspec-jenkins+ hs-source-dirs: test+ ghc-options: -Wall -W+ type: exitcode-stdio-1.0+ main-is: test.hs
+ example/lib/Example.hs view
@@ -0,0 +1,10 @@+module Example where++add :: Int -> Int -> Int+add = (+)++sub :: Int -> Int -> Int+sub = subtract++exn :: IO Int+exn = ioError $ userError "exn"
+ example/test/test.hs view
@@ -0,0 +1,42 @@+module Main where++import Control.Monad (unless)+import System.Exit (exitFailure)+import System.IO (withFile, IOMode(..))+import Test.Hspec+import Test.Hspec.QuickCheck (prop)+import Test.Hspec.Runner+import Test.Hspec.Formatters.Jenkins (xmlFormatter)++import Example+++main :: IO ()+main = do+ -- hspec spec+ summary <- withFile "results.xml" WriteMode $ \h -> do+ let c = defaultConfig+ { configFormatter = xmlFormatter+ , configHandle = h+ }+ hspecWith c spec+ unless (summaryFailures summary == 0) $+ exitFailure++spec :: Spec+spec = do+ describe "sub" $ do+ it "subtracts" $+ sub 1 5 == 1 - 5+ describe "add" $ do+ prop "truth" $ True+ prop "adds" $ \n m -> add n m == n + m+ describe "exn&" $ do+ describe "<desc>" $ do+ it "throws IOException" $+ exn `shouldThrow` anyIOException+ describe "foo" $ do+ it "bar" $ do+ pending "baz"+ it "hoge" $ do+ pending
+ hspec-jenkins.cabal view
@@ -0,0 +1,29 @@+name: hspec-jenkins+version: 0.1.0+synopsis: Jenkins-friendly XML formatter for Hspec+description: Jenkins-friendly XML formatter for Hspec+author: Kohei Suzuki+maintainer: eagletmt@gmail.com+build-type: Simple+cabal-version: >= 1.8+category: Testing+license: MIT+license-file: LICENSE.txt+homepage: https://github.com/worksap-ate/hspec-jenkins+extra-source-files:+ example/example.cabal+ example/lib/*.hs+ example/test/*.hs+source-repository head+ type: git+ location: git://github.com/worksap-ate/hspec-jenkins.git++library+ build-depends:+ base == 4.*+ , hspec >= 1.4+ , blaze-markup+ hs-source-dirs: lib+ ghc-options: -Wall -W+ exposed-modules:+ Test.Hspec.Formatters.Jenkins
+ lib/Test/Hspec/Formatters/Jenkins.hs view
@@ -0,0 +1,66 @@+{-| This module provides 'xmlFormatter' that can be used with 'Test.Hspec.Runner.hspecWith'.++ Example usage:++ > import Test.Hspec.Formatters.Jenkins (xmlFormatter)+ > import Test.Hspec.Runner+ >+ > main :: IO ()+ > main = do+ > summary <- withFile "results.xml" WriteMode $ \h -> do+ > let c = defaultConfig+ > { configFormatter = xmlFormatter+ > , configHandle = h+ > }+ > hspecWith c spec+ > unless (summaryFailures summary == 0) $+ > exitFailure++ An example project is located in @example@ directory.+-}++{-# LANGUAGE RecordWildCards, OverloadedStrings #-}+module Test.Hspec.Formatters.Jenkins (xmlFormatter) where+import Data.List (intercalate)+import Test.Hspec.Formatters+import Test.Hspec.Runner (Path)+import Text.Blaze.Renderer.String (renderMarkup)+import Text.Blaze.Internal++failure, skipped :: Markup -> Markup+failure = customParent "failure"+skipped = customParent "skipped"++name, className, message :: String -> Attribute+name = customAttribute "name" . stringValue+className = customAttribute "classname" . stringValue+message = customAttribute "message" . stringValue++testcase :: Path -> Markup -> Markup+testcase (xs,x) = customParent "testcase" ! name x ! className (intercalate "." xs)++-- | Format Hspec result to Jenkins-friendly XML.+xmlFormatter :: Formatter+xmlFormatter = Formatter{..}+ where+ headerFormatter = do+ writeLine "<?xml version='1.0' encoding='UTF-8'?>"+ writeLine "<testsuite>"+ exampleGroupStarted _ _ _ = return ()+ exampleGroupDone = return ()+ exampleSucceeded path = do+ writeLine $ renderMarkup $+ testcase path ""+ exampleFailed path err = do+ writeLine $ renderMarkup $+ testcase path $+ failure ! message (either formatException id err) $ ""+ examplePending path mdesc = do+ writeLine $ renderMarkup $+ testcase path $+ case mdesc of+ Just desc -> skipped ! message desc $ ""+ Nothing -> skipped ""+ failedFormatter = return ()+ footerFormatter = do+ writeLine "</testsuite>"