Greetings fellow monks,
for my studies at the university I recently endeavored with a friend to prepare the best infrastructure for the long term projects we are to be given later this year.
Amongst other things we set up a continuous integration environment, an xmpp server for team communications and that kind of things.
Since we both are big fans of test driven development and I fell in love with the TAP protocol as I started writing my own modules I decided to give this library a shot. After some manipulations I got it to work and started writing on scripts that would allow us to easily build and centralize test logs.
Thing is in previous projects we did that kind of thing in big and unwieldy bash scripts. I decided to do it in perl but hit quite the roadblock : my friend does not know perl and has no intention to learn it in the foreseeable future.
I prepared the following solution :
One makefile that calls the build.pl script (with whatever parameter are needed) and a run_test.pl script that goes through all the files in the tests directory, run all tests, log results, if some tests fail it creates two files, one for all failed test for the file tested and another with all the tests for the file tested to give it some context.
here is build.pl
#!/usr/bin/perl
use strict;
use warnings;
use File::Path;
use Cwd;
if ($ARGV[0]=~ 'all'){
mkdir 'logs';
chdir 'logs';
my $logwd = getcwd();
chdir '..';
my $basewd = getcwd();
chdir 'tests';
my @files = glob "*";
foreach my $file(@files){
my $outwd = $logwd.'/'.$file;
if(-d $file){
mkdir "$logwd/$file";
chdir $file;
if(`../run_tests.pl $outwd` =~ 0){
rmtree($outwd);
}
}
}
chdir $basewd;
`make unchecked`;
}
elsif($ARGV[0]=~/clean/){
my @ofiles = glob "*.o";
foreach my $file(@ofiles){
print "cleaning $file\n";
unlink $file;
}
}
here is run_tests.pl :
#!/usr/bin/perl
use strict;
use warnings;
`make tests`;
my $logwd = $ARGV[0];
my $pid = open(my $kid_to_read,"-|");
if($pid == 0){
print `./tests`;
}
else{
open(my $failed_tests,'>',"$logwd/test_fail.log");
open(my $test_output,'>',"$logwd/test_out.log");
my $fail = 0;
while(<$kid_to_read>){
my $line = $_;
if($line =~ /\Anot ok/){
print $failed_tests $line;
$fail++;
}
print $test_output $line;
}
close $test_output;
close $failed_tests;
`make clean`;
print $fail;
}
and the main project makefile :
all:
./build.pl all
make clean
.PHONY: clean
clean:
./build.pl clean
unchecked:
The unchecked target is used to build the project without running the test scripts.
It is important to take into account that inside the tests folder each subfolder contains its own makefile to build the test executable and then clean after tests have been run.
As always I post here hungry for ways to make that code better, more efficient or solve overlooked issues or design problems.
Also I hope that someone might have a use for it ^^
Kind Regards.