Commit 55d9875d authored by twanvl's avatar twanvl

added tests for export templates

parent ccd96bb4
#!/usr/bin/perl
# For each export-template:
# 1. Create a dummy set for its game, with the first stylesheet we encounter (?)
# 2. Invoke magicseteditor with that set & export-template
# 3. Ensure that there are no errors
use strict;
use lib "../util/";
use MseTestUtils;
use TestFramework;
use File::Spec;
use File::Basename;
# -----------------------------------------------------------------------------
# The tests
# -----------------------------------------------------------------------------
my $package_dir = "../../data";
our %default_stylesheets = ('magic' => 'new');
my @packages = glob "$package_dir/*.mse-export-template";
sub test_export_template {
my $path = shift;
(my $x,my $y,my $package) = File::Spec->splitpath($path);
my $basename = basename($package,".mse-export-template");
test_case("export-template/$basename",sub{
# Determine game for this export-template
my $game;
open TEMPLATE, "< $path/export-template";
while (<TEMPLATE>) {
$game = $1 if /^game:\s*(\S*)/;
}
close TEMPLATE;
die ("No game found for $package") if !$game;
# Check filename
my $suffix;
if ($package =~ /$game-(.+).mse-export-template$/) {
$suffix = $1;
} else {
die("Export-template filename doesn't match game ($game)!\n");
}
# Find stylesheet
my $stylesheet = $default_stylesheets{$game} // 'standard';
print "game: $game\n";
print "stylesheet: $stylesheet\n";
print "export-template: $suffix\n";
# Create dummy set
my $set;
my $tempname = "_dummy-$basename";
my $setname = "$tempname-set.mse-set";
$set .= "game: $game\n";
$set .= "stylesheet: $stylesheet\n";
$set .= "card:\n";
write_dummy_set($setname, $set);
# Run!
mkdir("out");
run_export_test($package, $setname, "out/$basename.out", cleanup => 1);
# Cleanup
remove_dummy_set($setname);
# TODO: Compare the output against the expected output?
});
}
foreach (@packages) {
test_export_template($_) ;
}
1;
#!/usr/bin/perl
# For each mse-script file:
# 1. Invoke magicseteditor
# 2. Ensure that there are no errors
# For each stylesheet:
# 1. Create a dummy set for that stylesheet
# 2. Invoke magicseteditor with that set
# 3. Ensure that there are no errors
use strict;
use lib "../util/";
......@@ -36,13 +37,11 @@ sub test_stylesheet {
if ($package =~ /$game-(.+).mse-style$/) {
$suffix = $1;
} else {
#die ("Stylesheet filename doesn't match game");
print (" Stylesheet filename doesn't match game ($game)!\n");
return;
die ("Stylesheet filename doesn't match game ($game)!\n");
}
print " game: $game\n";
print " stylesheet: $suffix\n";
print "game: $game\n";
print "stylesheet: $suffix\n";
# Create dummy set
my $set;
......@@ -59,12 +58,11 @@ sub test_stylesheet {
file_set_contents($script, "write_image_file(set.cards[0],file:\"cards-out/blank-$basename.png\");1");
# Run!
run_script_test($script, set => $setname);
run_script_test($script, set => $setname, cleanup => 1);
# Cleanup
remove_dummy_set($setname);
unlink($script);
unlink("$tempname.out");
# TODO: Compare the card against the expected output?
......
......@@ -8,7 +8,7 @@ package MseTestUtils;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(run_script_test file_set_contents write_dummy_set remove_dummy_set);
@EXPORT = qw(run_script_test run_export_test file_set_contents write_dummy_set remove_dummy_set);
use strict;
use File::Basename;
......@@ -34,13 +34,53 @@ sub run_script_test {
my %opts = @_;
my $args = defined($opts{set}) ? "\"$opts{set}\"" : '';
my $ignore_locale_errors = $opts{ignore_locale_errors} // 1;
my $cleanup = $opts{cleanup} // 0;
my $outfile = basename($script,".mse-script") . ".out";
my $command = "$MAGICSETEDITOR --cli --quiet --script \"$script\" $args > \"$outfile\"";
my $errfile = basename($script,".mse-script") . ".err";
my $command = "$MAGICSETEDITOR --cli --quiet --script \"$script\" $args > \"$outfile\" 2> \"$errfile\"";
print "$command\n";
`$command`;
# Check for errors / warnings
open FILE,"< $outfile";
check_for_errors($errfile, $ignore_locale_errors);
# TODO: diff against expected output?
#my $expected = basename($script,".mse-script") . ".out.expected";
if ($cleanup) {
unlink($outfile);
unlink($errfile);
}
}
# Invoke an export template
sub run_export_test {
my $template = shift;
my $set = shift;
my $outfile = shift;
my %opts = @_;
my $ignore_locale_errors = $opts{ignore_locale_errors} // 1;
my $cleanup = $opts{cleanup} // 0;
my $errfile = basename($set,".mse-set") . ".err";
my $command = "$MAGICSETEDITOR --export \"$template\" \"$set\" \"$outfile\" 2> \"$errfile\"";
print "$command\n";
`$command`;
# Check for errors / warnings
check_for_errors($errfile, $ignore_locale_errors);
# TODO: diff against expected output?
#my $expected = basename($script,".mse-script") . ".out.expected";
if ($cleanup) {
unlink($errfile);
}
}
sub check_for_errors {
my $errfile = shift;
my $ignore_locale_errors = shift;
open FILE,"< $errfile";
my $in_error = 0;
foreach (<FILE>) {
if (/^(WARNING|ERROR)/) {
......@@ -56,9 +96,6 @@ sub run_script_test {
}
}
close FILE;
# TODO: diff against expected output?
#my $expected = basename($script,".mse-script") . ".out.expected";
}
# -----------------------------------------------------------------------------
......@@ -79,7 +116,7 @@ sub svn_revision {
sub print_system_info {
print "host: ", getlogin()," @ ",hostname, "\n";
print "architecture: ",($is_windows ? "windows" : "not-windows"),"\n";
print "platform: ",($is_windows ? "Windows" : "not-windows"),"\n";
print "date: ", strftime('%Y-%m-%d %H:%m (%z)',localtime), "\n";
print "revision: ", svn_revision(), "\n";
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment