main-tester

Capture stdout/stderr/exit code, and replace stdin of your main function.

https://gitlab.com/igrep/main-tester#readme

LTS Haskell 22.43:0.2.0.1
Stackage Nightly 2024-12-08:0.2.0.1
Latest on Hackage:0.2.0.1

See all snapshots main-tester appears in

Apache-2.0 licensed by Yuji Yamamoto
Maintained by [email protected]
This version can be pinned in stack with:main-tester-0.2.0.1@sha256:49eab84f96bb70e1530f4a256d9c41a7b4175c8c372b68e900074a61e9d1f073,2030

Module documentation for 0.2.0.1

main-tester

Capture stdout/stderr/exit code, and replace stdin of your main function.

Why?

Against the best practice, I often prefer large, end-to-end (E2E) tests.
Because:

  • E2E tests can directly test your users’ requirement.
  • E2E tests can detect bugs caused by misassumption of external components
    • Which happenes relatively more often than the others, according to my experience.
  • I often write small programs where E2E tests are sufficient.

This library main-tester provides utility functions for E2E testing of your CLI applications.
With main-tester, You can test your apps with arbitrary stdin data, check their output and exit code.

Comparison with silently and System.IO.Fake

  • Can test exit code of your main.
  • All input and outputs are strict bytestrings except the command line arguments, which is very important when testing with non-UTF8 input and output.
  • Currently doesn’t support suppressing stdout and stderr (Pull request welcome!).

Usage

See the document of Test.Main module.

Changes

0.2.0.1

  • Fix: Fix Handle leak (!2)

0.2.0.0

  • Breaking change:
    • Add prException field to ProcessResult.
    • Now captureProcessResult catches any exception (including ExitCode) thrown by the given action (usually your main function).
      • The caught exception is available by prException function (except ExitCode).
  • :new: Add withEnv function.

0.1.0.0

  • Initial release.