tasty-mgolden: Golden testing provider for tasty with muti-line diff output

[ bsd3, library, program, testing ] [ Propose Tags ] [ Report a vulnerability ]

Please visit the README at https://github.com/mbj/tasty-mgolden#readme for usage information.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Flags

Manual Flags

NameDescriptionDefault
development

Run GHC with development flags

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.0.1, 0.0.2
Dependencies ansi-terminal (>=0.9 && <0.11), base (>=4.12 && <=4.15), Diff (==0.3.4 || >=0.4 && <0.5), filepath (>=1.4.2 && <1.5), tasty (>=1.3.1 && <1.4), tasty-expected-failure, tasty-hunit, tasty-mgolden, text (>=1.2 && <1.3) [details]
Tested with ghc ==8.6.5 || ==8.8.4 || ==8.10.2
License BSD-3-Clause
Author Markus Schirp <mbj@schirp-dso.com>
Maintainer Markus Schirp <mbj@schirp-dso.com>
Category Testing
Home page https://github.com/mbj/tasty-mgolden#readme
Bug tracker https://github.com/mbj/tasty-mgolden/issues
Source repo head: git clone https://github.com/mbj/tasty-mgolden
Uploaded by mbj at 2020-09-27T01:50:19Z
Distributions
Reverse Dependencies 1 direct, 1 indirect [details]
Executables tasty-mgolden-example
Downloads 374 total (2 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2020-09-27 [all 1 reports]

Readme for tasty-mgolden-0.0.2

[back to package description]

CI

tasty-mgolden

Text based golden tests for tasty, with multi line (colored) diff expectation failure reporting.

Basically this package can turn any IO Text action into a golden test via providing a FilePath.

This package is the small brother of tasty-golden which also implements the same golden testing pattern.

tasty-mgolden is less generic and more opinionated than its bigger brother. But for that reason can also offer more ergonomic defaults for its core use case:

Golden testing for IO Text actions. Where:

  • The text value is assuemd to contain multiple lines.
  • The expectation failures can be rendered nicely in multi line diffs.
  • The diff lines are colored via the tasty infrastructure
  • The diff rendering is not done via the external diff command, but uses the Diff package.

Expectation diffs are rendered like developers are used to:

  • Removed lines rendered in red.
  • Added lines in green.

Usage

This is taken from the example directory in the repository.

To run these execute from repository root:

stack build
stack exec tasty-mgolden-example

Contents of example/example-a.txt

foo
bar

Contents of example/example-b.txt

foo
bar

Contents: example/Test.hs

import Test.Tasty
import Test.Tasty.MGolden

main :: IO ()
main = defaultMain $ testGroup "golden tests"
  [ goldenTest "example-a" "example/example-a.txt" $ pure "foo\nbar\n"
  , goldenTest "example-b" "example/example-b.txt" $ pure "foo\nbaz\n"
  ]

Output:

golden tests
  example-a: OK
  example-b: FAIL
 foo
-bar
+baz

1 out of 2 tests failed (0.00s)

Passing the --update flag to accept the changes:

golden tests
  example-a: OK
  example-b: OK
    UPDATE

All 2 tests passed (0.00s)

TODOs

PRs on these are welcome.

  • Improve the multi line diff reporting to only show a minimal context around the changed hunks.
  • Add line markers in unified diff format.
  • Change to pathtype from filepath
  • Future? Upstream this to tasty-golden ?