tasty-jenkins-xml 0.1.0.0 → 0.2.0.0
raw patch · 5 files changed
+61/−143 lines, 5 filesdep ~tastydep ~tasty-ant-xmlPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: tasty, tasty-ant-xml
API changes (from Hackage documentation)
- Test.Tasty.Runners.JenkinsXML: jenkinsXMLTransformer :: [Ingredient] -> Ingredient
+ Test.Tasty.Runners.JenkinsXML: CompatAntXMLPath :: FilePath -> CompatAntXMLPath
+ Test.Tasty.Runners.JenkinsXML: ExitSuccess :: Bool -> ExitSuccess
+ Test.Tasty.Runners.JenkinsXML: [isExitSuccess] :: ExitSuccess -> Bool
+ Test.Tasty.Runners.JenkinsXML: addCompatOpt :: Ingredient -> Ingredient
+ Test.Tasty.Runners.JenkinsXML: addExitOpt :: Ingredient -> Ingredient
+ Test.Tasty.Runners.JenkinsXML: jenkinsXMLRunner :: Ingredient
+ Test.Tasty.Runners.JenkinsXML: newtype CompatAntXMLPath
+ Test.Tasty.Runners.JenkinsXML: newtype ExitSuccess
Files
- CHANGELOG.md +9/−1
- README.md +4/−27
- src/Test/Tasty/Runners/JenkinsXML.hs +38/−100
- tasty-jenkins-xml.cabal +7/−7
- test/spec.hs +3/−8
CHANGELOG.md view
@@ -4,9 +4,17 @@ ## [Unreleased][] +## [0.2.0.0][] (2017-03-04)++* Use [`composeReporters`][composeReporters] instead of being a transformer+ [#1](https://github.com/IxpertaSolutions/tasty-jenkins-xml/issues/1)++[composeReporters]: https://github.com/feuerbach/tasty/commit/e1f6a773ed42ad7401df2a8c3bbab1359dd0b22a+ ## [0.1.0.0][] (2017-02-28) * Initial release -[Unreleased]: https://github.com/IxpertaSolutions/tasty-jenkins-xml/compare/v0.1.0.0...HEAD+[Unreleased]: https://github.com/IxpertaSolutions/tasty-jenkins-xml/compare/v0.2.0.0...HEAD+[0.2.0.0]: https://github.com/IxpertaSolutions/tasty-jenkins-xml/compare/v0.1.0.0...v0.2.0.0 [0.1.0.0]: https://github.com/IxpertaSolutions/tasty-jenkins-xml/compare/v0.0.0.0...v0.1.0.0
README.md view
@@ -9,21 +9,14 @@ ## Description -**An ingredient transformer version of [tasty-ant-xml][tasty-ant-xml].**--This package implements a [tasty][] ingredient transformer that makes it-possible to output test results as JUnit XML **in addition to** other output-ingredient, e.g. a `consoleTestReporter`. Internally it invokes the-[tasty-ant-xml][] ingredient.--To be practically useful, it implements two additions:+An extension of [tasty-ant-xml][] that also outputs to console and implements+two additions to be more practically useful: * `--jxml` alias for `--xml` for [test-framework][] compatibility, * `--exit-success` to distinguish between _failed_ and _unstable_ builds in Jenkins CI. -[tasty]: https://hackage.haskell.org/package/tasty [tasty-ant-xml]: https://hackage.haskell.org/package/tasty-ant-xml [test-framework]: https://hackage.haskell.org/package/test-framework @@ -33,28 +26,12 @@ ```haskell import Test.Tasty-import Test.Tasty.Runners.JenkinsXML (jenkinsXMLTransformer)--main :: IO ()-main = defaultMainWithIngredients ingredients tests- where- ingredients = [listingTests, jenkinsXMLTransformer [consoleTestReporter]]-```--Alternatively `jenkinsXMLTransformer` may be applied directly to-`defaultIngredients`.--For comparison, here's a `main` that uses [tasty-ant-xml][] instead (and can't-output to console and XML at the same time):--```haskell-import Test.Tasty-import Test.Tasty.Runners.AntXML (antXMLRunner)+import Test.Tasty.Runners.JenkinsXML (jenkinsXMLRunner) main :: IO () main = defaultMainWithIngredients ingredients tests where- ingredients = [listingTests, antXMLRunner, consoleTestReporter]+ ingredients = [listingTests, jenkinsXMLRunner] ``` ## Contributing
src/Test/Tasty/Runners/JenkinsXML.hs view
@@ -2,43 +2,35 @@ {-# LANGUAGE NoImplicitPrelude #-} module Test.Tasty.Runners.JenkinsXML- ( jenkinsXMLTransformer+ ( CompatAntXMLPath(..)+ , ExitSuccess(..)+ , addCompatOpt+ , addExitOpt+ , jenkinsXMLRunner ) where import Control.Applicative (pure)-import Control.Monad ((>>=), msum, join) import Data.Bool (Bool(True, False), (||))-import Data.Foldable (concatMap) import Data.Function ((.), ($), flip)-import Data.Functor (fmap)-import Data.Maybe (Maybe(Nothing, Just), fromMaybe)-import Data.Monoid ((<>))+import Data.Functor (Functor(fmap))+import Data.Maybe (Maybe(Nothing, Just))+import Data.Monoid (mempty) import Data.Proxy (Proxy(Proxy))-import Data.Traversable (mapM) import Data.Typeable (Typeable)-import System.IO (IO, FilePath)+import System.IO (FilePath) +import Test.Tasty.Ingredients (Ingredient(TestReporter), composeReporters)+import Test.Tasty.Ingredients.Basic (consoleTestReporter) import Test.Tasty.Options ( IsOption(defaultValue, parseValue, optionName, optionHelp, optionCLParser)- , OptionSet , OptionDescription(Option)- , flagCLParser , lookupOption+ , mkFlagCLParser , safeRead , setOption )-import Test.Tasty.Runners- ( Ingredient(TestReporter, TestManager)- , StatusMap- , TestTree- , Time- , launchTestTree- )-import Test.Tasty.Runners.AntXML- ( antXMLRunner- , AntXMLPath(AntXMLPath)- )+import Test.Tasty.Runners.AntXML (antXMLRunner, AntXMLPath(AntXMLPath)) newtype CompatAntXMLPath = CompatAntXMLPath FilePath deriving Typeable@@ -56,92 +48,38 @@ parseValue = fmap ExitSuccess . safeRead optionName = pure "exit-success" optionHelp = pure "Exit with status 0 even if some tests failed"- optionCLParser = flagCLParser Nothing (ExitSuccess True)--type ReportFn = StatusMap -> IO (Time -> IO Bool)--antXmlOptions :: [OptionDescription]-antXmlReport :: OptionSet -> TestTree -> Maybe ReportFn-TestReporter antXmlOptions antXmlReport = antXMLRunner+ optionCLParser = mkFlagCLParser mempty (ExitSuccess True) --- | This 'Ingredient' transformer adds the possibility to produce a JUnit XML--- file __in addition to__ the output producer by another 'Ingredient'.--- Internally it invokes 'Test.Tasty.Runners.AntXML.antXMLRunner'.------ To be practically useful, it implements two additions:------ * @--jxml@ alias for @--xml@ for @test-framework@ compatibility,------ * @--exit-success@ to distinguish between /failed/ and /unstable/ builds--- in Jenkins CI.-jenkinsXMLTransformer :: [Ingredient] -> Ingredient-jenkinsXMLTransformer =- testReporterTransformer (exitOption : compatOption : antXmlOptions) $- reportTransform antXmlTransform . applyCompatOpt+addCompatOpt :: Ingredient -> Ingredient+addCompatOpt reporter =+ TestReporter (compatOpt : optDesc) (runner . applyCompatOpt) where- exitOption = Option (Proxy :: Proxy ExitSuccess)- compatOption = Option (Proxy :: Proxy (Maybe CompatAntXMLPath))-+ TestReporter optDesc runner = reporter+ compatOpt = Option (Proxy :: Proxy (Maybe CompatAntXMLPath)) applyCompatOpt opts = case lookupOption opts of Nothing -> opts Just (CompatAntXMLPath path) -> setOption (Just (AntXMLPath path)) opts - antXmlTransform opts testTree smap totalTime = fmap exit . antXml- where- exit retVal = retVal || isExitSuccess (lookupOption opts)-- antXml retVal = fromMaybe retVal `fmap` tryReport antXmlReport-- tryReport r =- (join . fmap ($ totalTime) . ($ smap)) `mapM` r opts testTree---- Combinator for transforming the final report/record callback of a--- 'TestReporter'.-reportTransform- :: (OptionSet -> TestTree -> StatusMap -> Time -> Bool -> IO Bool)- -> OptionSet -> TestTree -> ReportFn -> ReportFn-reportTransform f opts testTree reportFn smap =- reportFn smap >>= \k -> pure $ \totalTime ->- k totalTime >>= f opts testTree smap totalTime---- Combinator for building ingredient transformers that change the behaviour--- of an existing 'TestReporter' ingredient.-testReporterTransformer- :: [OptionDescription]- -- ^ Additional command-line options- -> (OptionSet -> TestTree -> ReportFn -> ReportFn)- -- ^ Function to transform the 'ReportFn' of a 'TestReporter', see- -- 'tryIngredient'' and 'launchTestTree' for details.- -> [Ingredient]- -- ^ Ingredients to transform and run.- -> Ingredient-testReporterTransformer options transform ingredients =- TestManager (options <> existingOptions) $- tryIngredients' transform ingredients+addExitOpt :: Ingredient -> Ingredient+addExitOpt reporter =+ TestReporter (exitOpt : optDesc) (mapExit exit runner) where- existingOptions = flip concatMap ingredients $ \ingredient ->- case ingredient of- TestReporter opts _ -> opts- TestManager opts _ -> opts+ TestReporter optDesc runner = reporter+ exitOpt = Option (Proxy :: Proxy ExitSuccess)+ exit opts retVal = retVal || isExitSuccess (lookupOption opts)+ mapExit f run o tt = run o tt <&> \rf s -> rf s <&> \r t -> r t <&> f o --- | Modified version of 'Test.Tasty.Ingredients.tryIngredient' that--- transforms the 'ReportFn' by a given function, if the 'Ingredient' happens--- to be a 'TestReporter'. 'TestManager' is left unmodified.-tryIngredient'- :: (OptionSet -> TestTree -> ReportFn -> ReportFn)- -> Ingredient -> OptionSet -> TestTree -> Maybe (IO Bool)-tryIngredient' f (TestReporter _ report) opts testTree = do -- Maybe monad- reportFn <- report opts testTree- pure $ launchTestTree opts testTree $ f opts testTree reportFn-tryIngredient' _ (TestManager _ manage) opts testTree =- manage opts testTree+(<&>) :: Functor f => f a -> (a -> b) -> f b+(<&>) = flip fmap --- | Modified version of 'Test.Tasty.Ingredients.tryIngredients' that--- transforms the 'ReportFn' by a given function, if the 'Ingredient' happens--- to be a 'TestReporter'. 'TestManager' is left unmodified.-tryIngredients'- :: (OptionSet -> TestTree -> ReportFn -> ReportFn)- -> [Ingredient] -> OptionSet -> TestTree -> Maybe (IO Bool)-tryIngredients' f ins opts tree =- msum $ fmap (\i -> tryIngredient' f i opts tree) ins+-- | An extended version of 'antXMLRunner' that also outputs to console and+-- implements two additions to be more practically useful:+--+-- * @--jxml@ alias for @--xml@ for @test-framework@ compatibility,+--+-- * @--exit-success@ to distinguish between /failed/ and /unstable/ builds+-- in Jenkins CI.+jenkinsXMLRunner :: Ingredient+jenkinsXMLRunner = addExitOpt . addCompatOpt+ $ antXMLRunner `composeReporters` consoleTestReporter
tasty-jenkins-xml.cabal view
@@ -3,9 +3,9 @@ -- see: https://github.com/sol/hpack name: tasty-jenkins-xml-version: 0.1.0.0-synopsis: Render tasty output to XML for Jenkins (ingredient transformer)-description: A tasty ingredient transformer (meaning consoleTestReporter or any other ingredient can run as well) to output test results in XML, using the Ant schema. This XML can be consumed by the Jenkins continuous integration framework.+version: 0.2.0.0+synopsis: Render tasty output to both console and XML for Jenkins+description: An extension of <https://hackage.haskell.org/package/tasty-ant-xml tasty-ant-xml> that is meant to be more practically useful with Jenkins CI. category: Testing homepage: https://github.com/IxpertaSolutions/tasty-jenkins-xml#readme bug-reports: https://github.com/IxpertaSolutions/tasty-jenkins-xml/issues@@ -37,8 +37,8 @@ ghc-options: -Wall -fwarn-tabs -fwarn-implicit-prelude build-depends: base >=4 && <5- , tasty >= 0.10 && < 0.12- , tasty-ant-xml == 1.0.*+ , tasty >=0.11.2 && <0.12+ , tasty-ant-xml ==1.0.* if flag(pedantic) ghc-options: -Werror if impl(ghc >=8)@@ -57,7 +57,7 @@ ghc-options: -Wall -fwarn-tabs -fwarn-implicit-prelude build-depends: base >=4 && <5- , tasty >= 0.10 && < 0.12+ , tasty >=0.11.2 && <0.12 , hlint >=1.9 if flag(pedantic) ghc-options: -Werror@@ -73,7 +73,7 @@ ghc-options: -Wall -fwarn-tabs -fwarn-implicit-prelude build-depends: base >=4 && <5- , tasty >= 0.10 && < 0.12+ , tasty >=0.11.2 && <0.12 , bytestring >=0.9 , directory >=1.2.3.0 , hspec >=2.2
test/spec.hs view
@@ -32,14 +32,9 @@ , shouldThrow ) import Test.Mockery.Directory (inTempDirectory)-import Test.Tasty- ( TestTree- , defaultMainWithIngredients- , defaultIngredients- , testGroup- )+import Test.Tasty (TestTree, defaultMainWithIngredients, testGroup) import Test.Tasty.HUnit (assert, testCase)-import Test.Tasty.Runners.JenkinsXML (jenkinsXMLTransformer)+import Test.Tasty.Runners.JenkinsXML (jenkinsXMLRunner) {-# ANN module ("HLint: ignore Reduce duplication" :: String) #-}@@ -91,7 +86,7 @@ tastyMain :: IO () tastyMain = defaultMainWithIngredients ingredients tastyTests where- ingredients = [jenkinsXMLTransformer defaultIngredients]+ ingredients = [jenkinsXMLRunner] tastyTests :: TestTree tastyTests = testGroup "group1"