Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Monday December 08, 2008
06:23 AM

Running Tests In Multiple Languages

[ #38048 ]

Recently on the TAP development list, the question of running tests in multiple languages came up. The example was PHP and Perl, but I'll show Ruby and Perl as I don't have PHP installed on this machine.

First, create the following Ruby program (adjusting the shebang line to taste):

#!/usr/bin/env ruby -w


puts '1..2';
puts 'ok 1 - ruby 1';
puts 'ok 2 - ruby 2';

Now run that with the prove utility which ships with Test::Harness.

prove -v test.rb
test.rb ..
ok 1 - ruby 1
ok 2 - ruby 2
test.rb:3: warning: unused literal ignored
All tests successful.
Files=1, Tests=2,  0 wallclock secs ( 0.03 usr  0.01 sys +  0.00 cusr  0.01 csys =  0.05 CPU)
Result: PASS

Note that we're really running Ruby code, even with a Ruby error message. How does that work? You can run perl test.rb and you'll see that when Perl encounters the shebang line, it's smart enough to DWIM! This means that if you have shebang lines, prove will DWIM also. So, let's assume that our Ruby tests end in .rbt, our PHP tests end in .phpt and Perl tests end in .t:

alias myprove='find t/ -name '*.t' -or '*.phpt' -or '*.rbt' | prove -

Then just run myprove and you can run test suites written in multiple languages. (You can do this with tests without shebang lines, but that's another post).

Note that you can't just use xargs here. I had originally suggested that, but Andy Lester pointed out to me that this would invoke prove multiple times. A colleague of mine explained to me that xargs will cause this behavior if the generated list is too large -- as often happens with a find command.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.