gdscript_test_runner.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /**************************************************************************/
  2. /* gdscript_test_runner.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "gdscript_test_runner.h"
  31. #include "../gdscript.h"
  32. #include "../gdscript_analyzer.h"
  33. #include "../gdscript_compiler.h"
  34. #include "../gdscript_parser.h"
  35. #include "core/config/project_settings.h"
  36. #include "core/core_globals.h"
  37. #include "core/core_string_names.h"
  38. #include "core/io/dir_access.h"
  39. #include "core/io/file_access_pack.h"
  40. #include "core/os/os.h"
  41. #include "core/string/string_builder.h"
  42. #include "scene/resources/packed_scene.h"
  43. #include "tests/test_macros.h"
  44. namespace GDScriptTests {
  45. void init_autoloads() {
  46. HashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
  47. // First pass, add the constants so they exist before any script is loaded.
  48. for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : ProjectSettings::get_singleton()->get_autoload_list()) {
  49. const ProjectSettings::AutoloadInfo &info = E.value;
  50. if (info.is_singleton) {
  51. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  52. ScriptServer::get_language(i)->add_global_constant(info.name, Variant());
  53. }
  54. }
  55. }
  56. // Second pass, load into global constants.
  57. for (const KeyValue<StringName, ProjectSettings::AutoloadInfo> &E : ProjectSettings::get_singleton()->get_autoload_list()) {
  58. const ProjectSettings::AutoloadInfo &info = E.value;
  59. if (!info.is_singleton) {
  60. // Skip non-singletons since we don't have a scene tree here anyway.
  61. continue;
  62. }
  63. Node *n = nullptr;
  64. if (ResourceLoader::get_resource_type(info.path) == "PackedScene") {
  65. // Cache the scene reference before loading it (for cyclic references)
  66. Ref<PackedScene> scn;
  67. scn.instantiate();
  68. scn->set_path(info.path);
  69. scn->reload_from_file();
  70. ERR_CONTINUE_MSG(!scn.is_valid(), vformat("Can't autoload: %s.", info.path));
  71. if (scn.is_valid()) {
  72. n = scn->instantiate();
  73. }
  74. } else {
  75. Ref<Resource> res = ResourceLoader::load(info.path);
  76. ERR_CONTINUE_MSG(res.is_null(), vformat("Can't autoload: %s.", info.path));
  77. Ref<Script> scr = res;
  78. if (scr.is_valid()) {
  79. StringName ibt = scr->get_instance_base_type();
  80. bool valid_type = ClassDB::is_parent_class(ibt, "Node");
  81. ERR_CONTINUE_MSG(!valid_type, vformat("Script does not inherit from Node: %s.", info.path));
  82. Object *obj = ClassDB::instantiate(ibt);
  83. ERR_CONTINUE_MSG(!obj, vformat("Cannot instance script for Autoload, expected 'Node' inheritance, got: %s.", ibt));
  84. n = Object::cast_to<Node>(obj);
  85. n->set_script(scr);
  86. }
  87. }
  88. ERR_CONTINUE_MSG(!n, vformat("Path in autoload not a node or script: %s.", info.path));
  89. n->set_name(info.name);
  90. for (int i = 0; i < ScriptServer::get_language_count(); i++) {
  91. ScriptServer::get_language(i)->add_global_constant(info.name, n);
  92. }
  93. }
  94. }
  95. void init_language(const String &p_base_path) {
  96. // Setup project settings since it's needed by the languages to get the global scripts.
  97. // This also sets up the base resource path.
  98. Error err = ProjectSettings::get_singleton()->setup(p_base_path, String(), true);
  99. if (err) {
  100. print_line("Could not load project settings.");
  101. // Keep going since some scripts still work without this.
  102. }
  103. // Initialize the language for the test routine.
  104. GDScriptLanguage::get_singleton()->init();
  105. init_autoloads();
  106. }
  107. void finish_language() {
  108. GDScriptLanguage::get_singleton()->finish();
  109. ScriptServer::global_classes_clear();
  110. }
  111. StringName GDScriptTestRunner::test_function_name;
  112. GDScriptTestRunner::GDScriptTestRunner(const String &p_source_dir, bool p_init_language, bool p_print_filenames) {
  113. test_function_name = StaticCString::create("test");
  114. do_init_languages = p_init_language;
  115. print_filenames = p_print_filenames;
  116. source_dir = p_source_dir;
  117. if (!source_dir.ends_with("/")) {
  118. source_dir += "/";
  119. }
  120. if (do_init_languages) {
  121. init_language(p_source_dir);
  122. }
  123. #ifdef DEBUG_ENABLED
  124. // Set all warning levels to "Warn" in order to test them properly, even the ones that default to error.
  125. ProjectSettings::get_singleton()->set_setting("debug/gdscript/warnings/enable", true);
  126. for (int i = 0; i < (int)GDScriptWarning::WARNING_MAX; i++) {
  127. String warning_setting = GDScriptWarning::get_settings_path_from_code((GDScriptWarning::Code)i);
  128. ProjectSettings::get_singleton()->set_setting(warning_setting, (int)GDScriptWarning::WARN);
  129. }
  130. #endif
  131. // Enable printing to show results
  132. CoreGlobals::print_line_enabled = true;
  133. CoreGlobals::print_error_enabled = true;
  134. }
  135. GDScriptTestRunner::~GDScriptTestRunner() {
  136. test_function_name = StringName();
  137. if (do_init_languages) {
  138. finish_language();
  139. }
  140. }
  141. #ifndef DEBUG_ENABLED
  142. static String strip_warnings(const String &p_expected) {
  143. // On release builds we don't have warnings. Here we remove them from the output before comparison
  144. // so it doesn't fail just because of difference in warnings.
  145. String expected_no_warnings;
  146. for (String line : p_expected.split("\n")) {
  147. if (line.begins_with(">> ")) {
  148. continue;
  149. }
  150. expected_no_warnings += line + "\n";
  151. }
  152. return expected_no_warnings.strip_edges() + "\n";
  153. }
  154. #endif
  155. int GDScriptTestRunner::run_tests() {
  156. if (!make_tests()) {
  157. FAIL("An error occurred while making the tests.");
  158. return -1;
  159. }
  160. if (!generate_class_index()) {
  161. FAIL("An error occurred while generating class index.");
  162. return -1;
  163. }
  164. int failed = 0;
  165. for (int i = 0; i < tests.size(); i++) {
  166. GDScriptTest test = tests[i];
  167. if (print_filenames) {
  168. print_line(test.get_source_relative_filepath());
  169. }
  170. GDScriptTest::TestResult result = test.run_test();
  171. String expected = FileAccess::get_file_as_string(test.get_output_file());
  172. #ifndef DEBUG_ENABLED
  173. expected = strip_warnings(expected);
  174. #endif
  175. INFO(test.get_source_file());
  176. if (!result.passed) {
  177. INFO(expected);
  178. failed++;
  179. }
  180. CHECK_MESSAGE(result.passed, (result.passed ? String() : result.output));
  181. }
  182. return failed;
  183. }
  184. bool GDScriptTestRunner::generate_outputs() {
  185. is_generating = true;
  186. if (!make_tests()) {
  187. print_line("Failed to generate a test output.");
  188. return false;
  189. }
  190. if (!generate_class_index()) {
  191. return false;
  192. }
  193. for (int i = 0; i < tests.size(); i++) {
  194. GDScriptTest test = tests[i];
  195. if (print_filenames) {
  196. print_line(test.get_source_relative_filepath());
  197. } else {
  198. OS::get_singleton()->print(".");
  199. }
  200. bool result = test.generate_output();
  201. if (!result) {
  202. print_line("\nCould not generate output for " + test.get_source_file());
  203. return false;
  204. }
  205. }
  206. print_line("\nGenerated output files for " + itos(tests.size()) + " tests successfully.");
  207. return true;
  208. }
  209. bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) {
  210. Error err = OK;
  211. Ref<DirAccess> dir(DirAccess::open(p_dir, &err));
  212. if (err != OK) {
  213. return false;
  214. }
  215. String current_dir = dir->get_current_dir();
  216. dir->list_dir_begin();
  217. String next = dir->get_next();
  218. while (!next.is_empty()) {
  219. if (dir->current_is_dir()) {
  220. if (next == "." || next == "..") {
  221. next = dir->get_next();
  222. continue;
  223. }
  224. if (!make_tests_for_dir(current_dir.path_join(next))) {
  225. return false;
  226. }
  227. } else {
  228. if (next.ends_with(".notest.gd")) {
  229. next = dir->get_next();
  230. continue;
  231. } else if (next.get_extension().to_lower() == "gd") {
  232. #ifndef DEBUG_ENABLED
  233. // On release builds, skip tests marked as debug only.
  234. Error open_err = OK;
  235. Ref<FileAccess> script_file(FileAccess::open(current_dir.path_join(next), FileAccess::READ, &open_err));
  236. if (open_err != OK) {
  237. ERR_PRINT(vformat(R"(Couldn't open test file "%s".)", next));
  238. next = dir->get_next();
  239. continue;
  240. } else {
  241. if (script_file->get_line() == "#debug-only") {
  242. next = dir->get_next();
  243. continue;
  244. }
  245. }
  246. #endif
  247. String out_file = next.get_basename() + ".out";
  248. if (!is_generating && !dir->file_exists(out_file)) {
  249. ERR_FAIL_V_MSG(false, "Could not find output file for " + next);
  250. }
  251. GDScriptTest test(current_dir.path_join(next), current_dir.path_join(out_file), source_dir);
  252. tests.push_back(test);
  253. }
  254. }
  255. next = dir->get_next();
  256. }
  257. dir->list_dir_end();
  258. return true;
  259. }
  260. bool GDScriptTestRunner::make_tests() {
  261. Error err = OK;
  262. Ref<DirAccess> dir(DirAccess::open(source_dir, &err));
  263. ERR_FAIL_COND_V_MSG(err != OK, false, "Could not open specified test directory.");
  264. source_dir = dir->get_current_dir() + "/"; // Make it absolute path.
  265. return make_tests_for_dir(dir->get_current_dir());
  266. }
  267. bool GDScriptTestRunner::generate_class_index() {
  268. StringName gdscript_name = GDScriptLanguage::get_singleton()->get_name();
  269. for (int i = 0; i < tests.size(); i++) {
  270. GDScriptTest test = tests[i];
  271. String base_type;
  272. String class_name = GDScriptLanguage::get_singleton()->get_global_class_name(test.get_source_file(), &base_type);
  273. if (class_name.is_empty()) {
  274. continue;
  275. }
  276. ERR_FAIL_COND_V_MSG(ScriptServer::is_global_class(class_name), false,
  277. "Class name '" + class_name + "' from " + test.get_source_file() + " is already used in " + ScriptServer::get_global_class_path(class_name));
  278. ScriptServer::add_global_class(class_name, base_type, gdscript_name, test.get_source_file());
  279. }
  280. return true;
  281. }
  282. GDScriptTest::GDScriptTest(const String &p_source_path, const String &p_output_path, const String &p_base_dir) {
  283. source_file = p_source_path;
  284. output_file = p_output_path;
  285. base_dir = p_base_dir;
  286. _print_handler.printfunc = print_handler;
  287. _error_handler.errfunc = error_handler;
  288. }
  289. void GDScriptTestRunner::handle_cmdline() {
  290. List<String> cmdline_args = OS::get_singleton()->get_cmdline_args();
  291. for (List<String>::Element *E = cmdline_args.front(); E; E = E->next()) {
  292. String &cmd = E->get();
  293. if (cmd == "--gdscript-generate-tests") {
  294. String path;
  295. if (E->next()) {
  296. path = E->next()->get();
  297. } else {
  298. path = "modules/gdscript/tests/scripts";
  299. }
  300. GDScriptTestRunner runner(path, false, cmdline_args.find("--print-filenames") != nullptr);
  301. bool completed = runner.generate_outputs();
  302. int failed = completed ? 0 : -1;
  303. exit(failed);
  304. }
  305. }
  306. }
  307. void GDScriptTest::enable_stdout() {
  308. // TODO: this could likely be handled by doctest or `tests/test_macros.h`.
  309. OS::get_singleton()->set_stdout_enabled(true);
  310. OS::get_singleton()->set_stderr_enabled(true);
  311. }
  312. void GDScriptTest::disable_stdout() {
  313. // TODO: this could likely be handled by doctest or `tests/test_macros.h`.
  314. OS::get_singleton()->set_stdout_enabled(false);
  315. OS::get_singleton()->set_stderr_enabled(false);
  316. }
  317. void GDScriptTest::print_handler(void *p_this, const String &p_message, bool p_error, bool p_rich) {
  318. TestResult *result = (TestResult *)p_this;
  319. result->output += p_message + "\n";
  320. }
  321. void GDScriptTest::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) {
  322. ErrorHandlerData *data = (ErrorHandlerData *)p_this;
  323. GDScriptTest *self = data->self;
  324. TestResult *result = data->result;
  325. result->status = GDTEST_RUNTIME_ERROR;
  326. StringBuilder builder;
  327. builder.append(">> ");
  328. switch (p_type) {
  329. case ERR_HANDLER_ERROR:
  330. builder.append("ERROR");
  331. break;
  332. case ERR_HANDLER_WARNING:
  333. builder.append("WARNING");
  334. break;
  335. case ERR_HANDLER_SCRIPT:
  336. builder.append("SCRIPT ERROR");
  337. break;
  338. case ERR_HANDLER_SHADER:
  339. builder.append("SHADER ERROR");
  340. break;
  341. default:
  342. builder.append("Unknown error type");
  343. break;
  344. }
  345. builder.append("\n>> on function: ");
  346. builder.append(String::utf8(p_function));
  347. builder.append("()\n>> ");
  348. builder.append(String::utf8(p_file).trim_prefix(self->base_dir));
  349. builder.append("\n>> ");
  350. builder.append(itos(p_line));
  351. builder.append("\n>> ");
  352. builder.append(String::utf8(p_error));
  353. if (strlen(p_explanation) > 0) {
  354. builder.append("\n>> ");
  355. builder.append(String::utf8(p_explanation));
  356. }
  357. builder.append("\n");
  358. result->output = builder.as_string();
  359. }
  360. bool GDScriptTest::check_output(const String &p_output) const {
  361. Error err = OK;
  362. String expected = FileAccess::get_file_as_string(output_file, &err);
  363. ERR_FAIL_COND_V_MSG(err != OK, false, "Error when opening the output file.");
  364. String got = p_output.strip_edges(); // TODO: may be hacky.
  365. got += "\n"; // Make sure to insert newline for CI static checks.
  366. #ifndef DEBUG_ENABLED
  367. expected = strip_warnings(expected);
  368. #endif
  369. return got == expected;
  370. }
  371. String GDScriptTest::get_text_for_status(GDScriptTest::TestStatus p_status) const {
  372. switch (p_status) {
  373. case GDTEST_OK:
  374. return "GDTEST_OK";
  375. case GDTEST_LOAD_ERROR:
  376. return "GDTEST_LOAD_ERROR";
  377. case GDTEST_PARSER_ERROR:
  378. return "GDTEST_PARSER_ERROR";
  379. case GDTEST_ANALYZER_ERROR:
  380. return "GDTEST_ANALYZER_ERROR";
  381. case GDTEST_COMPILER_ERROR:
  382. return "GDTEST_COMPILER_ERROR";
  383. case GDTEST_RUNTIME_ERROR:
  384. return "GDTEST_RUNTIME_ERROR";
  385. }
  386. return "";
  387. }
  388. GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) {
  389. disable_stdout();
  390. TestResult result;
  391. result.status = GDTEST_OK;
  392. result.output = String();
  393. result.passed = false;
  394. Error err = OK;
  395. // Create script.
  396. Ref<GDScript> script;
  397. script.instantiate();
  398. script->set_path(source_file);
  399. err = script->load_source_code(source_file);
  400. if (err != OK) {
  401. enable_stdout();
  402. result.status = GDTEST_LOAD_ERROR;
  403. result.passed = false;
  404. ERR_FAIL_V_MSG(result, "\nCould not load source code for: '" + source_file + "'");
  405. }
  406. // Test parsing.
  407. GDScriptParser parser;
  408. err = parser.parse(script->get_source_code(), source_file, false);
  409. if (err != OK) {
  410. enable_stdout();
  411. result.status = GDTEST_PARSER_ERROR;
  412. result.output = get_text_for_status(result.status) + "\n";
  413. const List<GDScriptParser::ParserError> &errors = parser.get_errors();
  414. if (!errors.is_empty()) {
  415. // Only the first error since the following might be cascading.
  416. result.output += errors[0].message + "\n"; // TODO: line, column?
  417. }
  418. if (!p_is_generating) {
  419. result.passed = check_output(result.output);
  420. }
  421. return result;
  422. }
  423. // Test type-checking.
  424. GDScriptAnalyzer analyzer(&parser);
  425. err = analyzer.analyze();
  426. if (err != OK) {
  427. enable_stdout();
  428. result.status = GDTEST_ANALYZER_ERROR;
  429. result.output = get_text_for_status(result.status) + "\n";
  430. const List<GDScriptParser::ParserError> &errors = parser.get_errors();
  431. if (!errors.is_empty()) {
  432. // Only the first error since the following might be cascading.
  433. result.output += errors[0].message + "\n"; // TODO: line, column?
  434. }
  435. if (!p_is_generating) {
  436. result.passed = check_output(result.output);
  437. }
  438. return result;
  439. }
  440. #ifdef DEBUG_ENABLED
  441. StringBuilder warning_string;
  442. for (const GDScriptWarning &E : parser.get_warnings()) {
  443. const GDScriptWarning warning = E;
  444. warning_string.append(">> WARNING");
  445. warning_string.append("\n>> Line: ");
  446. warning_string.append(itos(warning.start_line));
  447. warning_string.append("\n>> ");
  448. warning_string.append(warning.get_name());
  449. warning_string.append("\n>> ");
  450. warning_string.append(warning.get_message());
  451. warning_string.append("\n");
  452. }
  453. result.output += warning_string.as_string();
  454. #endif
  455. // Test compiling.
  456. GDScriptCompiler compiler;
  457. err = compiler.compile(&parser, script.ptr(), false);
  458. if (err != OK) {
  459. enable_stdout();
  460. result.status = GDTEST_COMPILER_ERROR;
  461. result.output = get_text_for_status(result.status) + "\n";
  462. result.output = compiler.get_error();
  463. if (!p_is_generating) {
  464. result.passed = check_output(result.output);
  465. }
  466. return result;
  467. }
  468. // Script files matching this pattern are allowed to not contain a test() function.
  469. if (source_file.match("*.notest.gd")) {
  470. enable_stdout();
  471. result.passed = check_output(result.output);
  472. return result;
  473. }
  474. // Test running.
  475. const HashMap<StringName, GDScriptFunction *>::ConstIterator test_function_element = script->get_member_functions().find(GDScriptTestRunner::test_function_name);
  476. if (!test_function_element) {
  477. enable_stdout();
  478. result.status = GDTEST_LOAD_ERROR;
  479. result.output = "";
  480. result.passed = false;
  481. ERR_FAIL_V_MSG(result, "\nCould not find test function on: '" + source_file + "'");
  482. }
  483. script->reload();
  484. // Create object instance for test.
  485. Object *obj = ClassDB::instantiate(script->get_native()->get_name());
  486. Ref<RefCounted> obj_ref;
  487. if (obj->is_ref_counted()) {
  488. obj_ref = Ref<RefCounted>(Object::cast_to<RefCounted>(obj));
  489. }
  490. obj->set_script(script);
  491. GDScriptInstance *instance = static_cast<GDScriptInstance *>(obj->get_script_instance());
  492. // Setup output handlers.
  493. ErrorHandlerData error_data(&result, this);
  494. _print_handler.userdata = &result;
  495. _error_handler.userdata = &error_data;
  496. add_print_handler(&_print_handler);
  497. add_error_handler(&_error_handler);
  498. // Call test function.
  499. Callable::CallError call_err;
  500. instance->callp(GDScriptTestRunner::test_function_name, nullptr, 0, call_err);
  501. // Tear down output handlers.
  502. remove_print_handler(&_print_handler);
  503. remove_error_handler(&_error_handler);
  504. // Check results.
  505. if (call_err.error != Callable::CallError::CALL_OK) {
  506. enable_stdout();
  507. result.status = GDTEST_LOAD_ERROR;
  508. result.passed = false;
  509. ERR_FAIL_V_MSG(result, "\nCould not call test function on: '" + source_file + "'");
  510. }
  511. result.output = get_text_for_status(result.status) + "\n" + result.output;
  512. if (!p_is_generating) {
  513. result.passed = check_output(result.output);
  514. }
  515. if (obj_ref.is_null()) {
  516. memdelete(obj);
  517. }
  518. enable_stdout();
  519. GDScriptCache::remove_script(script->get_path());
  520. return result;
  521. }
  522. GDScriptTest::TestResult GDScriptTest::run_test() {
  523. return execute_test_code(false);
  524. }
  525. bool GDScriptTest::generate_output() {
  526. TestResult result = execute_test_code(true);
  527. if (result.status == GDTEST_LOAD_ERROR) {
  528. return false;
  529. }
  530. Error err = OK;
  531. Ref<FileAccess> out_file = FileAccess::open(output_file, FileAccess::WRITE, &err);
  532. if (err != OK) {
  533. return false;
  534. }
  535. String output = result.output.strip_edges(); // TODO: may be hacky.
  536. output += "\n"; // Make sure to insert newline for CI static checks.
  537. out_file->store_string(output);
  538. return true;
  539. }
  540. } // namespace GDScriptTests