#!/bin/sh

# Script to summarize the results of a GPC Test Suite run
#
# Copyright (C) 1998-2000 Free Software Foundation, Inc.
#
# Authors: Matthias Klose <doko@cs.tu-berlin.de>
#          Frank Heckenbach <frank@pascal.gnu.de>
#
# This file is part of GNU Pascal.
#
# GNU Pascal is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# GNU Pascal is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Pascal; see the file COPYING. If not, write to the
# Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

# Find a good awk.
if test -z "$AWK"; then
  for AWK in gawk nawk awk ""; do
    if type "$AWK" 2>&1 | grep 'not found' > /dev/null 2>&1; then
      :
    else
      break
    fi
  done
fi
if test -z "$AWK" ; then
  echo 'No awk found.' >&2
  exit 1
fi

"$AWK" '
BEGIN {
    num = 0;
    num_ok = 0;
    num_wrong = 0;
    num_skipped = 0;
    start = 0;
    doend = 0;
    doit = 0;
    name = "";
    lines = "";
}
/^GPC-TEST-BEGIN$/ {
    start = 1;
    next;
}
/^==========================$/ {
    if (start)
      {
        start = 0;
        doit = 1;
      }
    else
      doend = 1;
    next;
}
/^GPC-TEST-END$/ && doend {
    doit = 0;
    next;
}
doit == 0 {
    next;
}
function eval () {
    if (lines == "")
      return;
    tmp = $0;
    $0 = lines;
    num++;
    if (NF == 3 && $1 == "TEST" && $3 == "OK") {
        ok = 1;
        num_ok++;
    }
    else if (NF >= 3 && $1 == "TEST" && ($3 == "SKIPPED" || $3 == "SKIPPED:")) {
        ok = 0;
        num_skipped++;
    }
    else {
        ok = 0;
        num_wrong++;
    }
    if (!ok) {
        printf "%s\n", lines;
        fflush (); # useful if the output of this script is piped to another process
    }
    lines = "";
    $0 = tmp
}
/^TEST/ {
    eval();
    lines = "";
}
{
    if (lines != "")
      lines = lines "\n";
    lines = lines $0
}
END {
    eval();
    print "";
    print "# of GPC tests          " num;
    print "# of GPC tests passed   " num_ok;
    print "# of GPC tests skipped  " num_skipped;
    print "# of GPC tests failed   " num_wrong;
}
'
