#!/usr/bin/perl -w

use strict;

my $verbose = 0;
while (defined $ARGV[0] && ("-v" eq $ARGV[0])) {
    $verbose++;
    shift @ARGV;
}

sub mysys {
    my $cmd = shift;

    if ($verbose > 1) {
	print "$cmd\n";
    }
    return system($cmd);
}

sub runone {
    my ($t, $p, $d, $tname) = @_;
    my $res;

    $p = "" if (!defined $p);
    $d = "" if (!defined $d);
    $tname = $t if (!defined $tname);
    mkdir $tname, 0755;
    chdir $tname;
    $res = mysys("gcc $d -g -o $t ../$t.c -lcyrus");
    if (!$res) {
	$res = mysys("./$t $p < ../$t.INPUT > $t.TEMP");
	$res = mysys("cmp -s $t.TEMP ../$t.OUTPUT");
    }
    if ($res) {
	print "$tname FAILED\n";
    } elsif ($verbose) {
	print "$tname ok\n";
    }
    chdir "..";
}

runone("cyrusdb", undef, "-DBACKEND=cyrusdb_flat");
runone("cyrusdb", undef, "-DBACKEND=cyrusdb_db3 -ldb", "cyrusdb_db3");
