Cagao has asked for the wisdom of the Perl Monks concerning the following question:

I've got a few test scripts that I'd like to build into a nice suite that will ask for user-input much like what is seen when installing CPAN modules.

currently I've just got a basic shell script doing...

prove -Isite/cgi-bin/ t

One of my test scripts needs some user-input, simply to either carry on or Ctrl+C out of it.

What options do I have? Currently I've put this check into the test script that requires the validation (by just reading<STDIN>, which doesn't get displayed unless the verbose flag is set when using 'prove'.

Should I be looking to TAP::Harness for this, and if so, could someone supply a bit of example code?

Thanks,

Cagao

Replies are listed 'Best First'.
Re: Interactive tests
by moritz (Cardinal) on Apr 17, 2008 at 21:10 UTC
    Please don't prompt for anything in tests - tests are so useful because the can be exeucted automatically.

    If you want a user to press Ctrl+C, you can send it a SIGINT, a interrupt signal instead.

    You can either let the user provide values through configuration files or environment variables.

    If you need interaction I'd suggest to skip the interactive tests unless an environment variable like $ENV{TEST_INTERACTVE} or something is set.

      Yup, see where you're coming from, and it makes perfect sense.

      The test file in question relies on some entries in the (test/local) database, so perhaps a nice big warning is enough.

      I just don't want future users being a bit baffled as to why tests may fail.
        The nice solution is to detect if a test database can be accessed, and if not print a warning and skip the tests.
Re: Interactive tests
by andreas1234567 (Vicar) on Apr 18, 2008 at 06:18 UTC
    Perl Testing by Ian Langworth and chromatic has a section on Testing Interactive Programs (p169). There is an example which uses Test::Expect to handle user interaction.
    --
    When you earnestly believe you can compensate for a lack of skill by doubling your efforts, there's no end to what you can't do. [1]