mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
a42cf020ea
Before, TEST_MAIN used to return the return value of TestSuite::main() function (which returns the number of test cases that did not pass, so it can be >=256) directly. The run-tests utility determines the success / failure of a test suite binary by examining its (or i.e. TEST_MAIN's) exit status. But as exit status values are supposed to be between 0 and 255, values >=256 will get wrapped around (modulo 256), converting a return value of 256 to 0. So, in a rare case where exactly 256 test cases are failing in your test suite, run-tests utility will display that the test suite passed without any failures. Now, TEST_MAIN just returns 0 if all of the test cases pass and returns 1 otherwise.
37 lines
1.0 KiB
C++
37 lines
1.0 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/Format.h>
|
|
#include <AK/Vector.h>
|
|
#include <LibTest/TestSuite.h>
|
|
|
|
#ifdef KERNEL
|
|
# define TEST_MAIN test_main
|
|
#else
|
|
# define TEST_MAIN main
|
|
#endif
|
|
|
|
int TEST_MAIN(int argc, char** argv)
|
|
{
|
|
if (argc < 1 || !argv[0] || '\0' == *argv[0]) {
|
|
warnln("Test main does not have a valid test name!");
|
|
return 1;
|
|
}
|
|
|
|
Vector<StringView> arguments;
|
|
arguments.ensure_capacity(argc);
|
|
for (auto i = 0; i < argc; ++i)
|
|
arguments.append({ argv[i], strlen(argv[i]) });
|
|
|
|
int ret = ::Test::TestSuite::the().main(argv[0], arguments);
|
|
::Test::TestSuite::release();
|
|
// As TestSuite::main() returns the number of test cases that did not pass,
|
|
// ret can be >=256 which cannot be returned as an exit status directly.
|
|
// Return 0 if all of the test cases pass and return 1 otherwise.
|
|
return ret != 0;
|
|
}
|