Fix tests in light of async File.readFile.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3669 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
843c53e15e
commit
786c83c57c
122
src/tests.c
122
src/tests.c
@ -33,8 +33,10 @@ static void _test_child(const tf_test_options_t* options)
|
||||
" print('child exited');\n"
|
||||
"};\n"
|
||||
"task.activate();\n"
|
||||
"task.execute({name: 'child.js', source: utf8Decode(File.readFile('out/child.js'))}).then(function() {\n"
|
||||
" print('child started');\n"
|
||||
"File.readFile('out/child.js').then(function(data) {\n"
|
||||
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
|
||||
" print('child started');\n"
|
||||
" });\n"
|
||||
"});");
|
||||
fclose(file);
|
||||
|
||||
@ -62,15 +64,17 @@ static void _test_promise(const tf_test_options_t* options)
|
||||
fprintf(file,
|
||||
"var task = new Task();\n"
|
||||
"task.activate();\n"
|
||||
"task.execute({name: 'child.js', source: utf8Decode(File.readFile('out/child.js'))}).then(function() {\n"
|
||||
" task.getExports().then(function(exports) {\n"
|
||||
" return exports.add(1, 1);\n"
|
||||
" }).then(function(sum) {\n"
|
||||
" if (sum == 2) {\n"
|
||||
" exit(0);\n"
|
||||
" } else {\n"
|
||||
" exit(1);\n"
|
||||
" }\n"
|
||||
"File.readFile('out/child.js').then(function(data) {\n"
|
||||
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
|
||||
" task.getExports().then(function(exports) {\n"
|
||||
" return exports.add(1, 1);\n"
|
||||
" }).then(function(sum) {\n"
|
||||
" if (sum == 2) {\n"
|
||||
" exit(0);\n"
|
||||
" } else {\n"
|
||||
" exit(1);\n"
|
||||
" }\n"
|
||||
" });\n"
|
||||
" });\n"
|
||||
"});\n");
|
||||
fclose(file);
|
||||
@ -102,20 +106,22 @@ static void _test_promise_remote_throw(const tf_test_options_t* options)
|
||||
fprintf(file,
|
||||
"var task = new Task();\n"
|
||||
"task.activate();\n"
|
||||
"task.execute({name: 'child.js', source: utf8Decode(File.readFile('out/child.js'))}).then(function() {\n"
|
||||
" task.getExports().then(function(exp) {\n"
|
||||
" return exp.add(1, 1);\n"
|
||||
" }).then(function(sum) {\n"
|
||||
" exit(1);\n"
|
||||
" }).catch(function(error) {\n"
|
||||
" print('Caught: ' + error.message);\n"
|
||||
" if (error.stack) {\n"
|
||||
" print('stack: ' + error.stack);\n"
|
||||
" }\n"
|
||||
" exit(0);\n"
|
||||
"File.readFile('out/child.js').then(function(data) {\n"
|
||||
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
|
||||
" task.getExports().then(function(exp) {\n"
|
||||
" return exp.add(1, 1);\n"
|
||||
" }).then(function(sum) {\n"
|
||||
" exit(1);\n"
|
||||
" }).catch(function(error) {\n"
|
||||
" print('Caught: ' + error.message);\n"
|
||||
" if (error.stack) {\n"
|
||||
" print('stack: ' + error.stack);\n"
|
||||
" }\n"
|
||||
" exit(0);\n"
|
||||
" });\n"
|
||||
" }).catch(function(e) {\n"
|
||||
" print('caught', e.message);\n"
|
||||
" });\n"
|
||||
"}).catch(function(e) {\n"
|
||||
" print('caught', e.message);\n"
|
||||
"});\n");
|
||||
fclose(file);
|
||||
|
||||
@ -146,20 +152,22 @@ static void _test_promise_remote_reject(const tf_test_options_t* options)
|
||||
fprintf(file,
|
||||
"var task = new Task();\n"
|
||||
"task.activate();\n"
|
||||
"task.execute({name: 'child.js', source: utf8Decode(File.readFile('out/child.js'))}).then(function() {\n"
|
||||
" task.getExports().then(function(exp) {\n"
|
||||
" return exp.add(1, 1);\n"
|
||||
" }).then(function(sum) {\n"
|
||||
" exit(1);\n"
|
||||
" }).catch(function(error) {\n"
|
||||
" print('Caught: ' + error.message);\n"
|
||||
" if (error.stack) {\n"
|
||||
" print('stack: ' + error.stack);\n"
|
||||
" }\n"
|
||||
" exit(0);\n"
|
||||
"File.readFile('out/child.js').then(function(data) {\n"
|
||||
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
|
||||
" task.getExports().then(function(exp) {\n"
|
||||
" return exp.add(1, 1);\n"
|
||||
" }).then(function(sum) {\n"
|
||||
" exit(1);\n"
|
||||
" }).catch(function(error) {\n"
|
||||
" print('Caught: ' + error.message);\n"
|
||||
" if (error.stack) {\n"
|
||||
" print('stack: ' + error.stack);\n"
|
||||
" }\n"
|
||||
" exit(0);\n"
|
||||
" });\n"
|
||||
" }).catch(function(e) {\n"
|
||||
" print('caught', e.message);\n"
|
||||
" });\n"
|
||||
"}).catch(function(e) {\n"
|
||||
" print('caught', e.message);\n"
|
||||
"});\n");
|
||||
fclose(file);
|
||||
|
||||
@ -259,7 +267,7 @@ static void _test_await(const tf_test_options_t* options)
|
||||
"print('hi');\n"
|
||||
|
||||
"function foobar() {\n"
|
||||
" return new Promise(function (resolve, reject) {\n"
|
||||
" return new Promise(function(resolve, reject) {\n"
|
||||
" resolve(10);\n"
|
||||
" });\n"
|
||||
"}\n"
|
||||
@ -375,25 +383,27 @@ static void _test_uint8array(const tf_test_options_t* options)
|
||||
" print('child exited');\n"
|
||||
"};\n"
|
||||
"task.activate();\n"
|
||||
"task.execute({name: 'child.js', source: utf8Decode(File.readFile('out/child.js'))}).then(async function() {\n"
|
||||
" print('child started');\n"
|
||||
" var input = new Uint8Array(10);\n"
|
||||
" for (var i = 0; i < 10; i++) {\n"
|
||||
" input[i] = i;\n"
|
||||
" }\n"
|
||||
" var test = (await task.getExports()).test;\n"
|
||||
" var output = new Uint8Array(await test(input));\n"
|
||||
" print('input', input, input.length, input.byteLength);\n"
|
||||
" print('output', output, output.length, output.byteLength);\n"
|
||||
" for (var i = 0; i < 10; i++) {\n"
|
||||
" print(output[i]);\n"
|
||||
" if (output[i] != i) {\n"
|
||||
" print('output[' + i + '] == ' + output[i]);\n"
|
||||
" exit(1);\n"
|
||||
"File.readFile('out/child.js').then(function(data) {\n"
|
||||
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(async function() {\n"
|
||||
" print('child started');\n"
|
||||
" var input = new Uint8Array(10);\n"
|
||||
" for (var i = 0; i < 10; i++) {\n"
|
||||
" input[i] = i;\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" exit(0);\n"
|
||||
"});\n");
|
||||
" var test = (await task.getExports()).test;\n"
|
||||
" var output = new Uint8Array(await test(input));\n"
|
||||
" print('input', input, input.length, input.byteLength);\n"
|
||||
" print('output', output, output.length, output.byteLength);\n"
|
||||
" for (var i = 0; i < 10; i++) {\n"
|
||||
" print(output[i]);\n"
|
||||
" if (output[i] != i) {\n"
|
||||
" print('output[' + i + '] == ' + output[i]);\n"
|
||||
" exit(1);\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" exit(0);\n"
|
||||
" })\n"
|
||||
"})\n");
|
||||
fclose(file);
|
||||
|
||||
file = fopen("out/child.js", "w");
|
||||
|
Loading…
Reference in New Issue
Block a user