Appease gcc 12's analyzer.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4740 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2024-01-07 21:08:20 +00:00
parent d5ede43a13
commit 21d4a9b328
3 changed files with 174 additions and 171 deletions

View File

@ -30,11 +30,22 @@
#endif
#if !TARGET_OS_IPHONE
static void _test_nop(const tf_test_options_t* options)
static void _write_file(const char* path, const char* contents)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file, "print('hi');");
if (!file)
{
printf("Unable to write %s: %s.\n", path, strerror(errno));
fflush(stdout);
abort();
}
fputs(contents, file);
fclose(file);
}
static void _test_nop(const tf_test_options_t* options)
{
_write_file("out/test.js", "print('hi');");
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -47,8 +58,8 @@ static void _test_nop(const tf_test_options_t* options)
static void _test_child(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"var task = new Task();\n"
"task.onExit = function() {\n"
" print('child exited');\n"
@ -59,13 +70,11 @@ static void _test_child(const tf_test_options_t* options)
" print('child started');\n"
" });\n"
"});");
fclose(file);
file = fopen("out/child.js", "w");
fprintf(file,
_write_file(
"out/child.js",
"print('I am the child process.');\n"
"exit(0);\n");
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -81,8 +90,7 @@ static void _test_child(const tf_test_options_t* options)
static void _test_promise(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file("out/test.js",
"var task = new Task();\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
@ -98,16 +106,14 @@ static void _test_promise(const tf_test_options_t* options)
" });\n"
" });\n"
"});\n");
fclose(file);
file = fopen("out/child.js", "w");
fprintf(file,
_write_file(
"out/child.js",
"exports = {\n"
" add: function(left, right) {\n"
" return left + right;\n"
" }\n"
"}\n");
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -123,8 +129,8 @@ static void _test_promise(const tf_test_options_t* options)
static void _test_promise_remote_throw(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"var task = new Task();\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
@ -144,16 +150,14 @@ static void _test_promise_remote_throw(const tf_test_options_t* options)
" print('caught', e.message);\n"
" });\n"
"});\n");
fclose(file);
file = fopen("out/child.js", "w");
fprintf(file,
_write_file(
"out/child.js",
"exports = {\n"
" add: function(left, right) {\n"
" throw new Error('fail');\n"
" }\n"
"}\n");
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -169,8 +173,8 @@ static void _test_promise_remote_throw(const tf_test_options_t* options)
static void _test_promise_remote_reject(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"var task = new Task();\n"
"task.activate();\n"
"File.readFile('out/child.js').then(function(data) {\n"
@ -190,10 +194,9 @@ static void _test_promise_remote_reject(const tf_test_options_t* options)
" print('caught', e.message);\n"
" });\n"
"});\n");
fclose(file);
file = fopen("out/child.js", "w");
fprintf(file,
_write_file(
"out/child.js",
"exports = {\n"
" add: function(left, right) {\n"
" return new Promise(function(resolve, reject) {\n"
@ -201,7 +204,6 @@ static void _test_promise_remote_reject(const tf_test_options_t* options)
" });\n"
" }\n"
"}\n");
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -217,8 +219,8 @@ static void _test_promise_remote_reject(const tf_test_options_t* options)
static void _test_database(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"var db = new Database('testdb');\n"
"if (db.get('a')) {\n"
" exit(1);\n"
@ -245,7 +247,6 @@ static void _test_database(const tf_test_options_t* options)
" print('Expected but did not find: ' + JSON.stringify(expected));\n"
" exit(4);\n"
"}\n");
fclose(file);
char command[256];
unlink("out/test_db0.sqlite");
@ -262,12 +263,11 @@ static void _test_database(const tf_test_options_t* options)
static void _test_this(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"var task = new Task();\n"
"task.activate.bind(null).apply();\n"
"exit(0);\n");
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -282,10 +282,9 @@ static void _test_this(const tf_test_options_t* options)
static void _test_await(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"print('hi');\n"
"function foobar() {\n"
" return new Promise(function(resolve, reject) {\n"
" resolve(10);\n"
@ -300,7 +299,6 @@ static void _test_await(const tf_test_options_t* options)
" }\n"
"}\n"
"\n");
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -315,28 +313,25 @@ static void _test_await(const tf_test_options_t* options)
static void _test_import(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"import * as req from './required.js';\n"
"if (req.foo() != 12345) {\n"
" exit(1);\n"
"}\n");
fclose(file);
file = fopen("out/required.js", "w");
fprintf(file,
_write_file(
"out/required.js",
"export function foo() {\n"
" return 12345;\n"
"}\n");
fclose(file);
file = fopen("out/bad.js", "w");
fprintf(file,
_write_file(
"out/bad.js",
"import * as req from './missing.js';\n"
"if (req.foo() != 12345) {\n"
" exit(1);\n"
"}\n");
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -360,13 +355,8 @@ static void _test_import(const tf_test_options_t* options)
static void _test_exit(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file, "import * as blah from './blah.js';\n");
fclose(file);
file = fopen("out/blah.js", "w");
fprintf(file, "\n");
fclose(file);
_write_file("out/test.js", "import * as blah from './blah.js';\n");
_write_file("out/blah.js", "\n");
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -382,11 +372,10 @@ static void _test_exit(const tf_test_options_t* options)
static void _test_icu(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"print('Hi');\n"
"print(parseInt('3').toLocaleString());\n");
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -401,8 +390,8 @@ static void _test_icu(const tf_test_options_t* options)
static void _test_uint8array(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"var task = new Task();\n"
"task.onExit = function() {\n"
" print('child exited');\n"
@ -429,16 +418,14 @@ static void _test_uint8array(const tf_test_options_t* options)
" exit(0);\n"
" })\n"
"})\n");
fclose(file);
file = fopen("out/child.js", "w");
fprintf(file,
_write_file(
"out/child.js",
"exports = {\n"
" test: function(data) {\n"
" return data;\n"
" }\n"
"}\n");
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -454,8 +441,8 @@ static void _test_uint8array(const tf_test_options_t* options)
static void _test_float(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"var task = new Task();\n"
"task.onExit = function() {\n"
" print('child exited');\n"
@ -471,10 +458,9 @@ static void _test_float(const tf_test_options_t* options)
" exit(result == 1.2 ? 0 : 1);\n"
" });\n"
"});");
fclose(file);
file = fopen("out/child.js", "w");
fprintf(file,
_write_file(
"out/child.js",
"print(\"child\");\n"
"exports = {\n"
" test: function(value) {\n"
@ -484,7 +470,6 @@ static void _test_float(const tf_test_options_t* options)
"};\n"
"print(\"child ready\");\n"
);
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -500,8 +485,8 @@ static void _test_float(const tf_test_options_t* options)
static void _test_socket(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"'use strict';\n"
"\n"
"var s = new Socket();\n"
@ -573,7 +558,6 @@ static void _test_socket(const tf_test_options_t* options)
" print('caught');\n"
" print(e);\n"
"});\n");
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -588,8 +572,8 @@ static void _test_socket(const tf_test_options_t* options)
static void _test_file(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"'use strict';\n"
"File.readFile('out/test.js').then(function(data) {\n"
"}).catch(function(error) {\n"
@ -602,7 +586,6 @@ static void _test_file(const tf_test_options_t* options)
"}).catch(function(error) {\n"
" print('expected error', error);\n"
"});\n");
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -617,8 +600,8 @@ static void _test_file(const tf_test_options_t* options)
static void _test_sign(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"'use strict';\n"
"let id = ssb.createIdentity('test');\n"
"print(id);\n"
@ -634,7 +617,6 @@ static void _test_sign(const tf_test_options_t* options)
" exit(1);\n"
"}\n"
);
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);
@ -649,8 +631,8 @@ static void _test_sign(const tf_test_options_t* options)
static void _test_b64(const tf_test_options_t* options)
{
FILE* file = fopen("out/test.js", "w");
fprintf(file,
_write_file(
"out/test.js",
"'use strict';\n"
"print(base64Encode('hello'));\n"
"let x = utf8Decode(base64Decode(base64Encode('hello')));\n"
@ -659,7 +641,6 @@ static void _test_b64(const tf_test_options_t* options)
" exit(1);\n"
"}\n"
);
fclose(file);
char command[256];
snprintf(command, sizeof(command), "%s run --ssb-port=0 --db-path=:memory: -s out/test.js", options->exe_path);