Improve the CLI JavaScript stack formating
This dresses up the output of the JavaScript tests by making sure the
output is sane. Most of the issue was that the tracebak prints function
arguments which can include the entire source of the test.
This also tries to print the source file and line number nicely so that
we can find right where errors have occurred. Its proven quite useful
while fixing JavaScript tests.
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/7d2fe958
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/7d2fe958
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/7d2fe958
Branch: refs/heads/master
Commit: 7d2fe95802e032b824f732f3b819483f71b6b443
Parents: ba6c574
Author: Paul Joseph Davis <davisp@apache.org>
Authored: Wed Mar 21 22:42:15 2012 -0500
Committer: Paul Joseph Davis <davisp@apache.org>
Committed: Wed Apr 25 16:54:08 2012 -0500
----------------------------------------------------------------------
test/javascript/cli_runner.js | 36 +++++++++++++++++++++++++++++++-----
test/javascript/run.tpl | 21 +++------------------
2 files changed, 34 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/7d2fe958/test/javascript/cli_runner.js
----------------------------------------------------------------------
diff --git a/test/javascript/cli_runner.js b/test/javascript/cli_runner.js
index f53ffe8..fcb4633 100644
--- a/test/javascript/cli_runner.js
+++ b/test/javascript/cli_runner.js
@@ -17,6 +17,29 @@ var console = {
}
};
+var fmtStack = function(stack) {
+ if(!stack) {
+ console.log("No stack information");
+ return;
+ }
+ console.log("Trace back (most recent call first):\n");
+ var re = new RegExp("(.*?)@([^:]*):(.*)$");
+ var lines = stack.split("\n");
+ for(var i = 0; i < lines.length; i++) {
+ var line = lines[i];
+ if(!line.length) continue;
+ var match = re.exec(line);
+ if(!match) continue
+ var source = match[1].substr(0, 70);
+ var file = match[2];
+ var lnum = match[3];
+ while(lnum.length < 3) lnum = " " + lnum;
+ console.log(" " + lnum + ": " + file);
+ console.log(" " + source);
+ }
+}
+
+
function T(arg1, arg2) {
if(!arg1) {
var result = (arg2 ? arg2 : arg1);
@@ -32,10 +55,8 @@ function runTestConsole(num, name, func) {
print("ok " + num + " " + name);
} catch(e) {
print("not ok " + num + " " + name);
- console.log(e.toSource());
- if (e.stack) {
- console.log("Stacktrace:\n" + e.stack.replace(/^/gm, "\t"));
- }
+ console.log("Reason: " + e.message);
+ fmtStack(e.stack);
}
return passed;
}
@@ -52,7 +73,12 @@ function runAllTestsConsole() {
numPassed++;
}
}
- T(numPassed == numTests, "All JS CLI tests should pass.");
+ if(numPassed != numTests) {
+ console.log("Test failures: " + (numTests - numPassed));
+ quit(1);
+ } else {
+ console.log("All tests passed");
+ }
};
waitForSuccess(CouchDB.getVersion);
http://git-wip-us.apache.org/repos/asf/couchdb/blob/7d2fe958/test/javascript/run.tpl
----------------------------------------------------------------------
diff --git a/test/javascript/run.tpl b/test/javascript/run.tpl
index ac78b50..3cf7e69 100644
--- a/test/javascript/run.tpl
+++ b/test/javascript/run.tpl
@@ -36,23 +36,15 @@ else
fi
fi
-
-
-# stop CouchDB on exit from various signals
-abort() {
- trap - 0
- ./utils/run -d
- exit 2
-}
-
# start CouchDB
if [ -z $COUCHDB_NO_START ]; then
make dev
- trap 'abort' 0 1 2 3 4 6 8 15
./utils/run -b -r 1 -n \
-a $SRC_DIR/etc/couchdb/default_dev.ini \
-a $SRC_DIR/test/random_port.ini \
-a $SRC_DIR/etc/couchdb/local_dev.ini
+ RUN_PID=$!
+ trap "./utils/run -d || kill $RUN_PID || exit 2" EXIT
sleep 1 # give it a sec
fi
@@ -67,12 +59,5 @@ $COUCHJS -H -u $COUCH_URI_FILE \
$TEST_SRC \
$JS_TEST_DIR/couch_http.js \
$JS_TEST_DIR/cli_runner.js
-RESULT=$?
-
-if [ -z $COUCHDB_NO_START ]; then
- # stop CouchDB
- ./utils/run -d
- trap - 0
-fi
-exit $RESULT
+exit $?
|