Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Unit testing with Perl

by arc_of_descent (Hermit)
on May 25, 2009 at 13:38 UTC ( #766031=note: print w/replies, xml ) Need Help??

in reply to Unit testing with Perl

You should start by using the Test::Simple module in your Perl test scripts. This will give you a good idea on what testing in Perl is about. Its simply just evaluating a condition (in your case, whether the list processed by the C program is sorted), and then declaring a pass/fail. To automate the test script, you have to first write the routines which run the C program (via system possibly), redirect its output to file, read the file into an Perl array, etc.

Next, you can read about Test::More and Test::Deep.

Here's some sample code:
use Test::More; use Test::Deep; my @input = (5, 8, 12, 9, 78, 1, 5); my @expected = (1, 5, 5, 8, 9, 12, 78); my $i_file = "input.txt"; my $o_file = "output.txt"; my $bin = '/bin/c_program'; write_sample_file(\@input, $i_file); # run the C program system "$bin < $i_file > $o_file"; my @processed = get_data($o_file); cmp_deeply (\@processed, \@expected, 'results are sorted');

Replies are listed 'Best First'.
Re^2: Unit testing with Perl
by n4nature (Novice) on May 25, 2009 at 13:50 UTC
    This is going to help immensely. Thank you.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://766031]
[MidLifeXis]: ISTR having a couple of issue based on undeclared dependencies around the time I was looking at that module on my last project, but cannot say if that was the module that I had the dependency issues with.
[MidLifeXis]: (5.22 at that time)
[MidLifeXis]: Yeah, I know, really helpful :-)
[Corion]: If all else fails, Spreadsheet::XLSX should be "installable" by manually copying the files, provided that the prerequisites are met
[thezip]: It fails in the "formatted 2-digit numeric" tests
[thezip]: Okay Corion, that's what I wanted to hear. Thanks!
[Corion]: Oh, a test failure... Just force-install it then? --force and potentially --notest to skip the tests alltogether ?
[ambrus]: thezip: is Activestate Perl usable for your scenario instead?
[MidLifeXis]: Yeah, --notest is good, not sure I would do --force.
[thezip]: It fails 2/10 tests in that group. What are the ramifications if I force it? What should I look for for?

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (13)
As of 2017-03-23 17:14 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (290 votes). Check out past polls.