1 // Dejagnu.as - HAXE class for dejagnu-like testing.
3 // Copyright (C) 2005, 2006, 2007, 2008, 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
23 import flash
.text
.TextField
;
26 static var passed
= 0;
27 static var failed
= 0;
28 static var xpassed
= 0;
29 static var xfailed
= 0;
30 static var untest
= 0;
31 static var unresolve
= 0;
33 // This is a trick to force our 'init' function
34 // to be automatically called at the start of the movie.
35 static var inithack
= init();
37 static var tf
:flash
.text
.TextField
;
39 static function init() {
40 //if(dejagnu_module_initialized == 1) return;
42 // create a textfield to output to
43 tf
= new flash
.text
.TextField();
44 tf
.autoSize
= flash
.text
.TextFieldAutoSize
.LEFT
;
45 //flash.Lib.current.createTextField("textout", 99, 10, 10, 500, 500);
46 flash
.Lib
.current
.addChild(tf
);
48 //dejagnu_module_initialized = 1;
53 static function fail (why
) {
55 var msg
= 'FAILED: '+why
;
59 static function xfail(why
) {
61 var msg
= 'XFAILED: '+why
;
65 static function pass(why
) {
67 var msg
= 'PASSED: '+why
;
71 static function xpass(why
) {
73 var msg
= 'XPASSED: '+why
;
77 static function testcount() {
79 if ( passed
> 0 ) c
+= passed
;
80 if ( failed
> 0 ) c
+= failed
;
81 if ( xpassed
> 0 ) c
+= xpassed
;
82 if ( xfailed
> 0 ) c
+= xfailed
;
83 if ( unresolve
> 0 ) c
+= unresolve
;
87 static function printtotals() {
88 xtrace('#passed: '+ passed
);
89 xtrace('#failed: '+ failed
);
91 xtrace('#unexpected successes: '+ xpassed
);
94 xtrace('#expected failures: '+ xfailed
);
97 xtrace('#tests unresolved'+ unresolve
);
99 xtrace('#total tests run: '+ testcount());
102 static public function totals(exp
:Dynamic, msg
:Dynamic) {
103 var obt
= testcount();
104 if ( exp
!= null && obt
!= exp
) {
105 fail('Test run '+obt
+' (expected '+exp
+') '+msg
);
107 pass('Test run '+obt
+' '+msg
);
111 static function xtotals(exp
:Dynamic, msg
:Dynamic) {
112 var obt
= testcount();
113 if ( exp
!= null && obt
!= exp
) {
114 xfail('Test run '+obt
+' (expected '+exp
+') ['+msg
+']');
116 xpass('Test run '+obt
+' ['+msg
+']');
120 static public function check_equals(obt
:Dynamic, exp
:Dynamic, msg
) {
121 if(msg
== null) msg
= "";
123 pass(obt
+' == '+exp
+' '+msg
);
125 fail('expected: "'+exp
+'" , obtained: "'+obt
+'" '+msg
);
128 static public function xcheck_equals(obt
:Dynamic, exp
:Dynamic, msg
)
130 if(msg
== null) msg
= "";
133 xpass(obt
+' == '+exp
+' '+msg
);
137 xfail('expected: '+exp
+' , obtained: '+obt
+" "+msg
);
141 static public function check(a
: Dynamic, msg
)
145 if ( msg
!= null ) pass(msg
);
150 if ( msg
!= null ) fail(msg
);
155 static public function xcheck(a
: Dynamic, msg
)
159 if ( msg
!= null ) xpass(msg
);
164 if ( msg
!= null ) xfail(msg
);
169 static public function note(msg
) {
173 static function xtrace(msg
) {
174 tf
.text
+= msg
+ "\n";
175 flash
.Lib
.trace(msg
);
178 static function untested(msg
) {
179 flash
.Lib
.trace("UNTESTED: "+msg
);
182 static function unresolved(msg
) {
184 flash
.Lib
.trace("UNRESOLVED: "+msg
);
187 static public function done() {
189 flash
.Lib
.trace("__END_OF_TEST__");
190 //loadMovie('fscommand:quit', _root);