MyNixOS website logo
Description

Golden testing provider for tasty with muti-line diff output.

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

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 ?
Metadata

Version

0.0.2

Platforms (77)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows