forked from cory/tildefriends
Remove require. There is only import+export.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3905 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
43
src/tests.c
43
src/tests.c
@ -299,32 +299,29 @@ static void _test_await(const tf_test_options_t* options)
|
||||
unlink("out/test.js");
|
||||
}
|
||||
|
||||
static void _test_require(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,
|
||||
"if (require('required').foo() != 12345) {\n"
|
||||
"import * as req from './required.js';\n"
|
||||
"if (req.foo() != 12345) {\n"
|
||||
" exit(1);\n"
|
||||
"}\n"
|
||||
"var gotError = false;\n"
|
||||
"try {\n"
|
||||
" require('missing');\n"
|
||||
"} catch (error) {\n"
|
||||
" print('nope');\n"
|
||||
" gotError = true;\n"
|
||||
"}\n"
|
||||
"if (!gotError) {\n"
|
||||
" exit(2);\n"
|
||||
"}\n"
|
||||
"exit(0);\n");
|
||||
"}\n");
|
||||
fclose(file);
|
||||
|
||||
file = fopen("out/required.js", "w");
|
||||
fprintf(file,
|
||||
"function foo() {\n"
|
||||
"export function foo() {\n"
|
||||
" return 12345;\n"
|
||||
"}\n"
|
||||
"exports.foo = foo;\n");
|
||||
"}\n");
|
||||
fclose(file);
|
||||
|
||||
file = fopen("out/bad.js", "w");
|
||||
fprintf(file,
|
||||
"import * as req from './missing.js';\n"
|
||||
"if (req.foo() != 12345) {\n"
|
||||
" exit(1);\n"
|
||||
"}\n");
|
||||
fclose(file);
|
||||
|
||||
char command[256];
|
||||
@ -335,14 +332,22 @@ static void _test_require(const tf_test_options_t* options)
|
||||
assert(WIFEXITED(result));
|
||||
assert(WEXITSTATUS(result) == 0);
|
||||
|
||||
snprintf(command, sizeof(command), "%s run --ssb-port=0 -s out/bad.js", options->exe_path);
|
||||
printf("%s\n", command);
|
||||
result = system(command);
|
||||
printf("returned %d\n", WEXITSTATUS(result));
|
||||
assert(WIFEXITED(result));
|
||||
assert(WEXITSTATUS(result) == 0);
|
||||
|
||||
unlink("out/test.js");
|
||||
unlink("out/required.js");
|
||||
unlink("out/missing.js");
|
||||
}
|
||||
|
||||
static void _test_exit(const tf_test_options_t* options)
|
||||
{
|
||||
FILE* file = fopen("out/test.js", "w");
|
||||
fprintf(file, "require('blah');");
|
||||
fprintf(file, "import * as blah from './blah.js';\n");
|
||||
fclose(file);
|
||||
|
||||
file = fopen("out/blah.js", "w");
|
||||
@ -595,7 +600,7 @@ void tf_tests(const tf_test_options_t* options)
|
||||
_tf_test_run(options, "database", _test_database);
|
||||
_tf_test_run(options, "this", _test_this);
|
||||
_tf_test_run(options, "await", _test_await);
|
||||
_tf_test_run(options, "require", _test_require);
|
||||
_tf_test_run(options, "import", _test_import);
|
||||
_tf_test_run(options, "exit", _test_exit);
|
||||
_tf_test_run(options, "icu", _test_icu);
|
||||
_tf_test_run(options, "uint8array", _test_uint8array);
|
||||
|
Reference in New Issue
Block a user