test-js.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /*
  2. * Copyright (c) 2020, Matthew Olsson <matthewcolsson@gmail.com>
  3. * Copyright (c) 2020, Linus Groh <mail@linusgroh.de>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  20. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include <AK/JsonObject.h>
  28. #include <AK/JsonValue.h>
  29. #include <AK/LogStream.h>
  30. #include <AK/QuickSort.h>
  31. #include <LibCore/ArgsParser.h>
  32. #include <LibCore/DirIterator.h>
  33. #include <LibCore/File.h>
  34. #include <LibJS/Interpreter.h>
  35. #include <LibJS/Lexer.h>
  36. #include <LibJS/Parser.h>
  37. #include <LibJS/Runtime/Array.h>
  38. #include <LibJS/Runtime/GlobalObject.h>
  39. #include <LibJS/Runtime/JSONObject.h>
  40. #include <signal.h>
  41. #include <stdlib.h>
  42. #include <sys/time.h>
  43. #define TOP_LEVEL_TEST_NAME "__$$TOP_LEVEL$$__"
  44. RefPtr<JS::VM> vm;
  45. static bool collect_on_every_allocation = false;
  46. static String currently_running_test;
  47. enum class TestResult {
  48. Pass,
  49. Fail,
  50. Skip,
  51. };
  52. struct JSTest {
  53. String name;
  54. TestResult result;
  55. String details;
  56. };
  57. struct JSSuite {
  58. String name;
  59. // A failed test takes precedence over a skipped test, which both have
  60. // precedence over a passed test
  61. TestResult most_severe_test_result { TestResult::Pass };
  62. Vector<JSTest> tests {};
  63. };
  64. struct ParserError {
  65. JS::Parser::Error error;
  66. String hint;
  67. };
  68. struct JSFileResult {
  69. String name;
  70. Optional<ParserError> error {};
  71. double time_taken { 0 };
  72. // A failed test takes precedence over a skipped test, which both have
  73. // precedence over a passed test
  74. TestResult most_severe_test_result { TestResult::Pass };
  75. Vector<JSSuite> suites {};
  76. Vector<String> logged_messages {};
  77. };
  78. struct JSTestRunnerCounts {
  79. int tests_failed { 0 };
  80. int tests_passed { 0 };
  81. int tests_skipped { 0 };
  82. int suites_failed { 0 };
  83. int suites_passed { 0 };
  84. int files_total { 0 };
  85. };
  86. class TestRunnerGlobalObject : public JS::GlobalObject {
  87. public:
  88. TestRunnerGlobalObject();
  89. virtual ~TestRunnerGlobalObject() override;
  90. virtual void initialize() override;
  91. private:
  92. virtual const char* class_name() const override { return "TestRunnerGlobalObject"; }
  93. JS_DECLARE_NATIVE_FUNCTION(is_strict_mode);
  94. };
  95. class TestRunner {
  96. public:
  97. static TestRunner* the()
  98. {
  99. return s_the;
  100. }
  101. TestRunner(String test_root, bool print_times)
  102. : m_test_root(move(test_root))
  103. , m_print_times(print_times)
  104. {
  105. ASSERT(!s_the);
  106. s_the = this;
  107. }
  108. void run();
  109. const JSTestRunnerCounts& counts() const { return m_counts; }
  110. private:
  111. static TestRunner* s_the;
  112. JSFileResult run_file_test(const String& test_path);
  113. void print_file_result(const JSFileResult& file_result) const;
  114. void print_test_results() const;
  115. String m_test_root;
  116. bool m_print_times;
  117. double m_total_elapsed_time_in_ms { 0 };
  118. JSTestRunnerCounts m_counts;
  119. RefPtr<JS::Program> m_test_program;
  120. };
  121. TestRunner* TestRunner::s_the = nullptr;
  122. TestRunnerGlobalObject::TestRunnerGlobalObject()
  123. {
  124. }
  125. TestRunnerGlobalObject::~TestRunnerGlobalObject()
  126. {
  127. }
  128. void TestRunnerGlobalObject::initialize()
  129. {
  130. JS::GlobalObject::initialize();
  131. static FlyString global_property_name { "global" };
  132. static FlyString is_strict_mode_property_name { "isStrictMode" };
  133. define_property(global_property_name, this, JS::Attribute::Enumerable);
  134. define_native_function(is_strict_mode_property_name, is_strict_mode);
  135. }
  136. JS_DEFINE_NATIVE_FUNCTION(TestRunnerGlobalObject::is_strict_mode)
  137. {
  138. return JS::Value(vm.in_strict_mode());
  139. }
  140. static void cleanup_and_exit()
  141. {
  142. // Clear the taskbar progress.
  143. #ifdef __serenity__
  144. fprintf(stderr, "\033]9;-1;\033\\");
  145. #endif
  146. exit(1);
  147. }
  148. static void handle_sigabrt(int)
  149. {
  150. dbg() << "test-js: SIGABRT received, cleaning up.";
  151. cleanup_and_exit();
  152. }
  153. static double get_time_in_ms()
  154. {
  155. struct timeval tv1;
  156. auto return_code = gettimeofday(&tv1, nullptr);
  157. ASSERT(return_code >= 0);
  158. return static_cast<double>(tv1.tv_sec) * 1000.0 + static_cast<double>(tv1.tv_usec) / 1000.0;
  159. }
  160. template<typename Callback>
  161. static void iterate_directory_recursively(const String& directory_path, Callback callback)
  162. {
  163. Core::DirIterator directory_iterator(directory_path, Core::DirIterator::Flags::SkipDots);
  164. while (directory_iterator.has_next()) {
  165. auto file_path = String::format("%s/%s", directory_path.characters(), directory_iterator.next_path().characters());
  166. if (Core::File::is_directory(file_path)) {
  167. iterate_directory_recursively(file_path, callback);
  168. } else {
  169. callback(move(file_path));
  170. }
  171. }
  172. }
  173. static Vector<String> get_test_paths(const String& test_root)
  174. {
  175. Vector<String> paths;
  176. iterate_directory_recursively(test_root, [&](const String& file_path) {
  177. if (!file_path.ends_with("test-common.js"))
  178. paths.append(file_path);
  179. });
  180. quick_sort(paths);
  181. return paths;
  182. }
  183. void TestRunner::run()
  184. {
  185. size_t progress_counter = 0;
  186. auto test_paths = get_test_paths(m_test_root);
  187. for (auto& path : test_paths) {
  188. ++progress_counter;
  189. print_file_result(run_file_test(path));
  190. #ifdef __serenity__
  191. fprintf(stderr, "\033]9;%zu;%zu;\033\\", progress_counter, test_paths.size());
  192. #endif
  193. }
  194. #ifdef __serenity__
  195. fprintf(stderr, "\033]9;-1;\033\\");
  196. #endif
  197. print_test_results();
  198. }
  199. static Result<NonnullRefPtr<JS::Program>, ParserError> parse_file(const String& file_path)
  200. {
  201. auto file = Core::File::construct(file_path);
  202. auto result = file->open(Core::IODevice::ReadOnly);
  203. if (!result) {
  204. printf("Failed to open the following file: \"%s\"\n", file_path.characters());
  205. cleanup_and_exit();
  206. }
  207. auto contents = file->read_all();
  208. String test_file_string(reinterpret_cast<const char*>(contents.data()), contents.size());
  209. file->close();
  210. auto parser = JS::Parser(JS::Lexer(test_file_string));
  211. auto program = parser.parse_program();
  212. if (parser.has_errors()) {
  213. auto error = parser.errors()[0];
  214. return Result<NonnullRefPtr<JS::Program>, ParserError>(ParserError { error, error.source_location_hint(test_file_string) });
  215. }
  216. return Result<NonnullRefPtr<JS::Program>, ParserError>(program);
  217. }
  218. static Optional<JsonValue> get_test_results(JS::Interpreter& interpreter)
  219. {
  220. auto result = vm->get_variable("__TestResults__", interpreter.global_object());
  221. auto json_string = JS::JSONObject::stringify_impl(interpreter.global_object(), result, JS::js_undefined(), JS::js_undefined());
  222. auto json = JsonValue::from_string(json_string);
  223. if (!json.has_value())
  224. return {};
  225. return json.value();
  226. }
  227. JSFileResult TestRunner::run_file_test(const String& test_path)
  228. {
  229. currently_running_test = test_path;
  230. double start_time = get_time_in_ms();
  231. auto interpreter = JS::Interpreter::create<TestRunnerGlobalObject>(*vm);
  232. // FIXME: This is a hack while we're refactoring Interpreter/VM stuff.
  233. JS::VM::InterpreterExecutionScope scope(*interpreter);
  234. interpreter->heap().set_should_collect_on_every_allocation(collect_on_every_allocation);
  235. if (!m_test_program) {
  236. auto result = parse_file(String::format("%s/test-common.js", m_test_root.characters()));
  237. if (result.is_error()) {
  238. printf("Unable to parse test-common.js\n");
  239. printf("%s\n", result.error().error.to_string().characters());
  240. printf("%s\n", result.error().hint.characters());
  241. cleanup_and_exit();
  242. ;
  243. }
  244. m_test_program = result.value();
  245. }
  246. interpreter->run(interpreter->global_object(), *m_test_program);
  247. auto file_program = parse_file(test_path);
  248. if (file_program.is_error())
  249. return { test_path, file_program.error() };
  250. interpreter->run(interpreter->global_object(), *file_program.value());
  251. auto test_json = get_test_results(*interpreter);
  252. if (!test_json.has_value()) {
  253. printf("Received malformed JSON from test \"%s\"\n", test_path.characters());
  254. cleanup_and_exit();
  255. }
  256. JSFileResult file_result { test_path.substring(m_test_root.length() + 1, test_path.length() - m_test_root.length() - 1) };
  257. // Collect logged messages
  258. auto& arr = interpreter->vm().get_variable("__UserOutput__", interpreter->global_object()).as_array();
  259. for (auto& entry : arr.indexed_properties()) {
  260. auto message = entry.value_and_attributes(&interpreter->global_object()).value;
  261. file_result.logged_messages.append(message.to_string_without_side_effects());
  262. }
  263. test_json.value().as_object().for_each_member([&](const String& suite_name, const JsonValue& suite_value) {
  264. JSSuite suite { suite_name };
  265. ASSERT(suite_value.is_object());
  266. suite_value.as_object().for_each_member([&](const String& test_name, const JsonValue& test_value) {
  267. JSTest test { test_name, TestResult::Fail, "" };
  268. ASSERT(test_value.is_object());
  269. ASSERT(test_value.as_object().has("result"));
  270. auto result = test_value.as_object().get("result");
  271. ASSERT(result.is_string());
  272. auto result_string = result.as_string();
  273. if (result_string == "pass") {
  274. test.result = TestResult::Pass;
  275. m_counts.tests_passed++;
  276. } else if (result_string == "fail") {
  277. test.result = TestResult::Fail;
  278. m_counts.tests_failed++;
  279. suite.most_severe_test_result = TestResult::Fail;
  280. ASSERT(test_value.as_object().has("details"));
  281. auto details = test_value.as_object().get("details");
  282. ASSERT(result.is_string());
  283. test.details = details.as_string();
  284. } else {
  285. test.result = TestResult::Skip;
  286. if (suite.most_severe_test_result == TestResult::Pass)
  287. suite.most_severe_test_result = TestResult::Skip;
  288. m_counts.tests_skipped++;
  289. }
  290. suite.tests.append(test);
  291. });
  292. if (suite.most_severe_test_result == TestResult::Fail) {
  293. m_counts.suites_failed++;
  294. file_result.most_severe_test_result = TestResult::Fail;
  295. } else {
  296. if (suite.most_severe_test_result == TestResult::Skip && file_result.most_severe_test_result == TestResult::Pass)
  297. file_result.most_severe_test_result = TestResult::Skip;
  298. m_counts.suites_passed++;
  299. }
  300. file_result.suites.append(suite);
  301. });
  302. m_counts.files_total++;
  303. file_result.time_taken = get_time_in_ms() - start_time;
  304. m_total_elapsed_time_in_ms += file_result.time_taken;
  305. return file_result;
  306. }
  307. enum Modifier {
  308. BG_RED,
  309. BG_GREEN,
  310. FG_RED,
  311. FG_GREEN,
  312. FG_ORANGE,
  313. FG_GRAY,
  314. FG_BLACK,
  315. FG_BOLD,
  316. ITALIC,
  317. CLEAR,
  318. };
  319. static void print_modifiers(Vector<Modifier> modifiers)
  320. {
  321. for (auto& modifier : modifiers) {
  322. auto code = [&]() -> String {
  323. switch (modifier) {
  324. case BG_RED:
  325. return "\033[48;2;255;0;102m";
  326. case BG_GREEN:
  327. return "\033[48;2;102;255;0m";
  328. case FG_RED:
  329. return "\033[38;2;255;0;102m";
  330. case FG_GREEN:
  331. return "\033[38;2;102;255;0m";
  332. case FG_ORANGE:
  333. return "\033[38;2;255;102;0m";
  334. case FG_GRAY:
  335. return "\033[38;2;135;139;148m";
  336. case FG_BLACK:
  337. return "\033[30m";
  338. case FG_BOLD:
  339. return "\033[1m";
  340. case ITALIC:
  341. return "\033[3m";
  342. case CLEAR:
  343. return "\033[0m";
  344. }
  345. ASSERT_NOT_REACHED();
  346. };
  347. printf("%s", code().characters());
  348. }
  349. }
  350. void TestRunner::print_file_result(const JSFileResult& file_result) const
  351. {
  352. if (file_result.most_severe_test_result == TestResult::Fail || file_result.error.has_value()) {
  353. print_modifiers({ BG_RED, FG_BLACK, FG_BOLD });
  354. printf(" FAIL ");
  355. print_modifiers({ CLEAR });
  356. } else {
  357. if (m_print_times || file_result.most_severe_test_result != TestResult::Pass) {
  358. print_modifiers({ BG_GREEN, FG_BLACK, FG_BOLD });
  359. printf(" PASS ");
  360. print_modifiers({ CLEAR });
  361. } else {
  362. return;
  363. }
  364. }
  365. printf(" %s", file_result.name.characters());
  366. if (m_print_times) {
  367. print_modifiers({ CLEAR, ITALIC, FG_GRAY });
  368. if (file_result.time_taken < 1000) {
  369. printf(" (%dms)\n", static_cast<int>(file_result.time_taken));
  370. } else {
  371. printf(" (%.3fs)\n", file_result.time_taken / 1000.0);
  372. }
  373. print_modifiers({ CLEAR });
  374. } else {
  375. printf("\n");
  376. }
  377. if (!file_result.logged_messages.is_empty()) {
  378. print_modifiers({ FG_GRAY, FG_BOLD });
  379. #ifdef __serenity__
  380. printf(" ℹ Console output:\n");
  381. #else
  382. // This emoji has a second invisible byte after it. The one above does not
  383. printf(" ℹ️ Console output:\n");
  384. #endif
  385. print_modifiers({ CLEAR, FG_GRAY });
  386. for (auto& message : file_result.logged_messages)
  387. printf(" %s\n", message.characters());
  388. }
  389. if (file_result.error.has_value()) {
  390. auto test_error = file_result.error.value();
  391. print_modifiers({ FG_RED });
  392. #ifdef __serenity__
  393. printf(" ❌ The file failed to parse\n\n");
  394. #else
  395. // No invisible byte here, but the spacing still needs to be altered on the host
  396. printf(" ❌ The file failed to parse\n\n");
  397. #endif
  398. print_modifiers({ FG_GRAY });
  399. for (auto& message : test_error.hint.split('\n', true)) {
  400. printf(" %s\n", message.characters());
  401. }
  402. print_modifiers({ FG_RED });
  403. printf(" %s\n\n", test_error.error.to_string().characters());
  404. return;
  405. }
  406. if (file_result.most_severe_test_result != TestResult::Pass) {
  407. for (auto& suite : file_result.suites) {
  408. if (suite.most_severe_test_result == TestResult::Pass)
  409. continue;
  410. bool failed = suite.most_severe_test_result == TestResult::Fail;
  411. print_modifiers({ FG_GRAY, FG_BOLD });
  412. if (failed) {
  413. #ifdef __serenity__
  414. printf(" ❌ Suite: ");
  415. #else
  416. // No invisible byte here, but the spacing still needs to be altered on the host
  417. printf(" ❌ Suite: ");
  418. #endif
  419. } else {
  420. #ifdef __serenity__
  421. printf(" ⚠ Suite: ");
  422. #else
  423. // This emoji has a second invisible byte after it. The one above does not
  424. printf(" ⚠️ Suite: ");
  425. #endif
  426. }
  427. print_modifiers({ CLEAR, FG_GRAY });
  428. if (suite.name == TOP_LEVEL_TEST_NAME) {
  429. printf("<top-level>\n");
  430. } else {
  431. printf("%s\n", suite.name.characters());
  432. }
  433. print_modifiers({ CLEAR });
  434. for (auto& test : suite.tests) {
  435. if (test.result == TestResult::Pass)
  436. continue;
  437. print_modifiers({ FG_GRAY, FG_BOLD });
  438. printf(" Test: ");
  439. if (test.result == TestResult::Fail) {
  440. print_modifiers({ CLEAR, FG_RED });
  441. printf("%s (failed):\n", test.name.characters());
  442. printf(" %s\n", test.details.characters());
  443. } else {
  444. print_modifiers({ CLEAR, FG_ORANGE });
  445. printf("%s (skipped)\n", test.name.characters());
  446. }
  447. print_modifiers({ CLEAR });
  448. }
  449. }
  450. }
  451. }
  452. void TestRunner::print_test_results() const
  453. {
  454. printf("\nTest Suites: ");
  455. if (m_counts.suites_failed) {
  456. print_modifiers({ FG_RED });
  457. printf("%d failed, ", m_counts.suites_failed);
  458. print_modifiers({ CLEAR });
  459. }
  460. if (m_counts.suites_passed) {
  461. print_modifiers({ FG_GREEN });
  462. printf("%d passed, ", m_counts.suites_passed);
  463. print_modifiers({ CLEAR });
  464. }
  465. printf("%d total\n", m_counts.suites_failed + m_counts.suites_passed);
  466. printf("Tests: ");
  467. if (m_counts.tests_failed) {
  468. print_modifiers({ FG_RED });
  469. printf("%d failed, ", m_counts.tests_failed);
  470. print_modifiers({ CLEAR });
  471. }
  472. if (m_counts.tests_skipped) {
  473. print_modifiers({ FG_ORANGE });
  474. printf("%d skipped, ", m_counts.tests_skipped);
  475. print_modifiers({ CLEAR });
  476. }
  477. if (m_counts.tests_passed) {
  478. print_modifiers({ FG_GREEN });
  479. printf("%d passed, ", m_counts.tests_passed);
  480. print_modifiers({ CLEAR });
  481. }
  482. printf("%d total\n", m_counts.tests_failed + m_counts.tests_skipped + m_counts.tests_passed);
  483. printf("Files: %d total\n", m_counts.files_total);
  484. printf("Time: ");
  485. if (m_total_elapsed_time_in_ms < 1000.0) {
  486. printf("%dms\n\n", static_cast<int>(m_total_elapsed_time_in_ms));
  487. } else {
  488. printf("%-.3fs\n\n", m_total_elapsed_time_in_ms / 1000.0);
  489. }
  490. }
  491. int main(int argc, char** argv)
  492. {
  493. struct sigaction act;
  494. memset(&act, 0, sizeof(act));
  495. act.sa_flags = SA_NOCLDWAIT;
  496. act.sa_handler = handle_sigabrt;
  497. int rc = sigaction(SIGABRT, &act, nullptr);
  498. if (rc < 0) {
  499. perror("sigaction");
  500. return 1;
  501. }
  502. #ifdef SIGINFO
  503. signal(SIGINFO, [](int) {
  504. static char buffer[4096];
  505. auto& counts = TestRunner::the()->counts();
  506. int len = snprintf(buffer, sizeof(buffer), "Pass: %d, Fail: %d, Skip: %d\nCurrent test: %s\n", counts.tests_passed, counts.tests_failed, counts.tests_skipped, currently_running_test.characters());
  507. write(STDOUT_FILENO, buffer, len);
  508. });
  509. #endif
  510. bool print_times = false;
  511. const char* test_root = nullptr;
  512. Core::ArgsParser args_parser;
  513. args_parser.add_option(print_times, "Show duration of each test", "show-time", 't');
  514. args_parser.add_option(collect_on_every_allocation, "Collect garbage after every allocation", "collect-often", 'g');
  515. args_parser.add_positional_argument(test_root, "Tests root directory", "path", Core::ArgsParser::Required::No);
  516. args_parser.parse(argc, argv);
  517. if (getenv("DISABLE_DBG_OUTPUT")) {
  518. DebugLogStream::set_enabled(false);
  519. }
  520. if (!test_root) {
  521. #ifdef __serenity__
  522. test_root = "/home/anon/js-tests";
  523. #else
  524. char* serenity_root = getenv("SERENITY_ROOT");
  525. if (!serenity_root) {
  526. printf("No test root given, test-js requires the SERENITY_ROOT environment variable to be set");
  527. return 1;
  528. }
  529. test_root = String::formatted("{}/Libraries/LibJS/Tests", serenity_root).characters();
  530. #endif
  531. }
  532. if (!Core::File::is_directory(test_root)) {
  533. fprintf(stderr, "Test root is not a directory: %s\n", test_root);
  534. return 1;
  535. }
  536. vm = JS::VM::create();
  537. TestRunner(test_root, print_times).run();
  538. vm = nullptr;
  539. return TestRunner::the()->counts().tests_failed > 0 ? 1 : 0;
  540. }