TestMain.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/Format.h>
  8. #include <AK/Vector.h>
  9. #include <LibTest/TestSuite.h>
  10. #ifdef KERNEL
  11. # define TEST_MAIN test_main
  12. #else
  13. # define TEST_MAIN main
  14. #endif
  15. int TEST_MAIN(int argc, char** argv)
  16. {
  17. if (argc < 1 || !argv[0] || '\0' == *argv[0]) {
  18. warnln("Test main does not have a valid test name!");
  19. return 1;
  20. }
  21. Vector<StringView> arguments;
  22. arguments.ensure_capacity(argc);
  23. for (auto i = 0; i < argc; ++i)
  24. arguments.append({ argv[i], strlen(argv[i]) });
  25. int ret = ::Test::TestSuite::the().main(argv[0], arguments);
  26. ::Test::TestSuite::release();
  27. // As TestSuite::main() returns the number of test cases that did not pass,
  28. // ret can be >=256 which cannot be returned as an exit status directly.
  29. // Return 0 if all of the test cases pass and return 1 otherwise.
  30. return ret != 0;
  31. }