# Copyright 2006-2008 The FLWOR Foundation.                                                             
#  
# Licensed under the Apache License, Version 2.0 (the "License");                                       
# you may not use this file except in compliance with the License.                                      
# You may obtain a copy of the License at
#  
# http://www.apache.org/licenses/LICENSE-2.0                                                            
#  
# Unless required by applicable law or agreed to in writing, software                                   
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.                              
# See the License for the specific language governing permissions and
# limitations under the License.
#!/usr/bin/perl
use strict;
use File::Basename;

sub parse_test_file {
  my ($fname) = @_;
  my $fh1;
  open ($fh1, $fname) or die ("$fname not found");
  my $code=chomp $fh1;
  my $text = do { local ($/); <$fh1>; };

 return ($code, $text);
}

sub report_failure {
    my $expected_dir=shift;
    my $test_name=shift;
    
    my $f1="$test_name/result.txt";
    my $f2="$expected_dir/test_results/$test_name/result.txt";
    
    my ($code1, $text1) = parse_test_file ($f1);
    my ($code2, $text2) = parse_test_file ($f2);
    
    print ("<failure test='$test_name'><code><actual>$code1</actual><expected>$code2</expected></code><text><actual>$text1</actual><expected>$text2</expected></text></failure>\n");
}

my $test_dir = shift;
while (<>) {
    if (/^Files ([^ ]+) /) {
        report_failure ($test_dir, dirname $1);
    }
}
