mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
js: Remove test mode
Now that we have a standalone test-js program, the "-t" test mode of the js REPL is unused and can simply be removed. Required functionality has been duplicated in test-js (isStrictMode function, loading of testing utilities). Also remove outdated information about tests from the js(1) man page.
This commit is contained in:
parent
651829c1e6
commit
8b76a1e548
2 changed files with 1 additions and 44 deletions
|
@ -25,7 +25,6 @@ Run `help()` in REPL mode to see its available built-in functions.
|
||||||
* `-l`, `--print-last-result`: Print the result of the last statement executed.
|
* `-l`, `--print-last-result`: Print the result of the last statement executed.
|
||||||
* `-g`, `--gc-on-every-allocation`: Run garbage collection on every allocation.
|
* `-g`, `--gc-on-every-allocation`: Run garbage collection on every allocation.
|
||||||
* `-s`, `--no-syntax-highlight`: Disable live syntax highlighting in the REPL
|
* `-s`, `--no-syntax-highlight`: Disable live syntax highlighting in the REPL
|
||||||
* `-t`, `--test-mode`: Run the interpreter with added functionality for the test harness
|
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
@ -47,26 +46,3 @@ undefined
|
||||||
77
|
77
|
||||||
undefined
|
undefined
|
||||||
```
|
```
|
||||||
|
|
||||||
## Test mode
|
|
||||||
|
|
||||||
In test mode, the `load()` function is added to the global object and can be used
|
|
||||||
to load further test utility functions defined in `LibJS/Tests/test-common.js`.
|
|
||||||
|
|
||||||
Typically a test will look like this:
|
|
||||||
|
|
||||||
```js
|
|
||||||
load("test-common.js");
|
|
||||||
|
|
||||||
try {
|
|
||||||
// test feature
|
|
||||||
console.log("PASS");
|
|
||||||
} catch (e) {
|
|
||||||
console.log("FAIL: " + e);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Available functions in `test-common.js`:
|
|
||||||
|
|
||||||
* `assert(expression)`: Throws an `AssertionError` if condition does not evaluate to a truthy value
|
|
||||||
* `assertNotReached()`: Throws an `AssertionError`, use to ensure certain code paths are never reached
|
|
||||||
|
|
|
@ -55,14 +55,12 @@ public:
|
||||||
virtual void initialize() override;
|
virtual void initialize() override;
|
||||||
virtual ~ReplObject() override;
|
virtual ~ReplObject() override;
|
||||||
|
|
||||||
JS_DECLARE_NATIVE_FUNCTION(load_file);
|
|
||||||
JS_DECLARE_NATIVE_FUNCTION(is_strict_mode);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "ReplObject"; }
|
virtual const char* class_name() const override { return "ReplObject"; }
|
||||||
|
|
||||||
JS_DECLARE_NATIVE_FUNCTION(exit_interpreter);
|
JS_DECLARE_NATIVE_FUNCTION(exit_interpreter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(repl_help);
|
JS_DECLARE_NATIVE_FUNCTION(repl_help);
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(load_file);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(save_to_file);
|
JS_DECLARE_NATIVE_FUNCTION(save_to_file);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -441,11 +439,6 @@ JS_DEFINE_NATIVE_FUNCTION(ReplObject::load_file)
|
||||||
return JS::Value(true);
|
return JS::Value(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(ReplObject::is_strict_mode)
|
|
||||||
{
|
|
||||||
return JS::Value(interpreter.in_strict_mode());
|
|
||||||
}
|
|
||||||
|
|
||||||
void repl(JS::Interpreter& interpreter)
|
void repl(JS::Interpreter& interpreter)
|
||||||
{
|
{
|
||||||
while (!s_fail_repl) {
|
while (!s_fail_repl) {
|
||||||
|
@ -457,12 +450,6 @@ void repl(JS::Interpreter& interpreter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void enable_test_mode(JS::Interpreter& interpreter)
|
|
||||||
{
|
|
||||||
interpreter.global_object().define_native_function("load", ReplObject::load_file);
|
|
||||||
interpreter.global_object().define_native_function("isStrictMode", ReplObject::is_strict_mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Function<void()> interrupt_interpreter;
|
static Function<void()> interrupt_interpreter;
|
||||||
void sigint_handler()
|
void sigint_handler()
|
||||||
{
|
{
|
||||||
|
@ -549,7 +536,6 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
bool gc_on_every_allocation = false;
|
bool gc_on_every_allocation = false;
|
||||||
bool disable_syntax_highlight = false;
|
bool disable_syntax_highlight = false;
|
||||||
bool test_mode = false;
|
|
||||||
const char* script_path = nullptr;
|
const char* script_path = nullptr;
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
|
@ -557,7 +543,6 @@ int main(int argc, char** argv)
|
||||||
args_parser.add_option(s_print_last_result, "Print last result", "print-last-result", 'l');
|
args_parser.add_option(s_print_last_result, "Print last result", "print-last-result", 'l');
|
||||||
args_parser.add_option(gc_on_every_allocation, "GC on every allocation", "gc-on-every-allocation", 'g');
|
args_parser.add_option(gc_on_every_allocation, "GC on every allocation", "gc-on-every-allocation", 'g');
|
||||||
args_parser.add_option(disable_syntax_highlight, "Disable live syntax highlighting", "no-syntax-highlight", 's');
|
args_parser.add_option(disable_syntax_highlight, "Disable live syntax highlighting", "no-syntax-highlight", 's');
|
||||||
args_parser.add_option(test_mode, "Run the interpreter with added functionality for the test harness", "test-mode", 't');
|
|
||||||
args_parser.add_positional_argument(script_path, "Path to script file", "script", Core::ArgsParser::Required::No);
|
args_parser.add_positional_argument(script_path, "Path to script file", "script", Core::ArgsParser::Required::No);
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(argc, argv);
|
||||||
|
|
||||||
|
@ -577,8 +562,6 @@ int main(int argc, char** argv)
|
||||||
interpreter->console().set_client(console_client);
|
interpreter->console().set_client(console_client);
|
||||||
interpreter->heap().set_should_collect_on_every_allocation(gc_on_every_allocation);
|
interpreter->heap().set_should_collect_on_every_allocation(gc_on_every_allocation);
|
||||||
interpreter->set_underscore_is_last_value(true);
|
interpreter->set_underscore_is_last_value(true);
|
||||||
if (test_mode)
|
|
||||||
enable_test_mode(*interpreter);
|
|
||||||
|
|
||||||
s_editor = Line::Editor::construct();
|
s_editor = Line::Editor::construct();
|
||||||
|
|
||||||
|
@ -861,8 +844,6 @@ int main(int argc, char** argv)
|
||||||
ReplConsoleClient console_client(interpreter->console());
|
ReplConsoleClient console_client(interpreter->console());
|
||||||
interpreter->console().set_client(console_client);
|
interpreter->console().set_client(console_client);
|
||||||
interpreter->heap().set_should_collect_on_every_allocation(gc_on_every_allocation);
|
interpreter->heap().set_should_collect_on_every_allocation(gc_on_every_allocation);
|
||||||
if (test_mode)
|
|
||||||
enable_test_mode(*interpreter);
|
|
||||||
|
|
||||||
signal(SIGINT, [](int) {
|
signal(SIGINT, [](int) {
|
||||||
sigint_handler();
|
sigint_handler();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue