]> git.lyx.org Git - lyx.git/blob - development/batchtests/bin/compare_custom.pl
Cmake tests: findadv-01 - findadv-21 working
[lyx.git] / development / batchtests / bin / compare_custom.pl
1 #! /usr/bin/env perl
2 # -*- mode: perl; -*-
3
4 # This script does a line by line comparison of two lyx files
5
6 use File::Slurp qw(read_file);
7
8 my $file1_name = shift;
9 my $file2_name = shift;
10
11 my @file1 = read_file($file1_name);
12 my @file2 = read_file($file2_name);
13 chomp @file1;
14 chomp @file2;
15
16 my $line_count = 0;
17 my $in_body = 0;
18
19 my @diffs;
20
21 foreach my $file1_line (@file1) {
22         $line_count++;
23
24         if ($file1_line eq '\begin_body') {
25                 $in_body = 1;
26                 next;
27         }
28
29         next if (! $in_body);
30
31         my $file2_line = $file2[$line_count-1];
32
33         # Ignore timestamps on changes
34         if ($file1_line =~ m|\\change_\w+|) {
35                 $file1_line =~ s|(\d+) \d+||;
36                 $file2_line =~ s|(\d+) \d+||;
37         }
38
39         if ($file1_line ne $file2_line) {
40                 push @diffs, {
41                         line => $line_count,
42                         file1 => $file1_line,
43                         file2 => $file2_line,
44                 };
45         }
46 }
47
48 die "No body found in $file1_name\n" if (! $in_body);
49
50 my $diff_output = '';
51 foreach $diff (@diffs) {
52         $diff_output .= $diff->{line} . ' - ' . $diff->{file1} . ' | ' . $diff->{file2} . "\n";
53 }
54
55 if ($diff_output) {
56         die "Differences found!\n$diff_output\n";
57 }
58
59 exit(0);