The tests are built by default when you build JS. All the tests are compiled
into a single binary named jsapi-tests. They all run in a single process.
They must be run from the js/src directory.
To run the tests:
$OBJDIR/dist/bin/jsapi-tests
To run the tests in a debugger:
gdb $OBJDIR/dist/bin/jsapi-tests
## Creating new tests
1. You can either add to an existing test*.cpp file or make a new one.
Copy an existing test and replace the body with your test code.
The test harness provides `cx`, `rt`, and `global` for your use.
2. If you made a new .cpp file, add it to the UNIFIED_SOURCES list in moz.build.
The BEGIN_TEST and END_TEST macros bracket each test. By convention, the test
name is <testFilename>_<detail>. (The above test isin testIntString.cpp.)
The curly braces are required. This block is the body of a C++ member function
that returns bool. The test harness calls this member function
automatically. If the function returns true, the test passes. False, it fails.
JSAPI tests often need extra global C/C++ code: a JSClass, a getter or setter
function, a resolve hook. Put these before the BEGIN_TEST macro.
The body of the test can use these member variables and macros, defined in
tests.h:
JSRuntime *rt;
JSContext *cx;
JSObject *global;
The test framework creates these fresh for each test. The default
environment has reasonable default settings, including
JSOPTION_VAROBJFIX, JSOPTION_JIT, a global object of a classwith
JSCLASS_GLOBAL_FLAGS, and an error reporter that prints to stderr.
See also "Custom test setup" below.
EXEC(const char *code);
Execute some JS code inglobal scope, using JS::Evaluate. Return falseif that fails. (This means that if the code throws an uncaught JS
exception, the test fails.)
EVAL(const char *code, jsval *vp);
Same as EXEC, but store the result value in *vp.
CHECK(bool cond);
If the condition isnottrue, print an error message andreturnfalse,
failing the test.
CHECK_SAME(jsval a, jsval b);
If a and b are different values, print an error message andreturn false, failing the test.
This is like CHECK(sameValue(a, b)) but with a more detailed error
message on failure. See sameValue below.
CHECK_EQUAL(const T &a, const U &b);
CHECK(a == b), but with a more detailed error message.
CHECK_NULL(const T *ptr);
CHECK(ptr == nullptr), but with a more detailed error message.
(This is here because CHECK_EQUAL(ptr, nullptr) fails to compile on GCC
2.5 and before.)
bool knownFail;
Set this to trueif your test is known to fail. The test runner will
print a TEST-KNOWN-FAIL line rather than a TEST-UNEXPECTED-FAIL
line. This way you can check in a test illustrating a bug ahead of the
fix.
If your test actually crashes the process or triggers an assertion,
this of course will not help, so you should add something like
knownFail = true; // see bug 123456 returnfalse; // the code below crashes!
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.