Some test fixes, and introduce some pledge and unveil for OpenBSD.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4851 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
43
src/tests.c
43
src/tests.c
@ -34,7 +34,7 @@
|
||||
#if !TARGET_OS_IPHONE
|
||||
static void _write_file(const char* path, const char* contents)
|
||||
{
|
||||
FILE* file = fopen("out/test.js", "w");
|
||||
FILE* file = fopen(path, "w");
|
||||
if (!file)
|
||||
{
|
||||
printf("Unable to write %s: %s.\n", path, strerror(errno));
|
||||
@ -58,12 +58,48 @@ static void _test_nop(const tf_test_options_t* options)
|
||||
assert(WEXITSTATUS(result) == 0);
|
||||
}
|
||||
|
||||
static void _test_sandbox(const tf_test_options_t* options)
|
||||
{
|
||||
_write_file("out/test.js",
|
||||
"var task = new Task();\n"
|
||||
"task.onExit = function(code, signal) {\n"
|
||||
" print('child exited', code, signal);\n"
|
||||
" if (code === 0 && signal === 0) {\n"
|
||||
" exit(1);\n"
|
||||
" }\n"
|
||||
"};\n"
|
||||
"task.activate();\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"
|
||||
"});");
|
||||
|
||||
_write_file("out/child.js",
|
||||
"print('Poking the sandbox. This should fail.');\n"
|
||||
"pokeSandbox();\n"
|
||||
"print('We poked the sandbox without failing.');\n"
|
||||
"exit(0);\n");
|
||||
|
||||
char command[256];
|
||||
snprintf(command, sizeof(command), "%s run --db-path=:memory: -s out/test.js" TEST_ARGS, options->exe_path);
|
||||
tf_printf("%s\n", command);
|
||||
int result = system(command);
|
||||
(void)result;
|
||||
assert(WIFEXITED(result));
|
||||
assert(WEXITSTATUS(result) == 0);
|
||||
|
||||
unlink("out/test.js");
|
||||
unlink("out/child.js");
|
||||
}
|
||||
|
||||
static void _test_child(const tf_test_options_t* options)
|
||||
{
|
||||
_write_file("out/test.js",
|
||||
"var task = new Task();\n"
|
||||
"task.onExit = function() {\n"
|
||||
" print('child exited');\n"
|
||||
"task.onExit = function(code, signal) {\n"
|
||||
" print('child exited', code, signal);\n"
|
||||
" exit(code || signal);\n"
|
||||
"};\n"
|
||||
"task.activate();\n"
|
||||
"File.readFile('out/child.js').then(function(data) {\n"
|
||||
@ -846,6 +882,7 @@ void tf_tests(const tf_test_options_t* options)
|
||||
_tf_test_run(options, "ssb_id", tf_ssb_test_id_conversion, false);
|
||||
_tf_test_run(options, "ssb_following", tf_ssb_test_following, false);
|
||||
_tf_test_run(options, "nop", _test_nop, false);
|
||||
_tf_test_run(options, "sandbox", _test_sandbox, false);
|
||||
_tf_test_run(options, "child", _test_child, false);
|
||||
_tf_test_run(options, "promise", _test_promise, false);
|
||||
_tf_test_run(options, "promise_remote_throw", _test_promise_remote_throw, false);
|
||||
|
Reference in New Issue
Block a user