From 2886280c57cb77b6e7f2bac544af5b8c23164816 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Fri, 2 Jan 2009 02:00:33 +0000 Subject: test runner is back up (thanks davisp), and tests pass in safari again (e4x syntax fix) git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@730656 13f79535-47bb-0310-9956-ffa450edef68 --- share/server/main.js | 7 ++-- share/www/script/couch_tests.js | 87 ++++++++++++++++++++++------------------- test/runner.sh | 2 +- test/test.js | 3 +- 4 files changed, 52 insertions(+), 47 deletions(-) diff --git a/share/server/main.js b/share/server/main.js index 58acae90..dfb0a403 100644 --- a/share/server/main.js +++ b/share/server/main.js @@ -133,7 +133,6 @@ var Mimeparse = (function() { return publicMethods; })(); - // this function provides a shortcut for managing responses by Accept header respondWith = function(req, responders) { var accept = req.headers["Accept"]; @@ -153,9 +152,9 @@ respondWith = function(req, responders) { resp["headers"]["Content-Type"] = bestMime; return resp; } - } - if (responders.default) { - return responders[responders.default](); + } + if (responders.fallback) { + return responders[responders.fallback](); } throw({code:406, body:"Not Acceptable: "+accept}); } diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 5a642f33..c0f909ad 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -2034,43 +2034,49 @@ var tests = { db.deleteDb(); db.createDb(); if (debug) debugger; + + function stringFun(fun) { + var string = fun.toSource ? fun.toSource() : "(" + fun.toString() + ")"; + return string; + } var designDoc = { _id:"_design/template", language: "javascript", forms: { - "hello" : (function() { + "hello" : stringFun(function() { return { body : "Hello World" }; - }).toString(), - "just-name" : (function(doc, req) { + }), + "just-name" : stringFun(function(doc, req) { return { body : "Just " + doc.name }; - }).toString(), - "req-info" : (function(doc, req) { + }), + "req-info" : stringFun(function(doc, req) { return { json : req } - }).toString(), - "xml-type" : (function(doc, req) { - return { - headers : { - "Content-Type" : "application/xml" - }, - "body" : - } - }).toString(), - "no-set-etag" : (function(doc, req) { + }), + "xml-type" : [ + 'function(doc, req) { ', + ' return { ', + ' "headers" : { ', + ' "Content-Type" : "application/xml" ', + ' }, ', + ' "body" : ', + ' } ', + '}'].join('\n'), + "no-set-etag" : stringFun(function(doc, req) { return { headers : { "Etag" : "skipped" }, "body" : "something" } - }).toString(), - "accept-switch" : (function(doc, req) { + }), + "accept-switch" : stringFun(function(doc, req) { if (req.headers["Accept"].match(/image/)) { return { // a 16x16 px version of the CouchDB logo @@ -2097,29 +2103,30 @@ var tests = { } }; } - }).toString(), - "respondWith" : (function(doc, req) { - registerType("foo", "application/foo","application/x-foo"); - return respondWith(req, { - html : function() { - return { - body:"Ha ha, you said \"" + doc.word + "\"." - }; - }, - xml : function() { - return { - body: - }; - }, - foo : function() { - return { - body: "foofoo" - }; - }, - default : "html" - }); - }).toString() - } + }), + "respondWith" : [ + 'function(doc, req) { ', + ' registerType("foo", "application/foo","application/x-foo");', + ' return respondWith(req, { ', + ' html : function() { ', + ' return { ', + ' body:"Ha ha, you said \\"" + doc.word + "\\"." ', + ' }; ', + ' }, ', + ' xml : function() { ', + ' return { ', + ' body: ', + ' }; ', + ' }, ', + ' foo : function() { ', + ' return { ', + ' body: "foofoo" ', + ' }; ', + ' }, ', + ' fallback : "html" ', + ' }); ', + '}'].join('\n') + } }; T(db.save(designDoc).ok); diff --git a/test/runner.sh b/test/runner.sh index e920090d..561110a8 100755 --- a/test/runner.sh +++ b/test/runner.sh @@ -4,4 +4,4 @@ erlc runner.erl erl -noshell -pa ../src/couchdb -pa ../src/mochiweb -eval "runner:run()" -cat ../share/www/script/couch.js ../share/www/script/couch_tests.js test.js | ../src/couchdb/couchjs - +cat ../share/www/script/couch.js ../share/www/script/couch_test_runner.js ../share/www/script/couch_tests.js test.js | ../src/couchdb/couchjs - diff --git a/test/test.js b/test/test.js index e47153bd..a4aa32e1 100644 --- a/test/test.js +++ b/test/test.js @@ -67,8 +67,7 @@ var HTTP = (function() { var h = headers[i]; if (keymatcher.test(h)) { var value = h.substr(key.length+2); - value = value.slice(0, value.length-1); - return value; + return value.replace(/^\s+|\s+$/g,""); } } return ""; -- cgit v1.2.3