forked from cory/tildefriends
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"
|
" print('child exited');\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"task.activate();\n"
|
"task.activate();\n"
|
||||||
"task.execute({name: 'child.js', source: utf8Decode(File.readFile('out/child.js'))}).then(function() {\n"
|
"File.readFile('out/child.js').then(function(data) {\n"
|
||||||
" print('child started');\n"
|
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
|
||||||
|
" print('child started');\n"
|
||||||
|
" });\n"
|
||||||
"});");
|
"});");
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
@ -62,15 +64,17 @@ static void _test_promise(const tf_test_options_t* options)
|
|||||||
fprintf(file,
|
fprintf(file,
|
||||||
"var task = new Task();\n"
|
"var task = new Task();\n"
|
||||||
"task.activate();\n"
|
"task.activate();\n"
|
||||||
"task.execute({name: 'child.js', source: utf8Decode(File.readFile('out/child.js'))}).then(function() {\n"
|
"File.readFile('out/child.js').then(function(data) {\n"
|
||||||
" task.getExports().then(function(exports) {\n"
|
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
|
||||||
" return exports.add(1, 1);\n"
|
" task.getExports().then(function(exports) {\n"
|
||||||
" }).then(function(sum) {\n"
|
" return exports.add(1, 1);\n"
|
||||||
" if (sum == 2) {\n"
|
" }).then(function(sum) {\n"
|
||||||
" exit(0);\n"
|
" if (sum == 2) {\n"
|
||||||
" } else {\n"
|
" exit(0);\n"
|
||||||
" exit(1);\n"
|
" } else {\n"
|
||||||
" }\n"
|
" exit(1);\n"
|
||||||
|
" }\n"
|
||||||
|
" });\n"
|
||||||
" });\n"
|
" });\n"
|
||||||
"});\n");
|
"});\n");
|
||||||
fclose(file);
|
fclose(file);
|
||||||
@ -102,20 +106,22 @@ static void _test_promise_remote_throw(const tf_test_options_t* options)
|
|||||||
fprintf(file,
|
fprintf(file,
|
||||||
"var task = new Task();\n"
|
"var task = new Task();\n"
|
||||||
"task.activate();\n"
|
"task.activate();\n"
|
||||||
"task.execute({name: 'child.js', source: utf8Decode(File.readFile('out/child.js'))}).then(function() {\n"
|
"File.readFile('out/child.js').then(function(data) {\n"
|
||||||
" task.getExports().then(function(exp) {\n"
|
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
|
||||||
" return exp.add(1, 1);\n"
|
" task.getExports().then(function(exp) {\n"
|
||||||
" }).then(function(sum) {\n"
|
" return exp.add(1, 1);\n"
|
||||||
" exit(1);\n"
|
" }).then(function(sum) {\n"
|
||||||
" }).catch(function(error) {\n"
|
" exit(1);\n"
|
||||||
" print('Caught: ' + error.message);\n"
|
" }).catch(function(error) {\n"
|
||||||
" if (error.stack) {\n"
|
" print('Caught: ' + error.message);\n"
|
||||||
" print('stack: ' + error.stack);\n"
|
" if (error.stack) {\n"
|
||||||
" }\n"
|
" print('stack: ' + error.stack);\n"
|
||||||
" exit(0);\n"
|
" }\n"
|
||||||
|
" exit(0);\n"
|
||||||
|
" });\n"
|
||||||
|
" }).catch(function(e) {\n"
|
||||||
|
" print('caught', e.message);\n"
|
||||||
" });\n"
|
" });\n"
|
||||||
"}).catch(function(e) {\n"
|
|
||||||
" print('caught', e.message);\n"
|
|
||||||
"});\n");
|
"});\n");
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
@ -146,20 +152,22 @@ static void _test_promise_remote_reject(const tf_test_options_t* options)
|
|||||||
fprintf(file,
|
fprintf(file,
|
||||||
"var task = new Task();\n"
|
"var task = new Task();\n"
|
||||||
"task.activate();\n"
|
"task.activate();\n"
|
||||||
"task.execute({name: 'child.js', source: utf8Decode(File.readFile('out/child.js'))}).then(function() {\n"
|
"File.readFile('out/child.js').then(function(data) {\n"
|
||||||
" task.getExports().then(function(exp) {\n"
|
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(function() {\n"
|
||||||
" return exp.add(1, 1);\n"
|
" task.getExports().then(function(exp) {\n"
|
||||||
" }).then(function(sum) {\n"
|
" return exp.add(1, 1);\n"
|
||||||
" exit(1);\n"
|
" }).then(function(sum) {\n"
|
||||||
" }).catch(function(error) {\n"
|
" exit(1);\n"
|
||||||
" print('Caught: ' + error.message);\n"
|
" }).catch(function(error) {\n"
|
||||||
" if (error.stack) {\n"
|
" print('Caught: ' + error.message);\n"
|
||||||
" print('stack: ' + error.stack);\n"
|
" if (error.stack) {\n"
|
||||||
" }\n"
|
" print('stack: ' + error.stack);\n"
|
||||||
" exit(0);\n"
|
" }\n"
|
||||||
|
" exit(0);\n"
|
||||||
|
" });\n"
|
||||||
|
" }).catch(function(e) {\n"
|
||||||
|
" print('caught', e.message);\n"
|
||||||
" });\n"
|
" });\n"
|
||||||
"}).catch(function(e) {\n"
|
|
||||||
" print('caught', e.message);\n"
|
|
||||||
"});\n");
|
"});\n");
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
@ -259,7 +267,7 @@ static void _test_await(const tf_test_options_t* options)
|
|||||||
"print('hi');\n"
|
"print('hi');\n"
|
||||||
|
|
||||||
"function foobar() {\n"
|
"function foobar() {\n"
|
||||||
" return new Promise(function (resolve, reject) {\n"
|
" return new Promise(function(resolve, reject) {\n"
|
||||||
" resolve(10);\n"
|
" resolve(10);\n"
|
||||||
" });\n"
|
" });\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
@ -375,25 +383,27 @@ static void _test_uint8array(const tf_test_options_t* options)
|
|||||||
" print('child exited');\n"
|
" print('child exited');\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"task.activate();\n"
|
"task.activate();\n"
|
||||||
"task.execute({name: 'child.js', source: utf8Decode(File.readFile('out/child.js'))}).then(async function() {\n"
|
"File.readFile('out/child.js').then(function(data) {\n"
|
||||||
" print('child started');\n"
|
" task.execute({name: 'child.js', source: utf8Decode(data)}).then(async function() {\n"
|
||||||
" var input = new Uint8Array(10);\n"
|
" print('child started');\n"
|
||||||
" for (var i = 0; i < 10; i++) {\n"
|
" var input = new Uint8Array(10);\n"
|
||||||
" input[i] = i;\n"
|
" for (var i = 0; i < 10; i++) {\n"
|
||||||
" }\n"
|
" input[i] = i;\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"
|
||||||
" }\n"
|
" var test = (await task.getExports()).test;\n"
|
||||||
" exit(0);\n"
|
" var output = new Uint8Array(await test(input));\n"
|
||||||
"});\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);
|
fclose(file);
|
||||||
|
|
||||||
file = fopen("out/child.js", "w");
|
file = fopen("out/child.js", "w");
|
||||||
|
Loading…
Reference in New Issue
Block a user