Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test when a feature was added to Perl?

Are there any services similar to codepad that will allow you to test Perl constructs on old versions of perl?

Ideally, a system where you could enter an expression and it will tell you the oldest version of perl that it will work with.

Of course it's possible to use CPANTS for this, but that seems like an abuse of the service (if only for making the BackPan bigger). And it could take several days/weeks to get decent test coverage on old versions.

like image 484
Eric Strom Avatar asked Mar 23 '10 14:03

Eric Strom


4 Answers

You might find Perl::MinimumVersion helpful. Use the provided perlver utility to scan your code.

like image 129
daotoad Avatar answered Oct 21 '22 14:10

daotoad


I think that if I was concerned, I'd build salient versions of Perl on my machine and test them. Actually, that's more or less what I do anyway. My Solaris 10 machine has:

lrwxrwxrwx   1 jleffler rd            26 Mar  6  2008 v5.10.0 -> v5.10.0-32bit-multiplicity
drwxr-xr-x   3 jleffler rd           512 Jan 10  2008 v5.10.0-32bit
drwxr-xr-x   6 jleffler rd           512 Mar  7  2008 v5.10.0-32bit-multiplicity
drwxr-xr-x   3 jleffler rd           512 Jan 10  2008 v5.10.0-64bit
lrwxrwxrwx   1 jleffler rd            13 Jan 29 21:07 v5.10.1 -> v5.10.1-64bit
drwxr-xr-x   6 jleffler rd           512 Jan 29 21:43 v5.10.1-64bit
drwxr-xr-x   5 jleffler rd           512 May  6  2003 v5.5.3
lrwxrwxrwx   1 jleffler RAND          11 Mar 21  2007 v5.6.1 -> v5.6.1-full
drwxr-xr-x   5 jleffler rd           512 May  6  2003 v5.6.1-full
drwxr-xr-x   5 jleffler rd           512 Feb  5  2008 v5.8.7-multi
lrwxrwxrwx   1 jleffler rd            19 Mar 24  2007 v5.8.8 -> v5.8.8-32bit-sun-cc
drwxr-xr-x   6 jleffler rd           512 Mar 25  2007 v5.8.8-32bit-sun-cc
drwxr-xr-x   5 jleffler rd           512 Feb 13  2006 v5.8.8-64bit-thread-multi
drwxr-xr-x   3 jleffler rd           512 Mar 20  2008 v5.8.8-gcc-3.4.6

So, that's 5.5.3, 5.6.1, 5.8.7, 5.8.8, 5.10.0 and 5.10.1 installed; I have the source for other versions too:

-rw-r--r--   1 jleffler rd       2171936 Apr 12  2001 perl-5.004_04.tar.bz2
-rw-r--r--   1 jleffler rd       3023320 Aug 31  1999 perl-5.005_03.tar.bz2
-rw-r--r--   1 jleffler rd       12426022 Dec 18  2007 perl-5.10.0.tar.bz2
-rw-r--r--   1 jleffler rd       11608061 Jan 29 12:32 perl-5.10.1.tar.bz2
-rw-r--r--   1 jleffler rd       4430438 Mar 29  2000 perl-5.6.0.tar.bz2
-rw-r--r--   1 jleffler rd       4864306 Apr  8  2001 perl-5.6.1.tar.bz2
-rw-r--r--   1 jleffler rd       5142605 Aug 16  2005 perl-5.6.2.tar.bz2
-rw-r--r--   1 jleffler rd       8618487 Jul 18  2002 perl-5.8.0.tar.bz2
-rw-------   1 jleffler rd       9410641 Sep 29  2003 perl-5.8.1.tar.bz2
-rw-r--r--   1 jleffler rd       9424944 Nov  5  2003 perl-5.8.2.tar.bz2
-rw-r--r--   1 jleffler rd       9509716 Jan 14  2004 perl-5.8.3.tar.bz2
-rw-r--r--   1 jleffler rd       9598489 Apr 21  2004 perl-5.8.4.tar.bz2
-rw-r--r--   1 jleffler rd       9464689 Jul 19  2004 perl-5.8.5.tar.bz2
-rw-r--r--   1 jleffler rd       9693085 Nov 27  2004 perl-5.8.6.tar.bz2
-rw-r--r--   1 jleffler rd       9839086 Jun 15  2005 perl-5.8.7.tar.bz2
-rw-r--r--   1 jleffler rd       10123359 Feb 13  2006 perl-5.8.8.tar.bz2
-rw-r--r--   1 jleffler rd       11121414 Dec 14  2008 perl-5.8.9.tar.bz2

@Ether asked:

Do you have a script which will run a particular module, script or unit test against all versions in sequence and collate the results? Such a utility might be really handy as a chrooted/sandboxed CGI.

No, but I haven't needed it. It's basically trivially, though:

for perl in /usr/perl/v5.*.?
do
    echo $(basename $perl)
    $perl/bin/perl "$@"
done

Basically, for each of the Perl directories in /usr/perl/, run the perl from the bin directory on the given set of arguments. Watch the output...

The difficulty is in deciding what constitutes pass/fail. Obviously, the core of the loop could be:

    if $perl/bin/perl "$@" >/dev/null 2>&1
    then echo ok $perl
    else echo not ok $perl
    fi

That's faintly similar to the TAP output. To make it formally equivalent (using bash or Korn shell):

test=0
max=$(ls -d /usr/perl/v5.*.? | wc -l | sed 's/ //g')
echo 1..$max
for perl in /usr/perl/v5.*.?
do
    ((test = test + 1))
    if $perl/bin/perl "$@" >/dev/null 2>&1
    then echo     ok $test - $perl
    else echo not ok $test - $perl
    fi
done

Here's an example of running it:

$ ksh test.perl -e 'exit 0'
1..6
ok 1 - /usr/perl/v5.10.0
ok 2 - /usr/perl/v5.10.1
ok 3 - /usr/perl/v5.5.3
ok 4 - /usr/perl/v5.6.1
ok 5 - /usr/perl/v5.8.8
not ok 6 - /usr/perl/v5.8.8-gcc-3.4.6
$

That shows a limitation in shell scripts and their globbing facilities (I'd like to limit the 'star' to a series of digits). The Perl that fails does so because the bin directory doesn't contain a copy of Perl; I needed to save space at some point! It would not be hard to convert the shell script into a Perl script, of course.

like image 34
Jonathan Leffler Avatar answered Oct 21 '22 14:10

Jonathan Leffler


If you're looking for when a module was introduced to core Perl, you can use Module::CoreList.

If you'd like to help develop a system like codepad for Perl, search for "PITA testing".

Specifically, if you want a utility to download and install a number of Perl binaries to test your code, you can look at the programs in PITA-Setup-Perl/bin.

like image 43
sachmet Avatar answered Oct 21 '22 15:10

sachmet


I know perlcritic is capable of finding a few cases, but in general you will have to look it up in google or in perldelta files. In particular, you may want to look at the deltas for 5.6 5.8 and 5.10 and maybe even the upcoming 5.12

like image 4
Leon Timmermans Avatar answered Oct 21 '22 16:10

Leon Timmermans