TestAssert.cpp 965 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibTest/TestCase.h>
  7. #undef NDEBUG
  8. #include <assert.h>
  9. #include <signal.h>
  10. TEST_CASE(assert)
  11. {
  12. EXPECT_CRASH("This should assert", [] {
  13. assert(!"This should assert");
  14. return Test::Crash::Failure::DidNotCrash;
  15. });
  16. EXPECT_CRASH_WITH_SIGNAL("This should assert with SIGABRT signal", SIGABRT, [] {
  17. assert(!"This should assert");
  18. return Test::Crash::Failure::DidNotCrash;
  19. });
  20. }
  21. #define NDEBUG
  22. #include <assert.h>
  23. TEST_CASE(assert_reinclude)
  24. {
  25. EXPECT_NO_CRASH("This should not assert", [] {
  26. assert(!"This should not assert");
  27. return Test::Crash::Failure::DidNotCrash;
  28. });
  29. }
  30. #undef NDEBUG
  31. #include <assert.h>
  32. TEST_CASE(assert_rereinclude)
  33. {
  34. EXPECT_CRASH("This should assert", [] {
  35. assert(!"This should assert");
  36. return Test::Crash::Failure::DidNotCrash;
  37. });
  38. }