hspec-junit-formatter 1.3.0.0 → 1.3.1.0
raw patch · 5 files changed
+76/−39 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- README.lhs +21/−17
- README.md +21/−17
- hspec-junit-formatter.cabal +1/−1
- library/Test/Hspec/JUnit/Formatter.hs +32/−3
- tests/SpecHook.hs +1/−1
README.lhs view
@@ -45,7 +45,6 @@ hook2 = Formatter.register $ defaultJUnitConfig "test-suite" ``` - ### Adding a JUnit report To produce a JUnit report _in addition to normal output_, use `add`:@@ -55,6 +54,26 @@ hook3 = Formatter.add $ defaultJUnitConfig "test-suite" ``` +### Mixing Formatters++In addition to the formatter named `junit`, this library also registers+formatters named `{formatter}+junit` for every existing formatter. This allows+doing something like `--format progress+junit` to produce output with `progress`+while also producing a JUnit file though `junit`.++The `add` hook can be thought of like `--format checks+junit`, so this extra+registration allows for similar "add" behavior on top of non-default formatters.++Once registered, they can be seen in Hspec's `--help`:++```console+ -f NAME --format=NAME use a custom formatter; this can be one of+ junit, checks+junit, specdoc+junit,+ progress+junit, failed-examples+junit,+ silent+junit, checks, specdoc, progress,+ failed-examples or silent+```+ ### Environment Configuration To configure things via @JUNIT_@-prefixed environment variables, import@@ -96,28 +115,13 @@ ```haskell main :: IO ()-main = hspec $ FormatterEnv.whenEnabled FormatterEnv.add spec+main = hspec $ FormatterEnv.register spec -- or use, or add spec :: Spec spec = describe "Addition" $ do it "adds" $ do 2 + 2 `shouldBe` (4 :: Int) ```--## Golden Testing--This project's test suite uses [hspec-golden][] to generate an XML report for-[`Example.hs`](./tests/Example.hs) and then compare that with golden XML files-checked into the repository. If your work changes things in a-functionally-correct way, but that diverges from the golden XML files, you need-to regenerate them.--1. Run `rm tests/golden*.xml`-2. Run the specs again--We maintain specific golden XML files for GHC 8.x vs 9.x, so you will need to-re-run the test suite with at least one of each series to regenerate all the-necessary files. ## Release
README.md view
@@ -45,7 +45,6 @@ hook2 = Formatter.register $ defaultJUnitConfig "test-suite" ``` - ### Adding a JUnit report To produce a JUnit report _in addition to normal output_, use `add`:@@ -55,6 +54,26 @@ hook3 = Formatter.add $ defaultJUnitConfig "test-suite" ``` +### Mixing Formatters++In addition to the formatter named `junit`, this library also registers+formatters named `{formatter}+junit` for every existing formatter. This allows+doing something like `--format progress+junit` to produce output with `progress`+while also producing a JUnit file though `junit`.++The `add` hook can be thought of like `--format checks+junit`, so this extra+registration allows for similar "add" behavior on top of non-default formatters.++Once registered, they can be seen in Hspec's `--help`:++```console+ -f NAME --format=NAME use a custom formatter; this can be one of+ junit, checks+junit, specdoc+junit,+ progress+junit, failed-examples+junit,+ silent+junit, checks, specdoc, progress,+ failed-examples or silent+```+ ### Environment Configuration To configure things via @JUNIT_@-prefixed environment variables, import@@ -96,28 +115,13 @@ ```haskell main :: IO ()-main = hspec $ FormatterEnv.whenEnabled FormatterEnv.add spec+main = hspec $ FormatterEnv.register spec -- or use, or add spec :: Spec spec = describe "Addition" $ do it "adds" $ do 2 + 2 `shouldBe` (4 :: Int) ```--## Golden Testing--This project's test suite uses [hspec-golden][] to generate an XML report for-[`Example.hs`](./tests/Example.hs) and then compare that with golden XML files-checked into the repository. If your work changes things in a-functionally-correct way, but that diverges from the golden XML files, you need-to regenerate them.--1. Run `rm tests/golden*.xml`-2. Run the specs again--We maintain specific golden XML files for GHC 8.x vs 9.x, so you will need to-re-run the test suite with at least one of each series to regenerate all the-necessary files. ## Release
hspec-junit-formatter.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: hspec-junit-formatter-version: 1.3.0.0+version: 1.3.1.0 license: MIT license-file: LICENSE copyright: 2021 Renaissance Learning Inc
library/Test/Hspec/JUnit/Formatter.hs view
@@ -21,6 +21,12 @@ -- hook = Formatter.register defaultJUnitConfig -- @ --+-- __NOTE__: In addition to registering the @junit@ formatter, all functions of+-- this module will register @{formatter}+junit@ formatters for every existing+-- available @formatter@. This allows you to produce JUnit files in addition to+-- non-default formats. For example, to produce output using @progress@ along+-- with a JUnit file, use @--format progress+junit@.+-- -- See also, -- -- - https://hspec.github.io/hspec-discover.html#spec-hooks@@ -49,19 +55,36 @@ -- | Register 'junit' as an available formatter and use it by default use :: JUnitConfig -> SpecWith a -> SpecWith a-use config = (modifyConfig (useFormatter $ formatter config) >>)+use config = (modifyConfig (useFormatter f . registerAdditions f) >>)+ where+ f = formatter config -- | Register 'junit', and use it /in addition/ to the default add :: JUnitConfig -> SpecWith a -> SpecWith a-add config = (modifyConfig (addFormatter $ formatter config) >>)+add config = (modifyConfig (addFormatter f . registerAdditions f) >>)+ where+ f = formatter config -- | Register 'junit', but do not change the default register :: JUnitConfig -> SpecWith a -> SpecWith a-register config = (modifyConfig (registerFormatter $ formatter config) >>)+register config = (modifyConfig (registerFormatter f . registerAdditions f) >>)+ where+ f = formatter config formatter :: JUnitConfig -> (String, FormatConfig -> IO Format) formatter config = ("junit", junit config) +registerAdditions :: (String, FormatConfig -> IO Format) -> Config -> Config+registerAdditions f config =+ config+ { configAvailableFormatters =+ -- registerFormatter puts it in the front, so we'll do the same+ map (`combineFormat` liftFormatter f) existing <> existing+ }+ where+ existing :: [(String, Core.FormatConfig -> IO Core.Format)]+ existing = configAvailableFormatters config+ addFormatter :: (String, FormatConfig -> IO Format) -> Config -> Config addFormatter f = go . registerFormatter f where@@ -78,6 +101,12 @@ defaultFormat :: Core.FormatConfig -> IO Core.Format defaultFormat = V2.formatterToFormat V2.checks++combineFormat+ :: (String, Core.FormatConfig -> IO Core.Format)+ -> (String, Core.FormatConfig -> IO Core.Format)+ -> (String, Core.FormatConfig -> IO Core.Format)+combineFormat (name1, f1) (name2, f2) = (name1 <> "+" <> name2, addFormat f1 f2) addFormat :: (Core.FormatConfig -> IO Core.Format)
tests/SpecHook.hs view
@@ -6,4 +6,4 @@ import Test.Hspec.JUnit.Formatter.Env as Formatter hook :: Spec -> Spec-hook = Formatter.whenEnabled Formatter.add+hook = Formatter.register