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.


In reply to C test suite management with perl by QuillMeantTen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.