summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandall Leeds <randall@apache.org>2012-01-18 22:48:01 -0800
committerRandall Leeds <randall@apache.org>2012-01-26 17:03:08 -0800
commit14ac70910acc5eab03e443a112bce04dfef91b6d (patch)
treecec28f40c59635f73f5b7ec82dad5a0cd1916cab
parent0c619ed996390f6de24f87ce6f2c380295e152aa (diff)
downloadcouchdb-14ac70910acc5eab03e443a112bce04dfef91b6d.tar.gz
print JS CLI test tracebacks to stderr
Nothing in couchjs assumes that multiple arguments to the couchjs `print` function is sensible. The call signature changes to take an optional second parameter - a true value prints to stderr. From this point forward, console.log in the JS CLI prints to stderr.
-rw-r--r--src/couchdb/priv/couch_js/util.c19
-rw-r--r--test/javascript/cli_runner.js6
2 files changed, 13 insertions, 12 deletions
diff --git a/src/couchdb/priv/couch_js/util.c b/src/couchdb/priv/couch_js/util.c
index b7bd3e41e..d41d9e994 100644
--- a/src/couchdb/priv/couch_js/util.c
+++ b/src/couchdb/priv/couch_js/util.c
@@ -207,20 +207,21 @@ couch_readfile(JSContext* cx, const char* filename)
void
couch_print(JSContext* cx, uintN argc, jsval* argv)
{
- char *bytes;
- uintN i;
+ char *bytes = NULL;
+ FILE *stream = stdout;
- for(i = 0; i < argc; i++)
- {
- bytes = enc_string(cx, argv[i], NULL);
+ if (argc) {
+ if (argc > 1 && argv[1] == JSVAL_TRUE) {
+ stream = stderr;
+ }
+ bytes = enc_string(cx, argv[0], NULL);
if(!bytes) return;
-
- fprintf(stdout, "%s%s", i ? " " : "", bytes);
+ fprintf(stream, "%s", bytes);
JS_free(cx, bytes);
}
- fputc('\n', stdout);
- fflush(stdout);
+ fputc('\n', stream);
+ fflush(stream);
}
diff --git a/test/javascript/cli_runner.js b/test/javascript/cli_runner.js
index d9d7fce1b..dec8803cd 100644
--- a/test/javascript/cli_runner.js
+++ b/test/javascript/cli_runner.js
@@ -13,7 +13,7 @@
var console = {
log: function(arg) {
var msg = (arg.toString()).replace(/\n/g, "\n ");
- print("# " + msg);
+ print(msg, true);
}
};
@@ -30,9 +30,9 @@ function runTestConsole(num, name, func) {
print("ok " + num + " " + name);
} catch(e) {
print("not ok " + num + " " + name);
- print("# " + e.toSource());
+ console.log(e.toSource());
if (e.stack) {
- print("# Stacktrace:\n" + e.stack.replace(/^/gm, "\t"));
+ console.log("Stacktrace:\n" + e.stack.replace(/^/gm, "\t"));
}
}
}