« Previous | Next » 

Revision 51000365

ID51000365958c1362ceb3c9a224f184aa64513c84
Parent 3ce788db
Child 5b11f8db

Added by Iustin Pop over 11 years ago

Rework CLI modules and tests

While investigating how we could test the Daemon.hs module, I realised
that we have a very, erm, sub-optimal situation:

- HTools/CLI.hs has a nice IO/pure separation testing in cmdline
parsing, which allows some basic functionality to be tested, but
uses direct 'read' in many options, which fails at runtime when
evaluating the argument, and not when parsing the options
- Daemon.hs lacks that, but has a much nicer 'reqWithConversion'
helper that can be used for nicer option parsing, and uses that +
tryRead instead of plain 'read'

Since this situation is very bad, let's clean it up. We introduce yet
another module, Common.hs, that holds functionality common to all
command line programs (daemons or not). We move the parsing to this
module, and introduce a type class to handle option types which
support --help/--version. This allows removal of duplicated code from
CLI.hs and Daemon.hs.

The other part of the patch is cleanup/rework of the tests for this
code: we introduce some helpers (checkOpt, passFailOpt,
checkEarlyExit) that can be used from the much-slimmer now tests for
CLI and Daemon. In the common module, we just test the yes/no helper
we have. Many new tests for boolean options and numeric options are
added.

A side change is the removal of the obsolete `--replay-count',
`--test-size' options (unused since commit 95f6c931, “Switch Haskell
test harness to test-framework”).

Signed-off-by: Iustin Pop <>
Reviewed-by: René Nussbaumer <>

Files

  • added
  • modified
  • copied
  • renamed
  • deleted

View differences