root/tests/testsuite.pl

Revision 34e4d9386f59a6ea555730f8ba40778ee71e3fec, 2.3 kB (checked in by Philip Herron <redbrain@…>, 2 years ago)

testsuite cleanup and additions

  • Property mode set to 100755
Line 
1#!/usr/bin/perl -w
2# -----------------------------
3# Test Suite Runner:
4# ./testsuite -c <crules bin-path> -t <test-folder> -r <results>
5#
6# author: RedBrain ( Philip Herron )
7# maintainer: RedBrain
8# -----------------------------
9
10use utf8;
11
12use strict;
13use IPC::Open3;
14use Getopt::Long;
15use Pod::Usage;
16
17use Test::Simple tests => 18;
18
19my $crl_bin_path = '../src/crules';
20my $crl_test_path = 't/';
21my $crl_res_path = 'r/';
22
23sub check_results {
24    my $oa = $_[0];
25    my $ob = $_[1];
26    my $curr_test = $_[2];
27
28    ok( $oa eq $ob, "Test: $curr_test" );
29}
30
31sub get_correct_results {
32
33    my $tr = substr( $_[0], 0, -4);
34    $tr = substr( $tr, 2 );
35    my $trr= $tr . ".r";
36    my $rr = $crl_res_path . $trr;
37
38    open( DAT, $rr ) || die("Error: opening results file <$rr>!\n");
39    my @raw_data = <DAT>;
40    close(DAT);
41
42    my $len= scalar(@raw_data);
43    my $str; my $it= 0;
44    while ( $it < $len ) {
45        if ( $raw_data[ $it ] =~ /TestIdent/ ) {
46            print "Testing: $raw_data[ $it ]";
47        }
48        else {
49            $str = $str . $raw_data[ $it ];
50        }
51        $it++;
52    }
53
54    return ( $str );
55}
56
57sub exec_test {
58    # the test should be the first argument!
59    my $ct = $_[0];
60    my($wtr, $rdr, $err);
61    use Symbol 'gensym'; $err = gensym;
62
63    print "Atempting to run test: $ct!\n";
64    my $time1 = time;
65    my $pid = open3( $wtr, $rdr, $err,
66                     "$crl_bin_path", "$ct" );
67
68    waitpid( $pid, 0 );
69    my $child_exit_status = $? >> 8;
70    my @rstdout = <$rdr>;
71    if( $child_exit_status != 0 ) {
72        die("test $ct did not exit cleanly exit code <$child_exit_status>!\n");
73    }
74
75    my $time2 = time; my $lent= $time2 - $time1;
76    print "Test $ct took: $lent!\n";
77
78    my $len= scalar(@rstdout);
79    my $str; my $it= 0;
80    while ( $it < $len ) {
81        $str = $str . $rstdout[ $it ];
82        $it++;
83    }
84    return ( $str );
85}
86
87sub main {
88
89    my @t_files = <$crl_test_path*.crl>;
90    my @r_files = <$crl_res_path*.r>;
91
92    ## find lengths!
93    my $tl = scalar( @t_files );
94    my $rl = scalar( @r_files );
95
96    if( $tl == $rl )
97    {
98        foreach( @t_files ) {
99            my $retval_t = &exec_test( $_ );
100            my $retval_r = &get_correct_results( $_ );
101            &check_results( $retval_t, $retval_r, $_ );
102            print "\n"; # just to space out the verbose output!
103        }
104    }
105    else
106    {
107        print "Error: un-equal number of tests and results!\n";
108        # work on giving more details...
109    }
110}
111
112&main( );
Note: See TracBrowser for help on using the browser.