diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d7d62ea..483409e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 diff --git a/test/restart.c b/test/restart.c new file mode 100644 index 0000000..e46f149 --- /dev/null +++ b/test/restart.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include + +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; +}