-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTestFramework.pm
More file actions
59 lines (49 loc) · 1.52 KB
/
TestFramework.pm
File metadata and controls
59 lines (49 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#+----------------------------------------------------------------------------+
#| 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;