MyNixOS website logo
Description

Alternative doctest implementation that extracts comments to modules.

doctest-extract lets you write test examples and QuickCheck properties in Haddock comments and extracts them to test modules. It means that the user sees your tests in the documentation and knows that the examples and properties are machine-tested, or at least, she can run the tests herself.

I found the barrier to write tests much lower when I do not need to write new test modules but just add some lines to the Haddock comments. I do not need to think of test names or filling test data structures. The test identifier is the module name and the line number and if a test fails I can easily jump to the failing code.

Differences to the original GHCi-based implementation of doctest:

Pros:

  • Package versions for tests are consistent with tested library

  • Tests run much faster, especially QuickCheck property tests

  • No dependency on GHCi or GHC-as-library

  • The tested package need not be ready for compilation. Our simple parser requires only clearly recognizable Haskell comments.

  • QuickCheck properties do not cause confusing type error messages when actually only identifiers are missing.

  • You can inspect extracted modules

  • doctest collects tests from the transitive hull of imports of the specified modules. This might help you to keep the list of modules short. doctest-extract only processes the specified modules and thus allows you to focus on a module for development of tests.

  • With option --verbose test source path and line number are formatted such that Emacs allows you to click and jump to the test definition.

  • Report success only of real tests. doctest reports successful imports and definition of helper types and functions as successful tests. This makes it hard to monitor the number of real tests, e.g. whether some tests have been dropped by accident.

Cons:

  • Cannot test for output of IO functions or error messages from partial functions.

  • All free variables in QuickCheck properties must be all-quantified using lambda. (Could be even seen as an advantage for the reader of your doctests.)

  • No support for a single-line let (as in a do-block) as an example.

  • The Test module does not automatically import modules that the tested module imports. Thus, you usually have to add a setup section with required imports.

  • You need tools additional to Cabal, e.g. make and a Makefile, in order generate test modules.

See packages utility-ht, apportionment or pathtype for packages with working setups of doctest-extract.

Alternatives: cabal-docspec, cabal-doctest

Metadata

Version

0.1.2

Maintainers (1)

Executables (1)

  • bin/doctest-extract-0.1

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • 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