]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_3/shell.js
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * The contents of this file are subject to the Netscape Public
4 * License Version 1.1 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of
6 * the License at http://www.mozilla.org/NPL/
8 * Software distributed under the License is distributed on an "AS
9 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10 * implied. See the License for the specific language governing
11 * rights and limitations under the License.
13 * The Original Code is Mozilla Communicator client code, released March
16 * The Initial Developer of the Original Code is Netscape Communications
17 * Corporation. Portions created by Netscape are
18 * Copyright (C) 1998 Netscape Communications Corporation. All
22 * Rob Ginda rginda@netscape.com
25 var FAILED
= "FAILED!: ";
26 var STATUS
= "STATUS: ";
27 var BUGNUMBER
= "BUGNUMBER: ";
28 var SECT_PREFIX
= 'Section ';
29 var SECT_SUFFIX
= ' of test -';
31 var callStack
= new Array();
34 * The test driver searches for such a phrase in the test output.
35 * If such phrase exists, it will set n as the expected exit code.
37 function expectExitCode(n
)
40 print('--- NOTE: IN THIS TESTCASE, WE EXPECT EXIT CODE ' + n
+ ' ---');
45 * Statuses current section of a test
50 return SECT_PREFIX
+ x
+ SECT_SUFFIX
;
55 * Some tests need to know if we are in Rhino as opposed to SpiderMonkey
59 return (typeof defineClass
== "function");
63 * Report a failure in the 'accepted' manner
65 function reportFailure (msg
)
67 var lines
= msg
.split ("\n");
69 var funcName
= currentFunc();
70 var prefix
= (funcName
) ? "[reported from " + funcName
+ "] ": "";
72 for (var i
=0; i
<lines
.length
; i
++)
73 print (FAILED
+ prefix
+ lines
[i
]);
78 * Print a non-failure message.
80 function printStatus (msg
)
82 var lines
= msg
.split ("\n");
85 for (var i
=0; i
<lines
.length
; i
++)
86 print (STATUS
+ lines
[i
]);
91 * Print a bugnumber message.
93 function printBugNumber (num
)
96 print (BUGNUMBER
+ num
);
101 * Compare expected result to actual result, if they differ (in value and/or
102 * type) report a failure. If description is provided, include it in the
105 function reportCompare (expected
, actual
, description
)
107 var expected_t
= typeof expected
;
108 var actual_t
= typeof actual
;
111 if ((VERBOSE
) && (typeof description
!= "undefined"))
112 printStatus ("Comparing '" + description
+ "'");
114 if (expected_t
!= actual_t
)
115 output
+= "Type mismatch, expected type " + expected_t
+
116 ", actual type " + actual_t
+ "\n";
118 printStatus ("Expected type '" + actual_t
+ "' matched actual " +
119 "type '" + expected_t
+ "'");
121 if (expected
!= actual
)
122 output
+= "Expected value '" + expected
+ "', Actual value '" + actual
+
125 printStatus ("Expected value '" + actual
+ "' matched actual " +
126 "value '" + expected
+ "'");
130 if (typeof description
!= "undefined")
131 reportFailure (description
);
132 reportFailure (output
);
138 * Puts funcName at the top of the call stack. This stack is used to show
139 * a function-reported-from field when reporting failures.
141 function enterFunc (funcName
)
144 if (!funcName
.match(/\(\)$/))
147 callStack
.push(funcName
);
152 * Pops the top funcName off the call stack. funcName is optional, and can be
153 * used to check push-pop balance.
155 function exitFunc (funcName
)
157 var lastFunc
= callStack
.pop();
161 if (!funcName
.match(/\(\)$/))
164 if (lastFunc
!= funcName
)
165 reportFailure ("Test driver failure, expected to exit function '" +
166 funcName
+ "' but '" + lastFunc
+ "' came off " +
173 * Peeks at the top of the call stack.
175 function currentFunc()
178 return callStack
[callStack
.length
- 1];