Added tests for compare function

Runs the compare via the command line, and then compares the output to the
expected result. Required adding a script to do the comparison, so that
the timestamps on changes in the lyx file are ignored.
This commit is contained in:
Sam Crawley 2020-11-13 20:58:20 +13:00 committed by Pavel Sanda
parent f457a32a13
commit 434ac146bd
15 changed files with 8020 additions and 50 deletions

View File

@ -14,4 +14,5 @@ add_batch_test(outline-beamer beamer_test "export")
add_batch_test(vcs-info vcs_info_export)
add_batch_test(AMS-import ams-import "tex2lyx")
add_batch_test(SAVE-as save_as_test "export")
add_batch_test(compare-test compare_test "compare_test")

View File

@ -0,0 +1,59 @@
#! /usr/bin/env perl
# -*- mode: perl; -*-
# This script does a line by line comparison of two lyx files
use File::Slurp qw(read_file);
my $file1_name = shift;
my $file2_name = shift;
my @file1 = read_file($file1_name);
my @file2 = read_file($file2_name);
chomp @file1;
chomp @file2;
my $line_count = 0;
my $in_body = 0;
my @diffs;
foreach my $file1_line (@file1) {
$line_count++;
if ($file1_line eq '\begin_body') {
$in_body = 1;
next;
}
next if (! $in_body);
my $file2_line = $file2[$line_count-1];
# Ignore timestamps on changes
if ($file1_line =~ m|\\change_\w+|) {
$file1_line =~ s|(\d+) \d+||;
$file2_line =~ s|(\d+) \d+||;
}
if ($file1_line ne $file2_line) {
push @diffs, {
line => $line_count,
file1 => $file1_line,
file2 => $file2_line,
};
}
}
die "No body found in $file1_name\n" if (! $in_body);
my $diff_output = '';
foreach $diff (@diffs) {
$diff_output .= $diff->{line} . ' - ' . $diff->{file1} . ' | ' . $diff->{file2} . "\n";
}
if ($diff_output) {
die "Differences found!\n$diff_output\n";
}
exit(0);

View File

@ -0,0 +1,97 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 599
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\use_default_options true
\maintain_unincluded_children no
\language newzealand
\language_package default
\inputencoding utf8
\fontencoding auto
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_roman_osf false
\font_sans_osf false
\font_typewriter_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement class
\float_alignment class
\paperfontsize default
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\use_lineno 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tablestyle default
\tracking_changes true
\output_changes true
\change_bars false
\postpone_fragile_content true
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\docbook_table_output 0
\author 193470694 "Sam"
\end_header
\begin_body
\begin_layout Standard
one
\change_deleted 193470694 1604116946
cat
\change_inserted 193470694 1604116946
dog
\end_layout
\end_body
\end_document

View File

@ -0,0 +1,92 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 599
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\use_default_options true
\maintain_unincluded_children no
\language newzealand
\language_package default
\inputencoding utf8
\fontencoding auto
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_roman_osf false
\font_sans_osf false
\font_typewriter_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement class
\float_alignment class
\paperfontsize default
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\use_lineno 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tablestyle default
\tracking_changes false
\output_changes false
\change_bars false
\postpone_fragile_content true
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\docbook_table_output 0
\end_header
\begin_body
\begin_layout Standard
one dog
\end_layout
\end_body
\end_document

View File

@ -0,0 +1,92 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 599
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\use_default_options true
\maintain_unincluded_children no
\language newzealand
\language_package default
\inputencoding utf8
\fontencoding auto
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_roman_osf false
\font_sans_osf false
\font_typewriter_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement class
\float_alignment class
\paperfontsize default
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\use_lineno 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tablestyle default
\tracking_changes false
\output_changes false
\change_bars false
\postpone_fragile_content true
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\docbook_table_output 0
\end_header
\begin_body
\begin_layout Standard
one cat
\end_layout
\end_body
\end_document

View File

@ -0,0 +1,112 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 599
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\use_default_options true
\maintain_unincluded_children no
\language newzealand
\language_package default
\inputencoding utf8
\fontencoding auto
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_roman_osf false
\font_sans_osf false
\font_typewriter_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement class
\float_alignment class
\paperfontsize default
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\use_lineno 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tablestyle default
\tracking_changes true
\output_changes true
\change_bars false
\postpone_fragile_content true
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\docbook_table_output 0
\author 193470694 "Sam"
\end_header
\begin_body
\begin_layout Standard
\begin_inset Foot
status open
\begin_layout Plain Layout
\change_deleted 193470694 1604721746
S
\change_inserted 193470694 1604721746
F
\change_unchanged
o
\change_deleted 193470694 1604721746
me new fo
\change_unchanged
otnote text
\end_layout
\end_inset
\end_layout
\end_body
\end_document

