• Iustin Pop's avatar
    Rework CLI modules and tests · 51000365
    Iustin Pop authored
    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
    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: default avatarIustin Pop <iustin@google.com>
    Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
Makefile.am 45.9 KB