converting lists to array for testing purposes

J

John

Hi all,

I am trying to write a test and the result expected from the module is
a list of lists. I will use Test module to check if the result is the
same than the expected.

Anyone know how this can be done? I could compare value by value or
parse the Data::Dumper value into an String but I am sure this is
something trivial to do in another way. As trivial that I can find how
on the reference.


Thanks for helping me
J
 
F

fifo

I am trying to write a test and the result expected from the module is
a list of lists. I will use Test module to check if the result is the
same than the expected.

Do you mean something like this:

#!/usr/bin/perl
use strict;
use warnings;
use Test::Simple tests => 2;

sub test {
grep(ref eq 'ARRAY', @_) == @_
}

ok(test returns_list_of_arrayrefs());
ok(test returns_something_else());

sub returns_list_of_arrayrefs {
([1, 2, 3], [4, 5], [])
}

sub returns_something_else {
([1, 2, 3], 45, [])
}
 
A

Anno Siegel

John said:
Hi all,

I am trying to write a test and the result expected from the module is
a list of lists. I will use Test module to check if the result is the
same than the expected.

Anyone know how this can be done? I could compare value by value or
parse the Data::Dumper value into an String but I am sure this is
something trivial to do in another way. As trivial that I can find how
on the reference.

Try Test::More (a standard module, like Test). It has methods that help
with this kind of thing. eq_array should be what you're looking for.

Anno
 
T

Tore Aursand

I am trying to write a test and the result expected from the module is a
list of lists. I will use Test module to check if the result is the same
than the expected.

Have you had a look at these modules?

Test::More
Test::Differences

You can find them at CPAN:

<http://www.cpan.org/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top