View File

@ -0,0 +1,101 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 599
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\use_default_options true
\maintain_unincluded_children no
\language newzealand
\language_package default
\inputencoding utf8
\fontencoding auto
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_roman_osf false
\font_sans_osf false
\font_typewriter_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement class
\float_alignment class
\paperfontsize default
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\use_lineno 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tablestyle default
\tracking_changes false
\output_changes false
\change_bars false
\postpone_fragile_content true
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\docbook_table_output 0
\end_header
\begin_body
\begin_layout Standard
\begin_inset Foot
status open
\begin_layout Plain Layout
Footnote text
\end_layout
\end_inset
\end_layout
\end_body
\end_document

View File

@ -0,0 +1,101 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 599
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\use_default_options true
\maintain_unincluded_children no
\language newzealand
\language_package default
\inputencoding utf8
\fontencoding auto
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_roman_osf false
\font_sans_osf false
\font_typewriter_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement class
\float_alignment class
\paperfontsize default
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\use_lineno 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tablestyle default
\tracking_changes false
\output_changes false
\change_bars false
\postpone_fragile_content true
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\docbook_table_output 0
\end_header
\begin_body
\begin_layout Standard
\begin_inset Foot
status open
\begin_layout Plain Layout
Some new footnote text
\end_layout
\end_inset
\end_layout
\end_body
\end_document

View File

@ -0,0 +1,105 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 599
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\use_default_options true
\maintain_unincluded_children no
\language newzealand
\language_package default
\inputencoding utf8
\fontencoding auto
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_roman_osf false
\font_sans_osf false
\font_typewriter_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement class
\float_alignment class
\paperfontsize default
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\use_lineno 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tablestyle default
\tracking_changes true
\output_changes true
\change_bars false
\postpone_fragile_content true
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\docbook_table_output 0
\author 193470694 "Sam"
\end_header
\begin_body
\begin_layout Standard
The
\change_deleted 193470694 1604717583
cat
\change_inserted 193470694 1604717583
bird
\change_unchanged
in the ha
\change_deleted 193470694 1604717583
t
\change_inserted 193470694 1604717583
nd
\change_unchanged
.
\end_layout
\end_body
\end_document

View File

@ -0,0 +1,92 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 599
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\use_default_options true
\maintain_unincluded_children no
\language newzealand
\language_package default
\inputencoding utf8
\fontencoding auto
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_roman_osf false
\font_sans_osf false
\font_typewriter_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement class
\float_alignment class
\paperfontsize default
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\use_lineno 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tablestyle default
\tracking_changes false
\output_changes false
\change_bars false
\postpone_fragile_content true
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\docbook_table_output 0
\end_header
\begin_body
\begin_layout Standard
The bird in the hand.
\end_layout
\end_body
\end_document

View File

