Commit 1319ce01 authored by twanvl's avatar twanvl

tests: consistent format for output, include some information on the machine...

tests: consistent format for output, include some information on the machine running the tests, script for testing at top-level
parent cd834771
#+----------------------------------------------------------------------------+
#| Description: Magic Set Editor - Program to make Magic (tm) cards |
#| Copyright: (C) 2001 - 2011 Twan van Laarhoven and Sean Hunt |
#| License: GNU General Public License 2 or later (see file COPYING) |
#+----------------------------------------------------------------------------+
use strict;
# -----------------------------------------------------------------------------
# Subdirectories
# -----------------------------------------------------------------------------
sub test_subdir {
my $dir = shift;
chdir($dir);
require "../$dir/run-tests.pl";
}
test_subdir('script');
test_subdir('stylesheets');
......@@ -7,13 +7,21 @@
use strict;
use lib "../util/";
use MseTestUtils;
use TestFramework;
# -----------------------------------------------------------------------------
# The tests
# -----------------------------------------------------------------------------
run_script_test("test-builtin.mse-script", "");
test_case("script/Builtin Funcions", sub{
run_script_test("test-builtin.mse-script", "");
die("asdf");
});
write_dummy_set("_dummy-magic-set.mse-set", "game: magic\nstylesheet: new\n");
run_script_test("test-magic.mse-script", "_dummy-magic-set.mse-set");
remove_dummy_set("_dummy-magic-set.mse-set");
test_case("script/Magic Funcions", sub{
write_dummy_set("_dummy-magic-set.mse-set", "game: magic\nstylesheet: new\n");
run_script_test("test-magic.mse-script", "_dummy-magic-set.mse-set");
remove_dummy_set("_dummy-magic-set.mse-set");
});
1;
......@@ -7,6 +7,7 @@
use strict;
use lib "../util/";
use MseTestUtils;
use TestFramework;
use File::Spec;
use File::Basename;
......@@ -18,7 +19,8 @@ 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";
test_case("stylesheets/$basename/Blank card",sub{
# Determine game for this set
my $game;
......@@ -57,15 +59,16 @@ 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, $setname);
run_script_test($script, "\"$setname\"");
# Cleanup
remove_dummy_set($setname);
unlink($script);
unlink("$tempname.out");
print "\n";
# TODO: Compare the card against the expected output?
});
}
my $package_dir = "../../data";
......@@ -74,3 +77,5 @@ my @packages = glob "$package_dir/*.mse-style";
foreach (@packages) {
test_stylesheet($_);
}
1;
......@@ -4,8 +4,15 @@
#| License: GNU General Public License 2 or later (see file COPYING) |
#+----------------------------------------------------------------------------+
package MseTestUtils;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(run_script_test file_set_contents write_dummy_set remove_dummy_set);
use strict;
use File::Basename;
use TestFramework;
# -----------------------------------------------------------------------------
# Invoking Magic Set Editor
......@@ -16,7 +23,7 @@ use File::Basename;
our $MAGICSETEDITOR;
my $is_windows = $^O =~ /win/i || -e "C:";
if ($is_windows) {
$MAGICSETEDITOR = "\"../../build/Release Unicode/mse.exe\"";
$MAGICSETEDITOR = "\"../../build/Release Unicode/mse.com\"";
} else {
$MAGICSETEDITOR = "../../magicseteditor";
}
......@@ -26,7 +33,7 @@ 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";
my $command = "$MAGICSETEDITOR --cli --quiet --script \"$script\" $args > \"$outfile\"";
print "$command\n";
`$command`;
......@@ -37,6 +44,7 @@ sub run_script_test {
if (/^(WARNING|ERROR)/) {
print $_;
$in_error = 1;
fail_current_test();
} elsif ($in_error) {
if (/^ /) {
print $_;
......@@ -52,9 +60,30 @@ sub run_script_test {
}
# -----------------------------------------------------------------------------
# Invoking Magic Set Editor
# Information on the machine running tests
# -----------------------------------------------------------------------------
use POSIX qw/strftime/;
use Sys::Hostname;
sub svn_revision {
my $rev = `svn info ../..`;
if ($rev =~ /Revision:\s*(\d+)/) {
return $1;
} else {
return "???";
}
}
sub print_system_info {
print "host: ", getlogin()," @ ",hostname, "\n";
print "architecture: ",($is_windows ? "windows" : "not-windows"),"\n";
print "date: ", strftime('%Y-%m-%d %H:%m (%z)',localtime), "\n";
print "revision: ", svn_revision(), "\n";
}
print_system_info();
# -----------------------------------------------------------------------------
# Dummy sets
# -----------------------------------------------------------------------------
......
#+----------------------------------------------------------------------------+
#| Description: Magic Set Editor - Program to make Magic (tm) cards |
#| Copyright: (C) 2001 - 2011 Twan van Laarhoven and Sean Hunt |
#| License: GNU General Public License 2 or later (see file COPYING) |
#+----------------------------------------------------------------------------+
package TestFramework;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(test_case fail_current_test);
use strict;
use warnings;
# -----------------------------------------------------------------------------
# Test cases
# -----------------------------------------------------------------------------
# Initialization
$|=1;
my $tests_passed = 0;
my $tests_failed = 0;
our $current_test_passed;
# Evaluate a testcase, catch any exceptions
# Usage: test_case("name",sub{code});
sub test_case {
my $name = shift;
my $sub = shift;
print "----\n";
print "test: $name\n";
$current_test_passed = 1;
eval { &$sub(); };
if ($@ || !$current_test_passed) {
$tests_failed++;
print $@;
print "FAIL\n";
} else {
$tests_passed++;
print "OK\n";
}
}
sub fail_current_test {
$current_test_passed = 0;
}
sub test_summary {
print "====\n";
print "tests passed: $tests_passed\n";
print "tests failed: $tests_failed\n" if ($tests_failed);
exit $tests_failed ? 1 : 0;
}
END { test_summary(); }
# -----------------------------------------------------------------------------
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