test_main.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*************************************************************************/
  2. /* test_main.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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. #include "test_main.h"
  31. #include "core/list.h"
  32. #ifdef DEBUG_ENABLED
  33. #include "test_astar.h"
  34. #include "test_basis.h"
  35. #include "test_class_db.h"
  36. #include "test_gdscript.h"
  37. #include "test_gui.h"
  38. #include "test_math.h"
  39. #include "test_oa_hash_map.h"
  40. #include "test_ordered_hash_map.h"
  41. #include "test_physics_2d.h"
  42. #include "test_physics_3d.h"
  43. #include "test_render.h"
  44. #include "test_shader_lang.h"
  45. #include "test_string.h"
  46. #include "test_validate_testing.h"
  47. #include "thirdparty/doctest/doctest.h"
  48. const char **tests_get_names() {
  49. static const char *test_names[] = {
  50. "*",
  51. "all",
  52. "math",
  53. "basis",
  54. "physics_2d",
  55. "physics_3d",
  56. "render",
  57. "oa_hash_map",
  58. "class_db",
  59. "gui",
  60. "shaderlang",
  61. "gd_tokenizer",
  62. "gd_parser",
  63. "gd_compiler",
  64. "gd_bytecode",
  65. "ordered_hash_map",
  66. "astar",
  67. nullptr
  68. };
  69. return test_names;
  70. }
  71. int test_main(int argc, char *argv[]) {
  72. // doctest runner for when legacy unit tests are no found
  73. doctest::Context test_context;
  74. List<String> valid_arguments;
  75. // clean arguments of --test from the args
  76. int argument_count = 0;
  77. for (int x = 0; x < argc; x++) {
  78. if (strncmp(argv[x], "--test", 6) != 0) {
  79. valid_arguments.push_back(String(argv[x]));
  80. argument_count++;
  81. }
  82. }
  83. // convert godot command line arguments back to standard arguments.
  84. char **args = new char *[valid_arguments.size()];
  85. for (int x = 0; x < valid_arguments.size(); x++) {
  86. // operation to convert godot string to non wchar string
  87. const char *str = valid_arguments[x].utf8().ptr();
  88. // allocate the string copy
  89. args[x] = new char[strlen(str) + 1];
  90. // copy this into memory
  91. std::memcpy(args[x], str, strlen(str) + 1);
  92. }
  93. test_context.applyCommandLine(valid_arguments.size(), args);
  94. test_context.setOption("order-by", "name");
  95. test_context.setOption("abort-after", 5);
  96. test_context.setOption("no-breaks", true);
  97. delete[] args;
  98. return test_context.run();
  99. }
  100. #else
  101. const char **tests_get_names() {
  102. static const char *test_names[] = {
  103. nullptr
  104. };
  105. return test_names;
  106. }
  107. int test_main(int argc, char *argv[]) {
  108. return 0;
  109. }
  110. #endif