in reply to Testing CPAN module that requires credentials

I have some tests in modules that require user input. I put them in a test.pl file so that tests won't fail with auto build processes (like that of Activestate's PPM) but also allow the user to supply information if they want to run the full test suite.

Have a look at the test.pl script in the Cisco::Management module for example. The test.pl script asks for a router IP address and SNMP community strings to run the full set of tests. Pressing just enter skips the suite entirely. That may be a way to go - put your regular tests in a file and the ones that require authentication - put them in a test file that prompts the user for input (their own credentials) or allows them to skip the tests.

  • Comment on Re: Testing CPAN module that requires credentials

Replies are listed 'Best First'.
Re^2: Testing CPAN module that requires credentials
by Marseille07 (Acolyte) on Jan 07, 2012 at 20:44 UTC
    Thanks for your reply. I'll take a look at test.pl in the module and learn the tricks from there.

      Don't.

      Doing your own prompting and reading from STDIN is bad practice. Instead use ExtUtils::MakeMaker's prompt() subroutine. It will cope properly with things like buffering when CPAN.pm's output is being piped to tee(1) or if it is being driven by Expect, and with the user setting PERL_MM_USE_DEFAULT.

        A better idea, don't prompt at all, no matter what :)

        Simply document the appropriate enviroment variable

        $ENV{PERL_MYCPANMODULE_CONFIG}='foo.yaml'; $ENV{PERL_MYCPANMODULE_USERPASS}='user:pass';

        Or Makefile.PL switch

        perl Makefile.PL --userpass=user:pass
        and then Makefile.PL stores that in MYCPANMODULE.ini next to Makefile.PL for use during  make test or some such

        I believe Module::Build provides something out of the box for this way, I might be wrong