Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 74792 invoked from network); 26 Nov 2009 19:32:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 26 Nov 2009 19:32:33 -0000 Received: (qmail 78475 invoked by uid 500); 26 Nov 2009 19:32:33 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 78386 invoked by uid 500); 26 Nov 2009 19:32:33 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 78377 invoked by uid 99); 26 Nov 2009 19:32:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Nov 2009 19:32:33 +0000 X-ASF-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,NORMAL_HTTP_TO_IP,WEIRD_PORT X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Nov 2009 19:32:30 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 61E242388A19; Thu, 26 Nov 2009 19:32:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r884675 - in /couchdb/trunk: ./ share/www/script/ share/www/script/test/ src/couchdb/priv/couch_js/ test/javascript/ Date: Thu, 26 Nov 2009 19:32:10 -0000 To: commits@couchdb.apache.org From: davisp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091126193210.61E242388A19@eris.apache.org> Author: davisp Date: Thu Nov 26 19:32:08 2009 New Revision: 884675 URL: http://svn.apache.org/viewvc?rev=884675&view=rev Log: Setup JavaScript command line runner. All JS tests can now be run from the command line using the cURL adapter. In the future I would like to rework this and provide better TAP output. For now, each test is a single TAP assert. Added: couchdb/trunk/test/javascript/cli_runner.js couchdb/trunk/test/javascript/couch_http.js couchdb/trunk/test/javascript/run.tpl Removed: couchdb/trunk/test/javascript/runner.sh couchdb/trunk/test/javascript/test.js Modified: couchdb/trunk/.gitignore couchdb/trunk/Makefile.am couchdb/trunk/license.skip couchdb/trunk/share/www/script/couch.js couchdb/trunk/share/www/script/test/changes.js couchdb/trunk/share/www/script/test/cookie_auth.js couchdb/trunk/src/couchdb/priv/couch_js/http.c couchdb/trunk/src/couchdb/priv/couch_js/main.c couchdb/trunk/test/javascript/Makefile.am Modified: couchdb/trunk/.gitignore URL: http://svn.apache.org/viewvc/couchdb/trunk/.gitignore?rev=884675&r1=884674&r2=884675&view=diff ============================================================================== --- couchdb/trunk/.gitignore (original) +++ couchdb/trunk/.gitignore Thu Nov 26 19:32:08 2009 @@ -36,6 +36,7 @@ stamp-h1 test/.deps/ test/Makefile +test/javascript/run_js_tests.sh var/Makefile # for make @@ -65,6 +66,7 @@ test/local.ini test/etap/run test/etap/test_util.erl +test/javascript/run share/server/main.js # for make dev @@ -85,6 +87,8 @@ # for make check test/etap/temp.* +couchdb.stderr +couchdb.stdout # for make cover Modified: couchdb/trunk/Makefile.am URL: http://svn.apache.org/viewvc/couchdb/trunk/Makefile.am?rev=884675&r1=884674&r2=884675&view=diff ============================================================================== --- couchdb/trunk/Makefile.am (original) +++ couchdb/trunk/Makefile.am Thu Nov 26 19:32:08 2009 @@ -53,9 +53,11 @@ @echo "it creates development ini files as well as a" @echo "$(top_builddir)/tmp structure for development runtime files." @echo "Use ./utils/run to launch CouchDB from the source tree." + mkdir -p $(top_builddir)/etc/couchdb/default.d + mkdir -p $(top_builddir)/etc/couchdb/local.d mkdir -p $(top_builddir)/tmp/lib mkdir -p $(top_builddir)/tmp/log - mkdir -p $(top_builddir)/tmp/run + mkdir -p $(top_builddir)/tmp/run/couchdb distclean-local: rm -fr $(top_builddir)/tmp Modified: couchdb/trunk/license.skip URL: http://svn.apache.org/viewvc/couchdb/trunk/license.skip?rev=884675&r1=884674&r2=884675&view=diff ============================================================================== --- couchdb/trunk/license.skip (original) +++ couchdb/trunk/license.skip Thu Nov 26 19:32:08 2009 @@ -12,6 +12,8 @@ ^CHANGES ^config.* ^configure +^couchdb.stderr +^couchdb.stdout ^cover/.*\.coverdata ^cover/.*\.html ^erl_crash.dump Modified: couchdb/trunk/share/www/script/couch.js URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch.js?rev=884675&r1=884674&r2=884675&view=diff ============================================================================== --- couchdb/trunk/share/www/script/couch.js [utf-8] (original) +++ couchdb/trunk/share/www/script/couch.js [utf-8] Thu Nov 26 19:32:08 2009 @@ -496,4 +496,4 @@ returnArray.push(key + "=" + value); } return returnArray.join("&"); -} +}; Modified: couchdb/trunk/share/www/script/test/changes.js URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/changes.js?rev=884675&r1=884674&r2=884675&view=diff ============================================================================== --- couchdb/trunk/share/www/script/test/changes.js (original) +++ couchdb/trunk/share/www/script/test/changes.js Thu Nov 26 19:32:08 2009 @@ -57,7 +57,12 @@ } // poor man's browser detection - var is_safari = navigator.userAgent.match(/AppleWebKit/); + var is_safari = false; + if(typeof(navigator) == "undefined") { + is_safari = true; // For CouchHTTP based runners + } else if(navigator.userAgent.match(/AppleWebKit/)) { + is_safari = true; + }; if (!is_safari && xhr) { // Only test the continuous stuff if we have a real XHR object // with real async support. Modified: couchdb/trunk/share/www/script/test/cookie_auth.js URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/cookie_auth.js?rev=884675&r1=884674&r2=884675&view=diff ============================================================================== --- couchdb/trunk/share/www/script/test/cookie_auth.js (original) +++ couchdb/trunk/share/www/script/test/cookie_auth.js Thu Nov 26 19:32:08 2009 @@ -94,7 +94,11 @@ body: "username=Jason%20Davies&password="+encodeURIComponent(password) }); // should this be a redirect code instead of 200? - T(xhr.status == 200); + // The cURL adapter is returning the expected 302 here. + // I imagine this has to do with whether the client is willing + // to follow the redirect, ie, the browser follows and does a + // GET on the returned Location + T(xhr.status == 200 || xhr.status == 302); usersDb.deleteDb(); // test user creation Modified: couchdb/trunk/src/couchdb/priv/couch_js/http.c URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/priv/couch_js/http.c?rev=884675&r1=884674&r2=884675&view=diff ============================================================================== --- couchdb/trunk/src/couchdb/priv/couch_js/http.c (original) +++ couchdb/trunk/src/couchdb/priv/couch_js/http.c Thu Nov 26 19:32:08 2009 @@ -38,6 +38,9 @@ static JSBool go(JSContext* cx, JSObject* obj, HTTPData* http, char* body, size_t blen); +static JSString* +str_from_binary(JSContext* cx, char* data, size_t length); + static JSBool constructor(JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval) { @@ -406,13 +409,13 @@ if(!HANDLE) { JS_ReportError(cx, "Failed to initialize cURL handle."); - goto error; + goto done; } if(http->method < 0 || http->method > COPY) { JS_ReportError(cx, "INTERNAL: Unknown method."); - goto error; + goto done; } curl_easy_setopt(HANDLE, CURLOPT_CUSTOMREQUEST, METHODS[http->method]); @@ -452,13 +455,13 @@ if(curl_easy_perform(HANDLE) != 0) { JS_ReportError(cx, "Failed to execute HTTP request: %s", ERRBUF); - goto error; + goto done; } if(!state.resp_headers) { JS_ReportError(cx, "Failed to recieve HTTP headers."); - goto error; + goto done; } tmp = OBJECT_TO_JSVAL(state.resp_headers); @@ -473,7 +476,7 @@ )) { JS_ReportError(cx, "INTERNAL: Failed to set response headers."); - goto error; + goto done; } if(state.recvbuf) // Is good enough? @@ -482,16 +485,15 @@ jsbody = dec_string(cx, state.recvbuf, state.read+1); if(!jsbody) { - // This is so dirty its not even almost funny. I'm ignoring - // all sorts of content-types and character sets and just falling - // back to doing a chop job when something doesn't decode as UTF-8 - // which is pretty sad. But, if you hate me for it, then feel free - // to write a patch that does the proper content-type parsing and - // actually respects charsets as returned in headers. - jsbody = JS_NewString(cx, state.recvbuf, state.read); + // If we can't decode the body as UTF-8 we forcefully + // convert it to a string by just forcing each byte + // to a jschar. + jsbody = str_from_binary(cx, state.recvbuf, state.read); if(!jsbody) { - JS_ReportError(cx, "INTERNAL: Failed to decode body."); - goto error; + if(!JS_IsExceptionPending(cx)) { + JS_ReportError(cx, "INTERNAL: Failed to decode body."); + } + goto done; } } tmp = STRING_TO_JSVAL(jsbody); @@ -512,16 +514,13 @@ )) { JS_ReportError(cx, "INTERNAL: Failed to set responseText."); - goto error; + goto done; } ret = JS_TRUE; - goto success; -error: +done: if(state.recvbuf) JS_free(cx, state.recvbuf); - -success: return ret; } @@ -644,4 +643,23 @@ state->read += length; return length; } - + +JSString* +str_from_binary(JSContext* cx, char* data, size_t length) +{ + jschar* conv = (jschar*) JS_malloc(cx, length * sizeof(jschar)); + JSString* ret = NULL; + size_t i; + + if(!conv) return NULL; + + for(i = 0; i < length; i++) + { + conv[i] = (jschar) data[i]; + } + + ret = JS_NewUCString(cx, conv, length); + if(!ret) JS_free(cx, conv); + + return ret; +} Modified: couchdb/trunk/src/couchdb/priv/couch_js/main.c URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/priv/couch_js/main.c?rev=884675&r1=884674&r2=884675&view=diff ============================================================================== --- couchdb/trunk/src/couchdb/priv/couch_js/main.c (original) +++ couchdb/trunk/src/couchdb/priv/couch_js/main.c Thu Nov 26 19:32:08 2009 @@ -306,13 +306,21 @@ JS_SetGlobalObject(cx, global); - if(argc != 2) { + if(argc > 2) + { fprintf(stderr, "incorrect number of arguments\n\n"); fprintf(stderr, "usage: %s \n", argv[0]); return 2; } - execute_script(cx, global, argv[1]); + if(argc == 0) + { + execute_script(cx, global, NULL); + } + else + { + execute_script(cx, global, argv[1]); + } FINISH_REQUEST(cx); Modified: couchdb/trunk/test/javascript/Makefile.am URL: http://svn.apache.org/viewvc/couchdb/trunk/test/javascript/Makefile.am?rev=884675&r1=884674&r2=884675&view=diff ============================================================================== --- couchdb/trunk/test/javascript/Makefile.am (original) +++ couchdb/trunk/test/javascript/Makefile.am Thu Nov 26 19:32:08 2009 @@ -11,5 +11,12 @@ ## the License. EXTRA_DIST = \ - runner.sh \ - test.js + cli_runner.js \ + couch_http.js \ + run.tpl + +run: run.tpl + sed -e "s|%abs_top_srcdir%|$(abs_top_srcdir)|" \ + -e "s|%abs_top_builddir%|$(abs_top_builddir)|" \ + < $< > $@ + chmod +x $@ Added: couchdb/trunk/test/javascript/cli_runner.js URL: http://svn.apache.org/viewvc/couchdb/trunk/test/javascript/cli_runner.js?rev=884675&view=auto ============================================================================== --- couchdb/trunk/test/javascript/cli_runner.js (added) +++ couchdb/trunk/test/javascript/cli_runner.js Thu Nov 26 19:32:08 2009 @@ -0,0 +1,52 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +var console = { + log: function(arg) { + var msg = (arg.toString()).replace(/\n/g, "\n "); + print("# " + msg); + } +}; + +function T(arg1, arg2) { + if(!arg1) { + throw((arg2 ? arg2 : arg1).toString()); + } +} + +function runTestConsole(num, name, func) { + try { + func(); + print("ok " + num + " " + name); + } catch(e) { + msg = e.toString(); + msg = msg.replace(/\n/g, "\n "); + print("not ok " + num + " " + name + " " + msg); + } +} + +function runAllTestsConsole() { + var numTests = 0; + for(var t in couchTests) { numTests += 1; } + print("1.." + numTests); + var testId = 0; + for(var t in couchTests) { + testId += 1; + runTestConsole(testId, t, couchTests[t]); + } +}; + +try { + runAllTestsConsole(); +} catch (e) { + p("# " + e.toString()); +} Added: couchdb/trunk/test/javascript/couch_http.js URL: http://svn.apache.org/viewvc/couchdb/trunk/test/javascript/couch_http.js?rev=884675&view=auto ============================================================================== --- couchdb/trunk/test/javascript/couch_http.js (added) +++ couchdb/trunk/test/javascript/couch_http.js Thu Nov 26 19:32:08 2009 @@ -0,0 +1,57 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy of +// the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +(function() { + CouchHTTP.prototype.base_url = "http://127.0.0.1:5984" + + if(typeof(CouchHTTP) != "undefined") { + CouchHTTP.prototype.open = function(method, url, async) { + if(/^\s*http:\/\//.test(url)) { + return this._open(method, url, async); + } else { + return this._open(method, this.base_url + url, async); + } + }; + + CouchHTTP.prototype.setRequestHeader = function(name, value) { + // Drop content-length headers because cURL will set it for us + // based on body length + if(name.toLowerCase().replace(/^\s+|\s+$/g, '') != "content-length") { + this._setRequestHeader(name, value); + } + } + + CouchHTTP.prototype.send = function(body) { + this._send(body || ""); + var headers = {}; + this._headers.forEach(function(hdr) { + var pair = hdr.split(":"); + var name = pair.shift(); + headers[name] = pair.join(":").replace(/^\s+|\s+$/g, ""); + }); + this.headers = headers; + }; + + CouchHTTP.prototype.getResponseHeader = function(name) { + for(var hdr in this.headers) { + if(hdr.toLowerCase() == name.toLowerCase()) { + return this.headers[hdr]; + } + } + return null; + }; + } +})(); + +CouchDB.newXhr = function() { + return new CouchHTTP(); +}; Added: couchdb/trunk/test/javascript/run.tpl URL: http://svn.apache.org/viewvc/couchdb/trunk/test/javascript/run.tpl?rev=884675&view=auto ============================================================================== --- couchdb/trunk/test/javascript/run.tpl (added) +++ couchdb/trunk/test/javascript/run.tpl Thu Nov 26 19:32:08 2009 @@ -0,0 +1,30 @@ +#!/bin/sh -e + +# Licensed under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +SRC_DIR=%abs_top_srcdir% +SCRIPT_DIR=$SRC_DIR/share/www/script +JS_TEST_DIR=$SRC_DIR/test/javascript + +COUCHJS=%abs_top_builddir%/src/couchdb/priv/couchjs + +cat $SCRIPT_DIR/json2.js \ + $SCRIPT_DIR/sha1.js \ + $SCRIPT_DIR/oauth.js \ + $SCRIPT_DIR/couch.js \ + $SCRIPT_DIR/couch_test_runner.js \ + $SCRIPT_DIR/couch_tests.js \ + $SCRIPT_DIR/test/*.js \ + $JS_TEST_DIR/couch_http.js \ + $JS_TEST_DIR/cli_runner.js \ + | $COUCHJS -