Skip to content

Commit

Permalink
Add restart test
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperisager committed Jun 5, 2024
1 parent eb7d6c3 commit df6fe4f
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ list(APPEND tests
import-dynamic-mjs.mjs
import-mjs.cjs
import-mjs.mjs
restart.c
suspend-from-thread.js
suspend-resume.js
suspend-resume-from-thread.js
Expand Down
50 changes: 50 additions & 0 deletions test/restart.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <assert.h>
#include <bare.h>
#include <js.h>
#include <string.h>
#include <uv.h>

int
main (int argc, char *argv[]) {
int e;

argc = 0;
argv = NULL;

argv = uv_setup_args(argc, argv);

js_platform_t *platform;
e = js_create_platform(uv_default_loop(), NULL, &platform);
assert(e == 0);

int exit_code = 0;

do {
bare_t *bare;
e = bare_setup(uv_default_loop(), platform, NULL, argc, argv, NULL, &bare);
assert(e == 0);

char *code;

if (exit_code == 0) {
code = "console.log('Restarting'); Bare.exit(1)";
} else {
code = "console.log('Restarted')";
}

uv_buf_t source = uv_buf_init(code, strlen(code));

bare_run(bare, "/test.js", &source);

e = bare_teardown(bare, &exit_code);
assert(e == 0);
} while (exit_code == 1);

e = js_destroy_platform(platform);
assert(e == 0);

e = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
assert(e == 0);

return exit_code;
}

0 comments on commit df6fe4f

Please sign in to comment.