From 11dc259566d109e8495e73bf694021576e315d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 1 Apr 2020 14:15:57 +0200 Subject: [PATCH] [python] test: add a function to run single command test --- python/test/execution_environment.cpp | 17 ++++++++++++----- python/test/execution_environment.h | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/python/test/execution_environment.cpp b/python/test/execution_environment.cpp index 4ba06d292..c14781119 100644 --- a/python/test/execution_environment.cpp +++ b/python/test/execution_environment.cpp @@ -36,13 +36,16 @@ void inlineToBeSingleInput(char * buffer, size_t bufferSize, const char * script *bufferChar = 0; } -bool execute_script(const char * script, const char * outputText = nullptr) { +bool execute_input(const char * input, bool singleCommandLine, const char * outputText = nullptr) { constexpr size_t bufferSize = 500; char buffer[bufferSize]; - inlineToBeSingleInput(buffer, bufferSize, script); + if (!singleCommandLine) { + inlineToBeSingleInput(buffer, bufferSize, input); + input = buffer; + } MicroPython::init(TestExecutionEnvironment::s_pythonHeap, TestExecutionEnvironment::s_pythonHeap + TestExecutionEnvironment::s_pythonHeapSize); TestExecutionEnvironment env; - bool executionResult = env.runCode(buffer); + bool executionResult = env.runCode(input); MicroPython::deinit(); if (outputText) { quiz_assert(strcmp(outputText, env.lastPrintedText()) == 0); @@ -51,9 +54,13 @@ bool execute_script(const char * script, const char * outputText = nullptr) { } void assert_script_execution_succeeds(const char * script, const char * outputText) { - quiz_assert(execute_script(script, outputText)); + quiz_assert(execute_input(script, false, outputText)); } void assert_script_execution_fails(const char * script) { - quiz_assert(!execute_script(script)); + quiz_assert(!execute_input(script, false)); +} + +void assert_command_execution_succeeds(const char * line, const char * outputText) { + quiz_assert(execute_input(line, true, outputText)); } diff --git a/python/test/execution_environment.h b/python/test/execution_environment.h index f77985cb4..6e52d5c4b 100644 --- a/python/test/execution_environment.h +++ b/python/test/execution_environment.h @@ -21,3 +21,4 @@ void inlineToBeSingleInput(char * buffer, size_t bufferSize, const char * script void assert_script_execution_succeeds(const char * script, const char * outputText = nullptr); void assert_script_execution_fails(const char * script); +void assert_command_execution_succeeds(const char * line, const char * outputText = nullptr);