Changeset 251

Show
Ignore:
Timestamp:
02/18/08 10:34:53 (9 months ago)
Author:
mbr
Message:

first working version of the test suite

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gpgdir/trunk/test/gpgdir_test.pl

    r248 r251  
    2929# 
    3030 
     31use File::Find; 
    3132use strict; 
     33 
     34#=================== config defaults ============== 
     35my $gpgdirCmd = '../gpgdir'; 
     36 
     37my $conf_dir   = 'conf'; 
     38my $output_dir = 'output'; 
     39my $logfile    = 'test.log'; 
     40my $tarfile    = 'gpgdir_test.tar.gz'; 
     41 
     42my $cmd_stdout = "$output_dir/cmd.stdout"; 
     43my $cmd_stderr = "$output_dir/cmd.stderr"; 
     44#==================== end config ================== 
     45 
     46my $test_num  = 0; 
     47my $PRINT_LEN = 68; 
     48my $failed_tests = 0; 
     49my $successful_tests = 0; 
     50 
     51### execute the tests 
     52&test_driver('(Setup) gpgdir program compilation', \&perl_compilation); 
     53&test_driver('(Setup) Command line argument processing', \&getopt_test); 
     54 
     55exit 0; 
     56#======================== end main ========================= 
     57 
     58sub test_driver() { 
     59    my ($msg, $func_ref) = @_; 
     60 
     61    &dots_print($msg); 
     62    if (&{$func_ref}) { 
     63        &pass(); 
     64    } else { 
     65        $failed_tests++; 
     66    } 
     67    $test_num++; 
     68    return; 
     69} 
     70 
     71sub perl_compilation() { 
     72    unless (&run_cmd("perl -c $gpgdirCmd")) { 
     73        return &print_errors("fail ($test_num)\n[*] " . 
     74            "$gpgdirCmd does not compile"); 
     75    } 
     76    return 1; 
     77} 
     78 
     79sub getopt_test() { 
     80    if (&run_cmd("$gpgdirCmd --no-such-argument")) { 
     81        return &print_errors("fail ($test_num)\n[*] $gpgdirCmd " . 
     82                "allowed --no-such-argument on the command line"); 
     83    } 
     84    return 1; 
     85} 
     86 
     87sub dots_print() { 
     88    my $msg = shift; 
     89    &logr($msg); 
     90    my $dots = ''; 
     91    for (my $i=length($msg); $i < $PRINT_LEN; $i++) { 
     92        $dots .= '.'; 
     93    } 
     94    &logr($dots); 
     95    return; 
     96} 
     97 
     98sub run_cmd() { 
     99    my $cmd = shift; 
     100    my $rv = ((system "$cmd > ${cmd_stdout}.$test_num " . 
     101            "2> ${cmd_stderr}.$test_num") >> 8); 
     102    if ($rv == 0) { 
     103        return 1; 
     104    } 
     105    return 0; 
     106} 
     107 
     108sub pass() { 
     109    &logr("pass ($test_num)\n"); 
     110    $successful_tests++; 
     111    return; 
     112} 
     113 
     114sub logr() { 
     115    my $msg = shift; 
     116 
     117    print STDOUT $msg; 
     118    open F, ">> $logfile" or die $!; 
     119    print F $msg; 
     120    close F; 
     121    return; 
     122}