Made File.readFile async.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3667 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2021-10-06 01:25:33 +00:00
parent 24a91219c1
commit 470814f147
5 changed files with 196 additions and 144 deletions

View File

@ -480,6 +480,36 @@ static void _test_socket(const tf_test_options_t* options)
unlink("out/test.js");
}
static void _test_file(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
"'use strict';\n"
"File.readFile('out/test.js').then(function(data) {\n"
" print('READ', utf8Decode(data));\n"
"}).catch(function(error) {\n"
" print('ERROR', error);\n"
" exit(1);\n"
"});\n"
"File.readFile('out/missing.txt').then(function(data) {\n"
" print('READ', utf8Decode(data));\n"
" exit(1);\n"
"}).catch(function(error) {\n"
" print('expected error', error);\n"
"});\n");
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/test.js", options->exe_path);
printf("%s\n", command);
int result = system(command);
printf("returned %d\n", WEXITSTATUS(result));
assert(WIFEXITED(result));
assert(WEXITSTATUS(result) == 0);
unlink("out/test.js");
}
static void _tf_test_run(const tf_test_options_t* options, const char* name, void (*test)(const tf_test_options_t* options))
{
bool specified = false;
@ -521,5 +551,6 @@ void tf_tests(const tf_test_options_t* options)
_tf_test_run(options, "icu", _test_icu);
_tf_test_run(options, "uint8array", _test_uint8array);
_tf_test_run(options, "socket", _test_socket);
_tf_test_run(options, "file", _test_file);
printf("Tests completed.\n");
}