1 // Dejagnu.as - MTASC class for dejagnu-like testing.
3 // Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 public class Dejagnu
{
26 private static var passed
= 0;
27 private static var failed
= 0;
28 private static var xpassed
= 0;
29 private static var xfailed
= 0;
30 private static var untest
= 0;
31 private static var unresolve
= 0;
32 private static var tf
:TextField = new TextField();
34 public static function fail
(why
) {
36 var msg
= 'FAILED: '+why
;
40 public static function xfail
(why
) {
42 var msg
= 'XFAILED: '+why
;
46 public static function pass
(why
) {
48 var msg
= 'PASSED: '+why
;
52 public static function xpass
(why
) {
54 var msg
= 'XPASSED: '+why
;
58 public static function totals
(exp
, msg
) {
59 var obt
= testcount
();
60 if ( exp
!= undefined && obt
!= exp
) {
61 fail
('Test run '+obt
+' (expected '+exp
+') ['+msg
+']');
63 pass
('Test run '+obt
+' ['+msg
+']');
67 public static function xtotals
(exp
, msg
) {
68 var obt
= testcount
();
69 if ( exp
!= undefined && obt
!= exp
) {
70 xfail
('Test run '+obt
+' (expected '+exp
+') ['+msg
+']');
72 xpass
('Test run '+obt
+' ['+msg
+']');
76 public static function check_equals
(obt
, exp
, msg
, expression
) {
77 if (msg
== null) msg
= "";
79 pass
(expression
+ ' == ' + exp
+ ' ' + msg
);
82 fail
(expression
+ ': expected: "' + exp
+
83 '" , obtained: "' + obt
+ '" ' + msg
);
87 public static function xcheck_equals
(obt
, exp
, msg
, expression
) {
88 if (msg
== null) msg
= "";
90 xpass
(expression
+ ' == ' + exp
+ ' ' + msg
);
93 xfail
(expression
+ ': expected: "' + exp
+
94 '" , obtained: "' + obt
+ '" ' + msg
);
98 public static function check
(a
, msg
) {
100 pass
(msg
!= undefined ? msg
: a
);
103 fail
(msg
!= undefined ? msg
: a
);
107 public static function xcheck
(a
, msg
) {
109 xpass
(msg
!= undefined ? msg
: a
);
112 xfail
(msg
!= undefined ? msg
: a
);
116 public static function note
(msg
) {
120 public static function untested
(msg
) {
121 trace
("UNTESTED: "+msg
);
124 public static function unresolved
(msg
) {
125 trace
("UNRESOLVED: "+msg
);
128 /// Private functions.
130 private static function xtrace
(msg
) {
131 //tf.text += msg + "\n";
135 private static function done
() {
137 trace
("__END_OF_TEST__");
140 private static function testcount
() {
142 if ( passed
) c
+= passed
;
143 if ( failed
) c
+= failed
;
144 if ( xpassed
) c
+= xpassed
;
145 if ( xfailed
) c
+= xfailed
;
149 private static function printtotals
() {
150 xtrace
('#passed: '+ passed
);
151 xtrace
('#failed: '+ failed
);
153 xtrace
('#unexpected successes: '+ xpassed
);
156 xtrace
('#expected failures: '+ xfailed
);
158 xtrace
('#total tests run: '+ testcount
());