#!/usr/bin/perl
#  _________________________________________________________________________
#
#  FAST: Python tools for software testing.
#  Copyright (c) 2008 Sandia Corporation.
#  This software is distributed under the BSD License.
#  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
#  the U.S. Government retains certain rights in this software.
#  For more information, see the FAST README.txt file.
#  _________________________________________________________________________
#

#
# Read input parameters
#
(open INPUT, "$ARGV[0]") || die "ERROR: cannot open file $ARGV[0]";
@lines = <INPUT>;
close(INPUT);
#
# Find command-line parameter
#
foreach $line (@lines) {
  chomp($line);
  @words=split(/\s+/,$line);
  if ($words[0] eq "command") {
     `$words[1] > $ARGV[2] 2>&1`;
     $command=$words[1];
     last;
     }
  }
#
# Generate measurements
#
print "DIFFING " . $ARGV[2] . " and ${command}.qa\n";
if (! -e $ARGV[2]) {
   $diffs = "Missing file " . $ARGV[2]
} elsif (! -e "${command}.qa") {
   $diffs = "Missing file ${command}.qa"
} else {
  $diffs = `diff -w $ARGV[2] ${command}.qa 2>&1`;
}
open OUTPUT, ">$ARGV[1]";
print OUTPUT "exit_status numeric/integer 0\n";
if ($diffs eq "") {
   print OUTPUT "diffs numeric/boolean 0\n";
}
else {
   print OUTPUT "diffs numeric/boolean 1\n";
}
print OUTPUT "diff_output text/string \"\"\"\n";
print OUTPUT "$diffs\n";
print OUTPUT "\"\"\"\n";
close(OUTPUT);
