gdscript_test_runner.cpp 19 KB

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