gdscript_test_runner_suite.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*************************************************************************/
  2. /* gdscript_test_runner_suite.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifndef GDSCRIPT_TEST_RUNNER_SUITE_H
  31. #define GDSCRIPT_TEST_RUNNER_SUITE_H
  32. #include "gdscript_test_runner.h"
  33. #include "tests/test_macros.h"
  34. namespace GDScriptTests {
  35. TEST_SUITE("[Modules][GDScript]") {
  36. // GDScript 2.0 is still under heavy construction.
  37. // Allow the tests to fail, but do not ignore errors during development.
  38. // Update the scripts and expected output as needed.
  39. TEST_CASE("Script compilation and runtime") {
  40. GDScriptTestRunner runner("modules/gdscript/tests/scripts", true);
  41. int fail_count = runner.run_tests();
  42. INFO("Make sure `*.out` files have expected results.");
  43. REQUIRE_MESSAGE(fail_count == 0, "All GDScript tests should pass.");
  44. }
  45. }
  46. TEST_CASE("[Modules][GDScript] Load source code dynamically and run it") {
  47. Ref<GDScript> gdscript = memnew(GDScript);
  48. gdscript->set_source_code(R"(
  49. extends RefCounted
  50. func _init():
  51. set_meta("result", 42)
  52. )");
  53. // A spurious `Condition "err" is true` message is printed (despite parsing being successful and returning `OK`).
  54. // Silence it.
  55. ERR_PRINT_OFF;
  56. const Error error = gdscript->reload();
  57. ERR_PRINT_ON;
  58. CHECK_MESSAGE(error == OK, "The script should parse successfully.");
  59. // Run the script by assigning it to a reference-counted object.
  60. Ref<RefCounted> ref_counted = memnew(RefCounted);
  61. ref_counted->set_script(gdscript);
  62. CHECK_MESSAGE(int(ref_counted->get_meta("result")) == 42, "The script should assign object metadata successfully.");
  63. }
  64. } // namespace GDScriptTests
  65. #endif // GDSCRIPT_TEST_RUNNER_SUITE_H