Make all of the File.* operations async.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3675 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2021-10-28 00:53:16 +00:00
parent 77ec1a0b2e
commit 21ba7cb02c
2 changed files with 109 additions and 65 deletions

View File

@ -496,7 +496,6 @@ static void _test_file(const tf_test_options_t* options)
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"
@ -507,19 +506,35 @@ static void _test_file(const tf_test_options_t* options)
"}).catch(function(error) {\n"
" print('expected error', error);\n"
"});\n"
"File.writeFile('out/new.txt', 'hello').then(function(result) {\n"
" File.readFile('out/new.txt').then(function(data) {\n"
" print('READ', utf8Decode(data));\n"
" if (utf8Decode(data) != 'hello') {\n"
"File.unlinkFile('out/test/new.txt').finally(function() {\n"
" return File.removeDirectory('out/test');\n"
"}).finally(function() {\n"
" return File.makeDirectory('out/test').then(function() {\n"
" return File.writeFile('out/test/new.txt', 'hello').then(function(result) {\n"
" return File.readFile('out/test/new.txt').then(function(data) {\n"
" if (utf8Decode(data) != 'hello') {\n"
" print('READ', utf8Decode(data));\n"
" exit(1);\n"
" }\n"
" }).catch(function(error) {\n"
" print('unexpected read error', error);\n"
" exit(1);\n"
" });\n"
" }).catch(function(error) {\n"
" print('unexpected write error', error);\n"
" exit(1);\n"
" }\n"
" });\n"
" }).catch(function(error) {\n"
" print('unexpected read error', error);\n"
" print('unexpected make directory error', error);\n"
" exit(1);\n"
" });\n"
"}).catch(function(error) {\n"
" print('unexpected write error', error);\n"
" exit(1);\n"
"}).finally(function() {\n"
" return File.renameFile('out/test/new.txt', 'out/test/renamed.txt').catch(x => print(x)).finally(function() {\n"
" return File.unlinkFile('out/test/renamed.txt').catch(x => print(x)).finally(function() {\n"
" print('removing directory');\n"
" return File.removeDirectory('out/test').catch(x => print(x));\n"
" });\n"
" });\n"
"});\n");
fclose(file);