Fossil SCM

JS code test cleanups to account for the fact that the ajax-thrown assertions/exceptions get swallowed by the ajax layer.

stephan 2011-10-11 19:57 UTC json-multitag-test
Commit 9e98a9bd9efb0f2f28be122af4e10d0f11758ee7
--- ajax/i-test/rhino-test.js
+++ ajax/i-test/rhino-test.js
@@ -3,11 +3,11 @@
33
'http://localhost:8080'
44
//'http://fjson/cgi-bin/fossil-json.cgi'
55
//'http://192.168.1.62:8080'
66
//'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi'
77
,
8
- verbose:true,
8
+ verbose:false,
99
wiki:{}
1010
};
1111
(function bootstrap() {
1212
var srcdir = '../js/';
1313
var includes = [srcdir+'json2.js',
@@ -49,11 +49,15 @@
4949
Throws an exception of cond is a falsy value.
5050
*/
5151
function assert(cond, descr){
5252
descr = descr || "Undescribed condition.";
5353
if(!cond){
54
+ print("Assertion FAILED: "+descr);
5455
throw new Error("Assertion failed: "+descr);
56
+ // aarrgghh. Exceptions are of course swallowed by
57
+ // the AJAX layer, to keep from killing a browser's
58
+ // script environment.
5559
}else{
5660
print("Assertion OK: "+descr);
5761
}
5862
}
5963
@@ -88,33 +92,35 @@
8892
!resp.resultCode.
8993
*/
9094
function assertResponseOK(resp){
9195
assert('object' === typeof resp,'Response is-a object.');
9296
assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
93
- assert( !resp.resultCode, 'resp.resultCode='+resp.resultCode);
97
+ assert( undefined === resp.resultCode, 'resp.resultCode is not set');
9498
}
9599
/**
96100
Asserts that resp is-a Object, resp.fossil is-a string, and
97101
resp.resultCode is a truthy value. If expectCode is set then
98102
it also asserts that (resp.resultCode=='FOSSIL-'+expectCode).
99103
*/
100104
function assertResponseError(resp,expectCode){
101105
assert('object' === typeof resp,'Response is-a object.');
102106
assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
103
- assert( resp.resultCode, 'resp.resultCode='+resp.resultCode);
107
+ assert( !!resp.resultCode, 'resp.resultCode='+resp.resultCode);
104108
if(expectCode){
105109
assert( 'FOSSIL-'+expectCode == resp.resultCode, 'Expecting result code '+expectCode );
106110
}
107111
}
108112
109113
function testHAI(){
114
+ var rs;
110115
TestApp.fossil.HAI({
111116
onResponse:function(resp,req){
112
- assertResponseOK(resp);
113
- TestApp.serverVersion = resp.fossil;
117
+ rs = resp;
114118
}
115119
});
120
+ assertResponseOK(rs);
121
+ TestApp.serverVersion = rs.fossil;
116122
assert( 'string' === typeof TestApp.serverVersion, 'server version = '+TestApp.serverVersion);
117123
}
118124
testHAI.description = 'Get server version info.';
119125
120126
function testIAmNobody(){
@@ -135,44 +141,53 @@
135141
assert( 'string' === typeof TestApp.fossil.auth.name, 'User name = '+TestApp.fossil.auth.name);
136142
}
137143
testAnonymousLogin.description = 'Perform anonymous login.';
138144
139145
function testAnonWiki(){
146
+ var rs;
140147
TestApp.fossil.sendCommand('/json/wiki/list',undefined,{
141148
beforeSend:function(req,opt){
142149
assert( req && (req.authToken==TestApp.fossil.auth.authToken), 'Request envelope contains expected authToken.' );
143150
},
144151
onResponse:function(resp,req){
145
- assertResponseOK(resp);
146
- assert( (typeof [] === typeof resp.payload) && resp.payload.length,
147
- "Wiki list seems to be okay.");
148
- TestApp.wiki.list = resp.payload;
152
+ rs = resp;
149153
}
150154
});
155
+ assertResponseOK(rs);
156
+ assert( (typeof [] === typeof rs.payload) && rs.payload.length,
157
+ "Wiki list seems to be okay.");
158
+ TestApp.wiki.list = rs.payload;
159
+
151160
TestApp.fossil.sendCommand('/json/wiki/get',{
152161
name:TestApp.wiki.list[0]
153162
},{
154163
onResponse:function(resp,req){
155
- assertResponseOK(resp);
156
- assert(resp.payload.name == TestApp.wiki.list[0], "Fetched page name matches expectations.");
157
- print("Got first wiki page: "+WhAjaj.stringify(resp.payload));
164
+ rs = resp;
158165
}
159166
});
167
+ assertResponseOK(rs);
168
+ assert(rs.payload.name == TestApp.wiki.list[0], "Fetched page name matches expectations.");
169
+ print("Got first wiki page: "+WhAjaj.stringify(rs.payload));
170
+
160171
}
161172
testAnonWiki.description = 'Fetch wiki list as anonymous user.';
162173
163174
function testAnonLogout(){
175
+ var rs;
164176
TestApp.fossil.logout({
165177
onResponse:function(resp,req){
166
- assertResponseOK(resp);
178
+ rs = resp;
167179
}
168180
});
181
+ assertResponseOK(rs);
182
+ print("Ensure that second logout attempt fails...");
169183
TestApp.fossil.logout({
170184
onResponse:function(resp,req){
171
- assertResponseError(resp);
185
+ rs = resp;
172186
}
173187
});
188
+ assertResponseError(rs);
174189
}
175190
testAnonLogout.description = 'Log out anonymous user.';
176191
177192
(function runAllTests(){
178193
var testList = [
179194
--- ajax/i-test/rhino-test.js
+++ ajax/i-test/rhino-test.js
@@ -3,11 +3,11 @@
3 'http://localhost:8080'
4 //'http://fjson/cgi-bin/fossil-json.cgi'
5 //'http://192.168.1.62:8080'
6 //'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi'
7 ,
8 verbose:true,
9 wiki:{}
10 };
11 (function bootstrap() {
12 var srcdir = '../js/';
13 var includes = [srcdir+'json2.js',
@@ -49,11 +49,15 @@
49 Throws an exception of cond is a falsy value.
50 */
51 function assert(cond, descr){
52 descr = descr || "Undescribed condition.";
53 if(!cond){
 
54 throw new Error("Assertion failed: "+descr);
 
 
 
55 }else{
56 print("Assertion OK: "+descr);
57 }
58 }
59
@@ -88,33 +92,35 @@
88 !resp.resultCode.
89 */
90 function assertResponseOK(resp){
91 assert('object' === typeof resp,'Response is-a object.');
92 assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
93 assert( !resp.resultCode, 'resp.resultCode='+resp.resultCode);
94 }
95 /**
96 Asserts that resp is-a Object, resp.fossil is-a string, and
97 resp.resultCode is a truthy value. If expectCode is set then
98 it also asserts that (resp.resultCode=='FOSSIL-'+expectCode).
99 */
100 function assertResponseError(resp,expectCode){
101 assert('object' === typeof resp,'Response is-a object.');
102 assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
103 assert( resp.resultCode, 'resp.resultCode='+resp.resultCode);
104 if(expectCode){
105 assert( 'FOSSIL-'+expectCode == resp.resultCode, 'Expecting result code '+expectCode );
106 }
107 }
108
109 function testHAI(){
 
110 TestApp.fossil.HAI({
111 onResponse:function(resp,req){
112 assertResponseOK(resp);
113 TestApp.serverVersion = resp.fossil;
114 }
115 });
 
 
116 assert( 'string' === typeof TestApp.serverVersion, 'server version = '+TestApp.serverVersion);
117 }
118 testHAI.description = 'Get server version info.';
119
120 function testIAmNobody(){
@@ -135,44 +141,53 @@
135 assert( 'string' === typeof TestApp.fossil.auth.name, 'User name = '+TestApp.fossil.auth.name);
136 }
137 testAnonymousLogin.description = 'Perform anonymous login.';
138
139 function testAnonWiki(){
 
140 TestApp.fossil.sendCommand('/json/wiki/list',undefined,{
141 beforeSend:function(req,opt){
142 assert( req && (req.authToken==TestApp.fossil.auth.authToken), 'Request envelope contains expected authToken.' );
143 },
144 onResponse:function(resp,req){
145 assertResponseOK(resp);
146 assert( (typeof [] === typeof resp.payload) && resp.payload.length,
147 "Wiki list seems to be okay.");
148 TestApp.wiki.list = resp.payload;
149 }
150 });
 
 
 
 
 
151 TestApp.fossil.sendCommand('/json/wiki/get',{
152 name:TestApp.wiki.list[0]
153 },{
154 onResponse:function(resp,req){
155 assertResponseOK(resp);
156 assert(resp.payload.name == TestApp.wiki.list[0], "Fetched page name matches expectations.");
157 print("Got first wiki page: "+WhAjaj.stringify(resp.payload));
158 }
159 });
 
 
 
 
160 }
161 testAnonWiki.description = 'Fetch wiki list as anonymous user.';
162
163 function testAnonLogout(){
 
164 TestApp.fossil.logout({
165 onResponse:function(resp,req){
166 assertResponseOK(resp);
167 }
168 });
 
 
169 TestApp.fossil.logout({
170 onResponse:function(resp,req){
171 assertResponseError(resp);
172 }
173 });
 
174 }
175 testAnonLogout.description = 'Log out anonymous user.';
176
177 (function runAllTests(){
178 var testList = [
179
--- ajax/i-test/rhino-test.js
+++ ajax/i-test/rhino-test.js
@@ -3,11 +3,11 @@
3 'http://localhost:8080'
4 //'http://fjson/cgi-bin/fossil-json.cgi'
5 //'http://192.168.1.62:8080'
6 //'http://fossil.wanderinghorse.net/repos/fossil-json-java/index.cgi'
7 ,
8 verbose:false,
9 wiki:{}
10 };
11 (function bootstrap() {
12 var srcdir = '../js/';
13 var includes = [srcdir+'json2.js',
@@ -49,11 +49,15 @@
49 Throws an exception of cond is a falsy value.
50 */
51 function assert(cond, descr){
52 descr = descr || "Undescribed condition.";
53 if(!cond){
54 print("Assertion FAILED: "+descr);
55 throw new Error("Assertion failed: "+descr);
56 // aarrgghh. Exceptions are of course swallowed by
57 // the AJAX layer, to keep from killing a browser's
58 // script environment.
59 }else{
60 print("Assertion OK: "+descr);
61 }
62 }
63
@@ -88,33 +92,35 @@
92 !resp.resultCode.
93 */
94 function assertResponseOK(resp){
95 assert('object' === typeof resp,'Response is-a object.');
96 assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
97 assert( undefined === resp.resultCode, 'resp.resultCode is not set');
98 }
99 /**
100 Asserts that resp is-a Object, resp.fossil is-a string, and
101 resp.resultCode is a truthy value. If expectCode is set then
102 it also asserts that (resp.resultCode=='FOSSIL-'+expectCode).
103 */
104 function assertResponseError(resp,expectCode){
105 assert('object' === typeof resp,'Response is-a object.');
106 assert( 'string' === typeof resp.fossil, 'Response contains fossil property.');
107 assert( !!resp.resultCode, 'resp.resultCode='+resp.resultCode);
108 if(expectCode){
109 assert( 'FOSSIL-'+expectCode == resp.resultCode, 'Expecting result code '+expectCode );
110 }
111 }
112
113 function testHAI(){
114 var rs;
115 TestApp.fossil.HAI({
116 onResponse:function(resp,req){
117 rs = resp;
 
118 }
119 });
120 assertResponseOK(rs);
121 TestApp.serverVersion = rs.fossil;
122 assert( 'string' === typeof TestApp.serverVersion, 'server version = '+TestApp.serverVersion);
123 }
124 testHAI.description = 'Get server version info.';
125
126 function testIAmNobody(){
@@ -135,44 +141,53 @@
141 assert( 'string' === typeof TestApp.fossil.auth.name, 'User name = '+TestApp.fossil.auth.name);
142 }
143 testAnonymousLogin.description = 'Perform anonymous login.';
144
145 function testAnonWiki(){
146 var rs;
147 TestApp.fossil.sendCommand('/json/wiki/list',undefined,{
148 beforeSend:function(req,opt){
149 assert( req && (req.authToken==TestApp.fossil.auth.authToken), 'Request envelope contains expected authToken.' );
150 },
151 onResponse:function(resp,req){
152 rs = resp;
 
 
 
153 }
154 });
155 assertResponseOK(rs);
156 assert( (typeof [] === typeof rs.payload) && rs.payload.length,
157 "Wiki list seems to be okay.");
158 TestApp.wiki.list = rs.payload;
159
160 TestApp.fossil.sendCommand('/json/wiki/get',{
161 name:TestApp.wiki.list[0]
162 },{
163 onResponse:function(resp,req){
164 rs = resp;
 
 
165 }
166 });
167 assertResponseOK(rs);
168 assert(rs.payload.name == TestApp.wiki.list[0], "Fetched page name matches expectations.");
169 print("Got first wiki page: "+WhAjaj.stringify(rs.payload));
170
171 }
172 testAnonWiki.description = 'Fetch wiki list as anonymous user.';
173
174 function testAnonLogout(){
175 var rs;
176 TestApp.fossil.logout({
177 onResponse:function(resp,req){
178 rs = resp;
179 }
180 });
181 assertResponseOK(rs);
182 print("Ensure that second logout attempt fails...");
183 TestApp.fossil.logout({
184 onResponse:function(resp,req){
185 rs = resp;
186 }
187 });
188 assertResponseError(rs);
189 }
190 testAnonLogout.description = 'Log out anonymous user.';
191
192 (function runAllTests(){
193 var testList = [
194
--- ajax/js/whajaj.js
+++ ajax/js/whajaj.js
@@ -405,11 +405,15 @@
405405
handling code ASSUMES that the response contains a JSONP-style
406406
construct and eval()s it after afterSend() but before onResponse().
407407
In this case, onResponse() will get a string value for the response
408408
instead of a response object parsed from JSON.
409409
*/
410
- jsonp:undefined
410
+ jsonp:undefined,
411
+ /**
412
+ Don't use yet. Planned future option.
413
+ */
414
+ propagateExceptions:false
411415
}
412416
};
413417
414418
415419
/**
@@ -947,10 +951,18 @@
947951
- timeouts are not supported.
948952
949953
- asynchronous mode is not supported because implementing it
950954
requires the ability to kill a running thread (which is deprecated
951955
in the Java API).
956
+
957
+ TODOs:
958
+
959
+ - add socket timeouts.
960
+
961
+ - support HTTP proxy.
962
+
963
+ The Java APIs support this, it just hasn't been added here yet.
952964
*/
953965
rhino:function(request,args)
954966
{
955967
var self = this;
956968
var data = request || undefined;
957969
--- ajax/js/whajaj.js
+++ ajax/js/whajaj.js
@@ -405,11 +405,15 @@
405 handling code ASSUMES that the response contains a JSONP-style
406 construct and eval()s it after afterSend() but before onResponse().
407 In this case, onResponse() will get a string value for the response
408 instead of a response object parsed from JSON.
409 */
410 jsonp:undefined
 
 
 
 
411 }
412 };
413
414
415 /**
@@ -947,10 +951,18 @@
947 - timeouts are not supported.
948
949 - asynchronous mode is not supported because implementing it
950 requires the ability to kill a running thread (which is deprecated
951 in the Java API).
 
 
 
 
 
 
 
 
952 */
953 rhino:function(request,args)
954 {
955 var self = this;
956 var data = request || undefined;
957
--- ajax/js/whajaj.js
+++ ajax/js/whajaj.js
@@ -405,11 +405,15 @@
405 handling code ASSUMES that the response contains a JSONP-style
406 construct and eval()s it after afterSend() but before onResponse().
407 In this case, onResponse() will get a string value for the response
408 instead of a response object parsed from JSON.
409 */
410 jsonp:undefined,
411 /**
412 Don't use yet. Planned future option.
413 */
414 propagateExceptions:false
415 }
416 };
417
418
419 /**
@@ -947,10 +951,18 @@
951 - timeouts are not supported.
952
953 - asynchronous mode is not supported because implementing it
954 requires the ability to kill a running thread (which is deprecated
955 in the Java API).
956
957 TODOs:
958
959 - add socket timeouts.
960
961 - support HTTP proxy.
962
963 The Java APIs support this, it just hasn't been added here yet.
964 */
965 rhino:function(request,args)
966 {
967 var self = this;
968 var data = request || undefined;
969

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button