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