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

What do you consider allowable internet access for a CPAN module test suite?
  • Comment on allowable internet access for a CPAN module test suite?

Replies are listed 'Best First'.
Re: allowable internet access for a CPAN module test suite?
by Corion (Patriarch) on Jun 14, 2009 at 19:03 UTC

    "None"

    WWW::Mechanize for a long time did tests against live sites, which was a source of constant problems as the reachability of those sites was spotty or the content changed. Hence, a CPAN module should never use outside contact for its test suite, except when that outside contact is the main reason for the module. For example, Finance::Bank::Postbank_DE does tests against the live (demo) website it is automating, because that is its only reason of existence.

    Update: Fixed module name, spotted by LanX, thanks!

Re: allowable internet access for a CPAN module test suite?
by CountZero (Bishop) on Jun 14, 2009 at 19:34 UTC
    A CPAN module test suite should never access anything outside the users computer (and of course outside the CPAN-site it uses to download the modules) without asking and obtaining authorization.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: allowable internet access for a CPAN module test suite?
by graff (Chancellor) on Jun 14, 2009 at 20:41 UTC
    This is a bit beyond my own scope of knowledge at the moment, but if you really wanted to test any particular http (or ftp or ...) type of transaction within a test suite -- and if you really wanted to elaborate your module distro to do this thoroughly -- you could probably include scripts in your distro that would run on the local machine and emulate a suitable server; your test scripts would attach to it via "localhost" (127.0.0.1), and you just have to set it up to supply the responses you want to test on.

    (And then of course you'd need tests for the server script...)

    For example, the Catalyst bundle includes a handy "web server" that runs on your development machine, so you can work up a web app without it ever being exposed in any way on a real server until it's ready.

Re: allowable internet access for a CPAN module test suite?
by JavaFan (Canon) on Jun 14, 2009 at 20:52 UTC
    It depends. If your module for instance is an API to a certain site, than it only makes sense to actually connecting to the site. Also, if the purpose of a module is to connect to some remote server, then by all means, a module should have tests for that. It's no different than say, a DBD driver containing tests that actually connect to a database.

    This may require some setting up to be done by person running the test suite. Just be sure it's documented. And die with a sensible error message if no connection can be made.

Re: allowable internet access for a CPAN module test suite?
by Khen1950fx (Canon) on Jun 15, 2009 at 07:19 UTC
    If you have to do internet tests, then you might try LWP::Online. It's really simple. Just preface your tests like so:

    #!/usr/bin/perl use strict; use warnings; use LWP::Online ':skip_all'; LWP::Online::online();

    The only drawback is that it justs checks for http by default. If it works, then it'll come back true. If it doesn't work, it will come back with "Invalid or Unsupported Transport".