Commit afb531dc authored by twanvl's avatar twanvl

another script: render a card for each stylesheet

parent aab4cbd3
These tests "assert" expected stuff in the scripting language.
Tests are invoked by run-tests.pl
...@@ -5,41 +5,15 @@ ...@@ -5,41 +5,15 @@
# 2. Ensure that there are no errors # 2. Ensure that there are no errors
use strict; use strict;
use File::Find;
use File::Basename;
use lib "../util/"; use lib "../util/";
use MseTestUtils; use MseTestUtils;
# -----------------------------------------------------------------------------
# Utility functions
# -----------------------------------------------------------------------------
# Invoke a script
sub run_script_test {
my $script = shift;
my $args = shift;
my $expected = basename($script,".mse-script") . ".out.expected";
my $outfile = basename($script,".mse-script") . ".out";
my $command = "$MseTestUtils::MAGICSETEDITOR --cli --quiet --script $script $args > $outfile";
print "$command\n";
`$command`;
# TODO: diff against expected output
}
sub write_dummy_set {
my $setname = shift;
my $contents = shift;
mkdir($setname);
open SET,"> $setname/set";
print SET "mse version: 2.0.0\n";
print SET $contents;
close SET;
}
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# The tests # The tests
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
run_script_test("test-builtin1.mse-script", ""); run_script_test("test-builtin.mse-script", "");
write_dummy_set("dummy-magic-set.mse-set", "game: magic\nstylesheet: new\n");
run_script_test("test-magic.mse-script", "dummy-magic-set"); write_dummy_set("_dummy-magic-set.mse-set", "game: magic\nstylesheet: new\n");
run_script_test("test-magic.mse-script", "_dummy-magic-set");
remove_dummy_set("_dummy-magic-set.mse-set");
These tests work by:
1. creating a set file for each style
2. loading that set file into magicseteditor --cli
(3. exporting a card image)
4. comparing the card image against expected output
Tests are invoked by run-tests.pl
#!/usr/bin/perl
# For each mse-script file:
# 1. Invoke magicseteditor
# 2. Ensure that there are no errors
use strict;
use lib "../util/";
use MseTestUtils;
use File::Spec;
use File::Basename;
# -----------------------------------------------------------------------------
# The tests
# -----------------------------------------------------------------------------
sub test_stylesheet {
my $path = shift;
(my $x,my $y,my $package) = File::Spec->splitpath($path);
my $basename = basename($package,".mse-style");
print "Testing $package\n";
# Determine game for this set
my $game;
open STYLE, "< $path/style";
while (<STYLE>) {
$game = $1 if /^game: (.*)/;
}
close STYLE;
die ("No game found for $package") if !$game;
# Stylesheet suffix
my $suffix;
if ($package =~ /$game-(.+).mse-style/) {
$suffix = $1;
} else {
#die ("Stylesheet filename doesn't match game");
print (" Stylesheet filename doesn't match game!\n");
return;
}
print " game: $game\n";
print " stylesheet: $suffix\n";
# Create dummy set
my $set;
my $tempname = "_dummy-$basename";
my $setname = "$tempname-set.mse-set";
$set .= "game: $game\n";
$set .= "stylesheet: $suffix\n";
$set .= "card:\n";
write_dummy_set($setname, $set);
# Write script
my $script = "$tempname.mse-script";
mkdir("cards-out");
file_set_contents($script, "write_image_file(set.cards[0],file:\"cards-out/$basename.png\");1");
run_script_test($script, $setname);
# Cleanup
remove_dummy_set($setname);
unlink($script);
unlink("$tempname.out");
print "\n";
}
my $package_dir = "../../data";
my @packages = glob "$package_dir/*.mse-style";
foreach (@packages) {
test_stylesheet($_);
}
#+----------------------------------------------------------------------------+ #+----------------------------------------------------------------------------+
#| Description: Magic Set Editor - Program to make Magic (tm) cards | #| Description: Magic Set Editor - Program to make Magic (tm) cards |
#| Copyright: (C) 2001 - 2011 Twan van Laarhoven and Sean Hunt | #| Copyright: (C) 2001 - 2011 Twan van Laarhoven and Sean Hunt |
#| License: GNU General Public License 2 or later (see file COPYING) | #| License: GNU General Public License 2 or later (see file COPYING) |
#+----------------------------------------------------------------------------+ #+----------------------------------------------------------------------------+
package MseTestUtils;
use strict; use strict;
use File::Basename;
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Utilities for testing scripts # Utilities for testing scripts
...@@ -22,6 +21,52 @@ if ($is_windows) { ...@@ -22,6 +21,52 @@ if ($is_windows) {
$MAGICSETEDITOR = "../../magicseteditor"; $MAGICSETEDITOR = "../../magicseteditor";
} }
# Invoke a script
sub run_script_test {
my $script = shift;
my $args = shift;
my $outfile = basename($script,".mse-script") . ".out";
my $command = "$MAGICSETEDITOR --cli --quiet --script $script $args > $outfile";
print "$command\n";
`$command`;
# Check for errors / warnings
open FILE,"< $outfile";
foreach (<FILE>) {
if (/^(WARNING|ERROR)/) {
print $_;
}
}
close FILE;
# TODO: diff against expected output?
#my $expected = basename($script,".mse-script") . ".out.expected";
}
# -----------------------------------------------------------------------------
# Dummy sets
# -----------------------------------------------------------------------------
sub file_set_contents {
my $filename = shift;
my $contents = shift;
open FILE,"> $filename";
print FILE $contents;
close FILE;
}
sub write_dummy_set {
my $setname = shift;
my $contents = shift;
mkdir($setname);
file_set_contents("$setname/set", "mse version: 2.0.0\n$contents");
}
sub remove_dummy_set {
my $setname = shift;
unlink("$setname/set");
rmdir($setname);
}
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
1; 1;
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