treebird/test/test.pl
nekobit 253f55dd36 Improved unit testing
FossilOrigin-Name: 786b4080abc83f076704b33ec884236a3733fef9a5a276d7df54fa35d228015b
2022-07-28 03:36:33 +00:00

39 lines
807 B
Perl
Executable file

#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $FAIL = "\033[91m";
my $OK = "\033[96m";
my $SUCCESS = "\033[92m";
my $ENDC = "\033[0m";
sub read_file
{
my ($filename) = @_;
open my $fh, '<', $filename or die "Error opening $filename: $!";
do { local $/; <$fh> };
}
my @files_glob = glob('./test/unit/t*.bin');
my $fail = 0;
foreach my $bin (@files_glob)
{
my $content = read_file(substr($bin, 0, -4) . ".c");
my ($name, $valgrind) = $content =~ /\/\*.*INFO name='(.*?)'.*valgrind=(.*?)\s\*\//s;
if (system(($bin)))
{
print "$FAIL -- !! -- Test '$name' failed!$ENDC\n";
$fail = 1;
last;
}
else {
print "$OK -- OK -- Test '$name' passed$ENDC\n";
}
}
print "$SUCCESS -- All Tests passed!$ENDC\n" unless $fail;