[python] test: check wether script execution lead to a Python error

This commit is contained in:
Émilie Feral
2020-04-01 13:51:13 +02:00
committed by LeaNumworks
parent 2f171eb2fd
commit 2738d30684
6 changed files with 37 additions and 25 deletions

View File

@@ -30,7 +30,7 @@ MicroPython::ExecutionEnvironment * MicroPython::ExecutionEnvironment::currentEx
return sCurrentExecutionEnvironment;
}
void MicroPython::ExecutionEnvironment::runCode(const char * str) {
bool MicroPython::ExecutionEnvironment::runCode(const char * str) {
assert(sCurrentExecutionEnvironment == nullptr);
sCurrentExecutionEnvironment = this;
@@ -38,6 +38,7 @@ void MicroPython::ExecutionEnvironment::runCode(const char * str) {
* for the exception handling (because of print). */
mp_hal_set_interrupt_char((int)Ion::Keyboard::Key::Back);
bool runSucceeded = true;
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
mp_lexer_t *lex = mp_lexer_new_from_str_len(0, str, strlen(str), false);
@@ -49,6 +50,7 @@ void MicroPython::ExecutionEnvironment::runCode(const char * str) {
mp_call_function_0(module_fun);
nlr_pop();
} else { // Uncaught exception
runSucceeded = false;
/* mp_obj_print_exception is supposed to handle error printing. However,
* because we want to print custom information, we copied and modified the
* content of mp_obj_print_exception instead of calling it. */
@@ -93,6 +95,7 @@ void MicroPython::ExecutionEnvironment::runCode(const char * str) {
assert(sCurrentExecutionEnvironment == this);
sCurrentExecutionEnvironment = nullptr;
return runSucceeded;
}
void MicroPython::ExecutionEnvironment::interrupt() {