Skip to content

Commit aaae64b

Browse files
committed
Update embind tests to run with the Closure Compiler
The tests themselves must not be run through the Closure Compiler, as it will mangle references to the names exported through embind. Since embind itself uses string literals to export its names, this would break. Therefore, the tests and adapter are now manually concatenated to the output JavaScript post-Closure. The IMVU test adapter also needed to be updated so that it does not rely on the assert function already having been created by Emscripten. It appears that this was its natural state at some point in history. Note that the embind tests prove that embind is broken when run through the Closure Compiler; embind will be fixed in the next commit :)
1 parent b7967e6 commit aaae64b

File tree

2 files changed

+37
-27
lines changed

2 files changed

+37
-27
lines changed

tests/embind/imvu_test_adapter.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -211,27 +211,27 @@ function module(ignore, func) {
211211
*/
212212
};
213213

214-
// var assert = {
214+
var assert = {
215215

216216
////////////////////////////////////////////////////////////////////////////////
217217
// GENERAL STATUS
218218

219-
assert.fail = function(info) {
219+
fail: function(info) {
220220
info = info || "assert.fail()";
221221
fail(new AssertionError(info));
222222
},
223223

224224
////////////////////////////////////////////////////////////////////////////////
225225
// BOOLEAN TESTS
226226

227-
assert['true'] = function(value) {
227+
'true': function(value) {
228228
if (!value) {
229229
fail(new AssertionError("expected truthy, actual " + formatTestValue(value)),
230230
{Value: value});
231231
}
232232
},
233233

234-
assert['false'] = function(value) {
234+
'false': function(value) {
235235
if (value) {
236236
fail(new AssertionError("expected falsy, actual " + formatTestValue(value)),
237237
{Value: value});
@@ -241,38 +241,38 @@ function module(ignore, func) {
241241
////////////////////////////////////////////////////////////////////////////////
242242
// SCALAR COMPARISON
243243

244-
assert.equal = function(expected, actual) {
244+
equal: function(expected, actual) {
245245
if (expected !== actual) {
246246
fail(new AssertionError('expected: ' + formatTestValue(expected) + ', actual: ' + formatTestValue(actual)),
247247
{Expected: expected, Actual: actual});
248248
}
249249
},
250250

251-
assert.notEqual = function(expected, actual) {
251+
notEqual: function(expected, actual) {
252252
if (expected === actual) {
253253
fail(new AssertionError('actual was equal to: ' + formatTestValue(expected)));
254254
}
255255
},
256256

257-
assert.greater = function(lhs, rhs) {
257+
greater: function(lhs, rhs) {
258258
if (lhs <= rhs) {
259259
fail(new AssertionError(formatTestValue(lhs) + ' not greater than ' + formatTestValue(rhs)));
260260
}
261261
},
262262

263-
assert.less = function(lhs, rhs) {
263+
less: function(lhs, rhs) {
264264
if (lhs >= rhs) {
265265
fail(new AssertionError(formatTestValue(lhs) + ' not less than ' + formatTestValue(rhs)));
266266
}
267267
},
268268

269-
assert.greaterOrEqual = function(lhs, rhs) {
269+
greaterOrEqual: function(lhs, rhs) {
270270
if (lhs < rhs) {
271271
fail(new AssertionError(formatTestValue(lhs) + ' not greater than or equal to ' + formatTestValue(rhs)));
272272
}
273273
},
274274

275-
assert.lessOrEqual = function(lhs, rhs) {
275+
lessOrEqual: function(lhs, rhs) {
276276
if (lhs > rhs) {
277277
fail(new AssertionError(formatTestValue(lhs) + ' not less than or equal to ' + formatTestValue(rhs)));
278278
}
@@ -281,14 +281,14 @@ function module(ignore, func) {
281281
////////////////////////////////////////////////////////////////////////////////
282282
// DEEP COMPARISON
283283

284-
assert.deepEqual = function(expected, actual) {
284+
deepEqual: function(expected, actual) {
285285
if (!_.isEqual(expected, actual)) {
286286
fail(new AssertionError('expected: ' + formatTestValue(expected) + ', actual: ' + formatTestValue(actual)),
287287
{Expected: expected, Actual: actual});
288288
}
289289
},
290290

291-
assert.notDeepEqual = function(expected, actual) {
291+
notDeepEqual: function(expected, actual) {
292292
if (_.isEqual(expected, actual)) {
293293
fail(new AssertionError('expected: ' + formatTestValue(expected) + ' and actual: ' + formatTestValue(actual) + ' were equal'));
294294
}
@@ -297,7 +297,7 @@ function module(ignore, func) {
297297
////////////////////////////////////////////////////////////////////////////////
298298
// FLOATING POINT
299299

300-
assert.nearEqual = function( expected, actual, tolerance ) {
300+
nearEqual: function( expected, actual, tolerance ) {
301301
if( tolerance === undefined ) {
302302
tolerance = 0.0;
303303
}
@@ -318,21 +318,21 @@ function module(ignore, func) {
318318
////////////////////////////////////////////////////////////////////////////////
319319
// STRING
320320

321-
assert.inString = function(expected, string){
321+
inString: function(expected, string){
322322
if (-1 === string.indexOf(expected)){
323323
fail(new AssertionError('expected: ' + formatTestValue(expected) + ' not in string: ' + formatTestValue(string)),
324324
{Expected: expected, 'String': string});
325325
}
326326
},
327327

328-
assert.notInString = function(expected, string){
328+
notInString: function(expected, string){
329329
if (-1 !== string.indexOf(expected)){
330330
fail(new AssertionError('unexpected: ' + formatTestValue(expected) + ' in string: ' + formatTestValue(string)),
331331
{Expected: expected, 'String': string});
332332
}
333333
},
334334

335-
assert.matches = function(re, string) {
335+
matches: function(re, string) {
336336
if (!re.test(string)) {
337337
fail(new AssertionError('regexp ' + re + ' does not match: ' + string));
338338
}
@@ -341,7 +341,7 @@ function module(ignore, func) {
341341
////////////////////////////////////////////////////////////////////////////////
342342
// ARRAY
343343

344-
assert.inArray = function(expected, array) {
344+
inArray: function(expected, array) {
345345
var found = false;
346346
_.each(array, function(element){
347347
if (_.isEqual(expected, element)){
@@ -354,7 +354,7 @@ function module(ignore, func) {
354354
}
355355
},
356356

357-
assert.notInArray = function(expected, array) {
357+
notInArray: function(expected, array) {
358358
var found = false;
359359
_.each(array, function(element){
360360
if (_.isEqual(expected, element)){
@@ -370,13 +370,13 @@ function module(ignore, func) {
370370
////////////////////////////////////////////////////////////////////////////////
371371
// OBJECTS
372372

373-
assert.hasKey = function (key, object) {
373+
hasKey: function (key, object) {
374374
if (!(key in object)) {
375375
fail(new AssertionError('Key ' + formatTestValue(key) + ' is not in object: ' + formatTestValue(object)));
376376
}
377377
},
378378

379-
assert.notHasKey = function (key, object) {
379+
notHasKey: function (key, object) {
380380
if (key in object) {
381381
fail(new AssertionError('Unexpected key ' + formatTestValue(key) + ' is found in object: ' + formatTestValue(object)));
382382
}
@@ -385,7 +385,7 @@ function module(ignore, func) {
385385
////////////////////////////////////////////////////////////////////////////////
386386
// EXCEPTIONS
387387

388-
assert.throws = function(exception, fn) {
388+
throws: function(exception, fn) {
389389
try {
390390
fn();
391391
} catch (e) {
@@ -401,7 +401,7 @@ function module(ignore, func) {
401401
////////////////////////////////////////////////////////////////////////////////
402402
// TYPE
403403

404-
assert['instanceof'] = function(actual, type) {
404+
'instanceof': function(actual, type) {
405405
if(!(actual instanceof type)) {
406406
fail(new AssertionError(formatTestValue(actual) + ' not instance of ' + formatTestValue(type)),
407407
{Type: type, Actual: actual});
@@ -412,7 +412,7 @@ function module(ignore, func) {
412412
// DOM ASSERTIONS
413413

414414
// TODO: lift into separate file?
415-
assert.dom = {
415+
dom: {
416416
present: function(domElement){
417417
if (!$(domElement).length) {
418418
fail(new AssertionError(decipherDomElement(domElement) + ' should be present'));
@@ -539,8 +539,8 @@ function module(ignore, func) {
539539
fail(new AssertionError(decipherDomElement(el) + ' expected NOT to be empty'));
540540
}
541541
}
542-
};
543-
// };
542+
}
543+
};
544544

545545
function decipherDomElement(selectorOrJQueryObject) {
546546
if (typeof selectorOrJQueryObject === 'string') {

tests/test_other.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,14 +2045,24 @@ def test_embind(self):
20452045
(['--bind'], False),
20462046
(['--bind', '-O1'], False),
20472047
(['--bind', '-O2'], False),
2048+
(['--bind', '-O2', '--closure', '1'], False),
20482049
]:
20492050
print args, fail
20502051
self.clear()
20512052
try_delete(self.in_dir('a.out.js'))
2052-
Popen([PYTHON, EMCC, path_from_root('tests', 'embind', 'embind_test.cpp'), '--post-js', path_from_root('tests', 'embind', 'underscore-1.4.2.js'), '--post-js', path_from_root('tests', 'embind', 'imvu_test_adapter.js'), '--post-js', path_from_root('tests', 'embind', 'embind.test.js')] + args, stderr=PIPE if fail else None).communicate()
2053+
Popen([PYTHON, EMCC, path_from_root('tests', 'embind', 'embind_test.cpp')] + args, stderr=PIPE if fail else None).communicate()
20532054
assert os.path.exists(self.in_dir('a.out.js')) == (not fail)
20542055
if not fail:
2055-
output = run_js(self.in_dir('a.out.js'), stdout=PIPE, stderr=PIPE, full_output=True, assert_returncode=0)
2056+
with open(self.in_dir('concat.js'), 'w') as outfile:
2057+
outfile.write('var Module=(function(){') # wrap output in function closure to prevent name leakage
2058+
with open(self.in_dir('a.out.js'), 'r') as infile:
2059+
outfile.write(infile.read())
2060+
outfile.write('\nreturn module["exports"];})();\n')
2061+
for filename in ['underscore-1.4.2.js', 'imvu_test_adapter.js', 'embind.test.js']:
2062+
with open(path_from_root('tests', 'embind', filename), 'r') as infile:
2063+
outfile.write(infile.read())
2064+
outfile.write('\n')
2065+
output = run_js(self.in_dir('concat.js'), stdout=PIPE, stderr=PIPE, full_output=True, assert_returncode=0)
20562066
assert "FAIL" not in output, output
20572067

20582068
def test_llvm_nativizer(self):

0 commit comments

Comments
 (0)