Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Writing tests when you don't know what the output should be

by nysus (Parson)
on May 17, 2016 at 21:01 UTC ( [id://1163265]=note: print w/replies, xml ) Need Help??


in reply to Re: Writing tests when you don't know what the output should be
in thread Writing tests when you don't know what the output should be

Regarding the files, I don't know what the files will be named ahead of time so how do I test if the module is loading the correct ones? If I create dummy files to run tests on, it will interfere with the proper operation of the actual module.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

  • Comment on Re^2: Writing tests when you don't know what the output should be

Replies are listed 'Best First'.
Re^3: Writing tests when you don't know what the output should be
by stevieb (Canon) on May 17, 2016 at 21:09 UTC

    How do you plan on deciding which files to load then? Will they be defined by name in some sort of configuration?

    You should be setting up an actual distribution structure. See Module::Starter. All of your tests go in t/, and you can then create a test directory structure and associated data in for eg: t/data/. Your module should have a method or something that allows a script to tell it what directory to look in for the files (the tests in the t/*.t test files would do this).

    Setting up a proper testing infrastructure allows you to very precisely control everything, and easily and quickly add new sample data and new tests going forward while making changes, or particularly when a bug has been found.

    Any chance you could show us the code you have so far?

      Sure thing:

      package DupEventChecker; use Modern::Perl; use IO::Dir; use Moose; has 'dir' => ( is => 'ro', isa => 'IO::Dir', writer => '_set_dir' ); sub BUILD { my $self = shift; my $args = shift; $self->_set_dir(IO::Dir->new($args->{dir_name})); } return 1;

      And here's the script:

      use Modern::Perl; use DupEventChecker; my $dir = DupEventChecker->new({dir_name => '.'});

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        OK, try adding something like
        use FindBin; use Test::More tests => 3; use Test::Exception; dies_ok { 'DupEventChecker'->new } 'dir_name not provided'; my $checker = 'DupEventChecker'->new(dir_name => $FindBin::Bin); isa_ok $checker, 'DupEventChecker'; my ($itself) = grep { 0 <= index $0, $_ } $checker->dir->read; ok $itself, 'test script found';

        BTW, dir_name is required, but it isn't apparent from the declaration. dir could also have a default (e.g. '.', Cwd::getcwd or File::HomeDir->my_home).

        Update: Example added to the BTW. Update 2: The example was improved.

        ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re^3: Writing tests when you don't know what the output should be
by afoken (Chancellor) on May 17, 2016 at 21:08 UTC
    Regarding the files, I don't know what the files will be named ahead of time so how do I test if the module is loading the correct ones? If I create dummy files to run tests on, it will interfere with the proper operation of the actual module.

    Then your module lacks a parameter telling it WHERE to look for the files. During the tests, you want to look for test input files usually below the "t" directory, not where the production files are.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1163265]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2024-03-29 15:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found