#!/usr/bin/perl

# This is the default test processing script, which is used to pre-process the
# screen output unless you create a <testname>.sh next to your test. The
# script gets one argument ($1), which is the name of the file (currently this
# will always be "screen-output") and the input is piped into the script.

# This implementation here just prints the input unmodified, except that we
# filter part of exception messages, because the types are compiler dependent:

$skip = 0;

while ( <STDIN> )
{
  # this is not strictly necessary because we are going to remove the
  # following lines inside the cmake script, but this makes it easier
  # to generate screen-output files from scratch because the useless
  # lines are already removed.
  next if $_ =~ m/^-- /;
  next if $_ =~ m/^\|/;

  if ($skip>0)
  {
    print "(line in output replaced by default.sh script)\n";
	  $skip=$skip-1;
	  next;
  }

  if ($_ =~ m/^\s*An error occurred in/)
  {
    if ($_ =~ /function/)
    {
      # These lines have the structure:
      # "An error occurred in file <...> in function"
      # The file name is unlikely to change frequently, so we keep this line
      print "$_";
    }
    else
    {
      # These lines have the structure:
      # "An error occurred in line <...> of file"
      # The line number is likely to change frequently, so we replace this line
      print "(line in output replaced by default.sh script)\n";
    }
    # In both of the above cases, we want to replace the next line
    # In the first case, the function arguments are formatted differently
    # when run with a different compiler version.
    # In the second case, the full file paths are printed.
    $skip=1;
    next
  }

  if ($_ =~ m/^\s*Stacktrace:/)
  {
    print "$_";
    print "(rest of the output replaced by default.sh script)\n";
    last;
  }

  if ($_ =~ m/^Aborting!/)
  {
    print "$_";
    print "(rest of the output replaced by default.sh script)\n";
    last;
  }

  print "$_";
}
