| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "../gdscript.h" |
| 34 |
|
| 35 |
#include "core/error/error_macros.h" |
| 36 |
#include "core/string/print_string.h" |
| 37 |
#include "core/string/ustring.h" |
| 38 |
#include "core/templates/vector.h" |
| 39 |
|
| 40 |
namespace GDScriptTests { |
| 41 |
|
| 42 |
void init_autoloads(); |
| 43 |
void init_language(const String &p_base_path); |
| 44 |
void finish_language(); |
| 45 |
|
| 46 |
|
| 47 |
class GDScriptTest { |
| 48 |
public: |
| 49 |
enum TestStatus { |
| 50 |
GDTEST_OK, |
| 51 |
GDTEST_LOAD_ERROR, |
| 52 |
GDTEST_PARSER_ERROR, |
| 53 |
GDTEST_ANALYZER_ERROR, |
| 54 |
GDTEST_COMPILER_ERROR, |
| 55 |
GDTEST_RUNTIME_ERROR, |
| 56 |
}; |
| 57 |
|
| 58 |
struct TestResult { |
| 59 |
TestStatus status; |
| 60 |
String output; |
| 61 |
bool passed; |
| 62 |
}; |
| 63 |
|
| 64 |
enum TokenizerMode { |
| 65 |
TOKENIZER_TEXT, |
| 66 |
TOKENIZER_BUFFER, |
| 67 |
}; |
| 68 |
|
| 69 |
private: |
| 70 |
struct ErrorHandlerData { |
| 71 |
TestResult *result = nullptr; |
| 72 |
GDScriptTest *self = nullptr; |
| 73 |
ErrorHandlerData(TestResult *p_result, GDScriptTest *p_this) { |
| 74 |
result = p_result; |
| 75 |
self = p_this; |
| 76 |
} |
| 77 |
}; |
| 78 |
|
| 79 |
String source_file; |
| 80 |
String output_file; |
| 81 |
String base_dir; |
| 82 |
|
| 83 |
PrintHandlerList _print_handler; |
| 84 |
ErrorHandlerList _error_handler; |
| 85 |
|
| 86 |
TokenizerMode tokenizer_mode = TOKENIZER_TEXT; |
| 87 |
|
| 88 |
void enable_stdout(); |
| 89 |
void disable_stdout(); |
| 90 |
bool check_output(const String &p_output) const; |
| 91 |
String get_text_for_status(TestStatus p_status) const; |
| 92 |
|
| 93 |
TestResult execute_test_code(bool p_is_generating); |
| 94 |
|
| 95 |
public: |
| 96 |
static void print_handler(void *p_this, const String &p_message, bool p_error, bool p_rich); |
| 97 |
static void error_handler(void *p_this, const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_explanation, bool p_editor_notify, ErrorHandlerType p_type); |
| 98 |
TestResult run_test(); |
| 99 |
bool generate_output(); |
| 100 |
|
| 101 |
const String &get_source_file() const { return source_file; } |
| 102 |
const String get_source_relative_filepath() const { return source_file.trim_prefix(base_dir); } |
| 103 |
const String &get_output_file() const { return output_file; } |
| 104 |
|
| 105 |
void set_tokenizer_mode(TokenizerMode p_tokenizer_mode) { tokenizer_mode = p_tokenizer_mode; } |
| 106 |
TokenizerMode get_tokenizer_mode() const { return tokenizer_mode; } |
| 107 |
|
| 108 |
GDScriptTest(const String &p_source_path, const String &p_output_path, const String &p_base_dir); |
| 109 |
GDScriptTest() : |
| 110 |
GDScriptTest(String(), String(), String()) {} |
| 111 |
}; |
| 112 |
|
| 113 |
class GDScriptTestRunner { |
| 114 |
String source_dir; |
| 115 |
Vector<GDScriptTest> tests; |
| 116 |
|
| 117 |
bool is_generating = false; |
| 118 |
bool do_init_languages = false; |
| 119 |
bool print_filenames; |
| 120 |
bool binary_tokens; |
| 121 |
|
| 122 |
bool make_tests(); |
| 123 |
bool make_tests_for_dir(const String &p_dir); |
| 124 |
bool generate_class_index(); |
| 125 |
|
| 126 |
public: |
| 127 |
static StringName test_function_name; |
| 128 |
|
| 129 |
static void handle_cmdline(); |
| 130 |
int run_tests(); |
| 131 |
bool generate_outputs(); |
| 132 |
|
| 133 |
GDScriptTestRunner(const String &p_source_dir, bool p_init_language, bool p_print_filenames = false, bool p_use_binary_tokens = false); |
| 134 |
~GDScriptTestRunner(); |
| 135 |
}; |
| 136 |
|
| 137 |
} |