summaryrefslogtreecommitdiff
path: root/tests/tools/flex-diff.pl
blob: 245e9a1bd330b9043197bef0390de6507f086d6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl -w
use strict;
use IPC::Run3;

# this file abstracts away from differences due to different hash
# functions that lead to different orders of features, n-best entries,
# etc.

die "Usage: $0 file1.txt file2.txt\n" unless scalar @ARGV == 2;
my $tmpa = "tmp.$$.a";
my $tmpb = "tmp.$$.b";
create_sorted($ARGV[0], $tmpa);
create_sorted($ARGV[1], $tmpb);

my $failed = 0;
run3 "diff $tmpa $tmpb";
if ($? != 0) {
  run3 "diff $ARGV[0] $ARGV[1]";
  $failed = 1;
}

unlink $tmpa;
unlink $tmpb;

exit $failed;

sub create_sorted {
  my ($in, $out) = @_;
  open A, "sort $in|" or die "Can't read $in: $!";
  open AA, ">$out" or die "Can't write $out: $!";
  while(<A>) {
    chomp;
    s/^\s*//;
    s/\s*$//;
    my @cs = split //;
    @cs = sort @cs;
    my $o = join('', @cs);
    print AA "$o\n";
  }
  close AA;
  close A;
}