1 // Dejagnu.hx - HAXE class for dejagnu-like testing.
3 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 import flash
.text
.TextField
;
23 import flash
.text
.TextFieldType
;
24 import flash
.external
.ExternalInterface
;
25 import flash
.display
.MovieClip
;
27 import flash
.TextField
;
28 import flash
.MovieClip
;
33 static var passed
= 0;
34 static var failed
= 0;
35 static var xpassed
= 0;
36 static var xfailed
= 0;
37 static var untest
= 0;
38 static var unresolve
= 0;
39 static var position
:PosInfos
;
40 static var trace = untyped __global__
['trace'];
42 static private function callerInfo(p
:haxe
.PosInfos
) {
43 return p
.fileName
+ ": " + p
.lineNumber
;
46 // This is a trick to force our 'init' function
47 // to be automatically called at the start of the movie.
48 static var inithack
= init();
50 static var tf
:TextField
;
52 static function init() {
53 //if(dejagnu_module_initialized == 1) return;
55 // create a textfield to output to
61 flash
.Lib
.current
.addChild(tf
);
63 flash
.Lib
.current
.createTextField("tfsoft", 100,0,0,390,290);
64 untyped tfsoft
.multiline
= true;
65 untyped tfsoft
.wordWrap
= true;
66 untyped tfsoft
.border
= true;
67 untyped tfsoft
.type
= "input";
69 //dejagnu_module_initialized = 1;
74 static public function fail (why
, ?p
:haxe
.PosInfos
) {
76 var msg
= 'FAILED: ' + why
+ " " + callerInfo(p
);
80 static public function xfail(why
, ?p
:haxe
.PosInfos
) {
82 var msg
= 'XFAILED: '+why
+ " " + callerInfo(p
);
86 static public function pass(why
, ?p
:haxe
.PosInfos
) {
88 var msg
= 'PASSED: '+why
+ " " + callerInfo(p
);
92 static public function xpass(why
, ?p
:haxe
.PosInfos
) {
94 var msg
= 'XPASSED: '+why
+ " " + callerInfo(p
);
98 static public function check_equals(obt
:Dynamic, exp
:Dynamic, msg
, ?p
:haxe
.PosInfos
) {
99 if(msg
== null) msg
= "";
101 // Pass the calling posinfos.
102 pass(obt
+' == ' + exp
+ ' ' + msg
, p
);
104 fail('expected: "' + exp
+ '" , obtained: "' + obt
+ '" ' + msg
, p
);
108 static public function xcheck_equals(obt
:Dynamic, exp
:Dynamic, msg
, ?p
:haxe
.PosInfos
)
110 if(msg
== null) msg
= "";
113 xpass(obt
+' == '+exp
+' '+msg
, p
);
117 xfail('expected: '+exp
+' , obtained: '+obt
+" "+msg
, p
);
121 static public function check(a
: Dynamic, msg
, ?p
:haxe
.PosInfos
)
125 if ( msg
!= null ) pass(msg
, p
);
130 if ( msg
!= null ) fail(msg
, p
);
135 static public function xcheck(a
: Dynamic, msg
, ?p
:haxe
.PosInfos
)
139 if ( msg
!= null ) xpass(msg
, p
);
144 if ( msg
!= null ) xfail(msg
, p
);
149 static function testcount() {
151 if ( passed
> 0 ) c
+= passed
;
152 if ( failed
> 0 ) c
+= failed
;
153 if ( xpassed
> 0 ) c
+= xpassed
;
154 if ( xfailed
> 0 ) c
+= xfailed
;
155 if ( unresolve
> 0 ) c
+= unresolve
;
159 static function printtotals() {
160 xtrace('#passed: '+ passed
);
161 xtrace('#failed: '+ failed
);
163 xtrace('#unexpected successes: '+ xpassed
);
166 xtrace('#expected failures: '+ xfailed
);
168 if ( unresolve
> 0 ) {
169 xtrace('#tests unresolved: '+ unresolve
);
171 xtrace('#total tests run: '+ testcount());
174 static public function totals(exp
:Dynamic, msg
:Dynamic, ?p
:haxe
.PosInfos
) {
175 var obt
= testcount();
176 if ( exp
!= null && obt
!= exp
) {
177 fail('Test run '+obt
+' (expected '+exp
+') '+msg
, p
);
179 pass('Test run '+obt
+' '+msg
, p
);
183 static public function xtotals(exp
:Dynamic, msg
:Dynamic, ?p
:haxe
.PosInfos
) {
184 var obt
= testcount();
185 if ( exp
!= null && obt
!= exp
) {
186 xfail('Test run '+obt
+' (expected '+exp
+') ['+msg
+']', p
);
188 xpass('Test run '+obt
+' ['+msg
+']', p
);
192 static public function note(msg
, ?p
:haxe
.PosInfos
) {
193 xtrace(msg
+ " " + p
.lineNumber
);
196 static function xtrace(msg
) {
200 untyped tfsoft
.text
+= msg
+"\n";
202 flash
.Lib
.trace(msg
);
205 static public function untested(msg
, ?p
:haxe
.PosInfos
) {
207 tf
.text
+= "UNTESTED: "+msg
+"\n";
209 untyped tfsoft
.text
+= "UNTESTED: "+msg
+"\n";
211 flash
.Lib
.trace("UNTESTED: " + msg
);
214 static public function unresolved(msg
) {
217 tf
.text
+= "UNRESOLVED: "+msg
+"\n";
219 untyped tfsoft
.text
+= "UNRESOLVED: "+msg
+"\n";
221 flash
.Lib
.trace("UNRESOLVED: "+msg
);
224 static public function done() {
227 tf
.text
+= "__END_OF_TEST__";
229 untyped tfsoft
.text
+= "__END_OF_TEST__";
231 flash
.Lib
.trace("__END_OF_TEST__");