@ -0,0 +1,92 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 599
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\use_default_options true
\maintain_unincluded_children no
\language newzealand
\language_package default
\inputencoding utf8
\fontencoding auto
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_roman_osf false
\font_sans_osf false
\font_typewriter_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\float_placement class
\float_alignment class
\paperfontsize default
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\use_lineno 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tablestyle default
\tracking_changes false
\output_changes false
\change_bars false
\postpone_fragile_content true
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\docbook_table_output 0
\end_header
\begin_body
\begin_layout Standard
The cat in the hat.
\end_layout
\end_body
\end_document

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -7,11 +7,12 @@ use strict;
use warnings;
use File::Copy;
use File::Compare;
use File::Slurp qw(read_dir);
sub checkPrecondition();
sub system1(@);
sub addFiles($$$);
sub mycompare($$$);
sub mycompare($$$$);
my $builddir = "@CMAKE_BINARY_DIR@";
my $userdir = "$builddir/Testing/.lyxbatch";
@ -24,13 +25,19 @@ my $qt_version = "@LYX_USE_QT@";
my $lyxsource = "@LYX_ABS_TOP_SRCDIR@";
my $data = "$lyxsource/development/batchtests";
my $test_bin = "$lyxsource/development/batchtests/bin";
my $comparepdf = "@COMPAREPDF_EXECUTABLE@";
my $perl = "@PERL_EXECUTABLE@";
# src_files := Files to be copied from lyx-source to build-dir
# check := List of tripples
# check := List of pairs of files to check
# created file (in build-dir)
# expected file (in source dir, to be compared with the created one)
# eventually system command to compare files
# check_type: Type of check to perform, can be either:
# * text (default) - compares using File::Compare (i.e. full comparison)
# * pdf - compares using comparepdf (must be installed)
# * custom - compares using a custom script
# check_script: For check_type==custom, this is the script that's executed to do the comparison
# commands := List of commands (lyx-functions) to be executed by lyx in a batch
# precondition: system commands to be executed prior to the test
# command_line: List of parameters to be used on the lyx-command-line
@ -67,7 +74,8 @@ my %Tests = (
},
"ams-import" => {
src_files => ["ams-import.tex"],
check => [["ams-import.pdf", "ams-import.pdf", $comparepdf],
check_type => 'pdf',
check => [["ams-import.pdf", "ams-import.pdf"],
["ams-import.lyx"]],
commands => ["buffer-new",
"buffer-import latex ams-import.tex",
@ -75,6 +83,18 @@ my %Tests = (
"buffer-export pdf2",
"lyx-quit"],
},
"compare_test" => {
src_files => ["old.lyx", "new.lyx"],
check_type => 'custom',
check_script => ["$perl","$test_bin/compare_custom.pl"],
test_dir => "$lyxsource/development/batchtests/compare_tests/",
check => [["diffs.lyx", "diffs.expected.lyx"]],
commands => [
"dialog-show compare run-blocking $workdir/old.lyx $workdir/new.lyx",
"buffer-write-as $workdir/diffs.lyx",
"lyx-quit"
],
},
);
die("Expected argument missing") if (! defined($ARGV[0]));
@ -84,23 +104,40 @@ die("Invalid argument") if (! defined($Tests{$test}));
if (! -e $userdir) {
mkdir($userdir);
}
my @expected = &addFiles($data, $Tests{$test}->{check},1);
my @created = &addFiles($workdir, $Tests{$test}->{check}, 0);
my @comparecommand = &addFiles(undef, $Tests{$test}->{check}, 2);
# Copy src-files to work with
for my $f (@{$Tests{$test}->{src_files}}) {
copy("$data/$f", "$workdir/$f") or die("Copy failed: $!");
}
print "Unlinking " . join(' ', @created) . "\n";
unlink(@created);
$ENV{LANG} = "en";
$ENV{LC_ALL} = "C";
$ENV{LANGUAGE} = "en_US";
if (defined $Tests{$test}->{test_dir}) {
my @dirs = read_dir($Tests{$test}->{test_dir}, prefix => 1);
foreach my $dir (@dirs) {
next unless -d $dir;
print "--- Running tests in $dir\n";
run_tests($dir);
}
}
else {
run_tests($data);
}
exit(0);
sub run_tests {
my $test_dir = shift;
my @expected = &addFiles($test_dir, $Tests{$test}->{check},1);
my @created = &addFiles($workdir, $Tests{$test}->{check}, 0);
# Copy src-files to work with
for my $f (@{$Tests{$test}->{src_files}}) {
copy("$test_dir/$f", "$workdir/$f") or die("Copy failed: $!");
}
print "Unlinking " . join(' ', @created) . "\n";
unlink(@created);
&checkPrecondition();
chdir($workdir);
my @command = ($lyx_exe, "-userdir", $userdir);
@ -123,11 +160,14 @@ if (defined($Tests{$test}->{commands}->[0])) {
for (my $i = 0; defined($created[$i]); $i++) {
die("File \"$created[$i]\" not created") if (! -e "$created[$i]");
if (defined($expected[$i])) {
die("Expected ($expected[$i]) and created ($created[$i]) files differ") if (&mycompare($comparecommand[$i], $expected[$i], $created[$i]) != 0);
my $res = mycompare($Tests{$test}->{check_type}, $expected[$i], $created[$i], $Tests{$test}->{check_script});
die("Expected ($expected[$i]) and created ($created[$i]) files differ") if $res != 0;
}
}
}
exit(0);
sub checkPrecondition()
{
@ -173,22 +213,24 @@ sub addFiles($$$)
return(@result);
}
sub mycompare($$$)
sub mycompare($$$$)
{
my ($cmd, $expected, $created) = @_;
my ($check_type, $expected, $created, $check_script) = @_;
my $result;
if (defined($cmd)) { # system command desired
my @params = ();
$check_type //= 'text';
if ($check_type eq 'pdf') {
my $cmd = $comparepdf;
if ($cmd =~ /NOTFOUND/) {
# no check is done due to missing executable
}
else {
if ($cmd =~ /comparepdf/) {
push(@params, "-ca", "-v=1", $expected, $created);
}
else {
die("unknown system command $cmd");
}
my @params = (
"-ca", "-v=1", $expected, $created
);
my $error = "";
if (&system1($cmd, @params) != 0) {
if ($? == -1) {
@ -206,9 +248,15 @@ sub mycompare($$$)
}
$result = 0;
}
else {
elsif ($check_type eq 'custom') {
$result = system1(@$check_script, $expected, $created);
}
elsif ($check_type eq 'text') {
# defaut text comparision
$result = compare($created, $expected);
}
else {
die "Unknown check type: $check_type";
}
return($result);
}