xref: /llvm-project/compiler-rt/lib/gwp_asan/tests/utilities.cpp (revision 0a94511aec7a41194c0e61d88801312542ff70ce)
1 //===-- utilities.cpp -------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "gwp_asan/utilities.h"
10 #include "gwp_asan/tests/harness.h"
11 
12 using gwp_asan::check;
13 using gwp_asan::checkWithErrorCode;
14 
15 TEST(UtilitiesDeathTest, CheckPrintsAsExpected) {
16   EXPECT_DEATH({ check(false, "Hello world"); }, "Hello world");
17   check(true, "Should not crash");
18   EXPECT_DEATH(
19       { checkWithErrorCode(false, "Hello world", 1337); },
20       "Hello world \\(Error Code: 1337\\)");
21   EXPECT_DEATH(
22       { checkWithErrorCode(false, "Hello world", -1337); },
23       "Hello world \\(Error Code: -1337\\)");
24 }
25