1 //===- unittests/Basic/SanitizersTest.cpp - Test Sanitizers ---------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "clang/Basic/Sanitizers.h"
11 #include "gmock/gmock-matchers.h"
12 #include "gtest/gtest.h"
14 using namespace clang
;
16 using testing::Contains
;
19 TEST(SanitizersTest
, serializeSanitizers
) {
21 Set
.set(parseSanitizerValue("memory", false), true);
22 Set
.set(parseSanitizerValue("nullability-arg", false), true);
24 SmallVector
<StringRef
, 4> Serialized
;
25 serializeSanitizerSet(Set
, Serialized
);
27 ASSERT_EQ(Serialized
.size(), 2u);
28 ASSERT_THAT(Serialized
, Contains("memory"));
29 ASSERT_THAT(Serialized
, Contains("nullability-arg"));
32 TEST(SanitizersTest
, serializeSanitizersIndividual
) {
34 Set
.set(parseSanitizerValue("memory", false), true);
35 Set
.set(parseSanitizerValue("nullability-arg", false), true);
36 Set
.set(parseSanitizerValue("nullability-assign", false), true);
37 Set
.set(parseSanitizerValue("nullability-return", false), true);
39 SmallVector
<StringRef
, 4> Serialized
;
40 serializeSanitizerSet(Set
, Serialized
);
42 ASSERT_EQ(Serialized
.size(), 4u);
43 ASSERT_THAT(Serialized
, Contains("memory"));
44 ASSERT_THAT(Serialized
, Contains("nullability-arg"));
45 ASSERT_THAT(Serialized
, Contains("nullability-assign"));
46 ASSERT_THAT(Serialized
, Contains("nullability-return"));
47 // Individual sanitizers don't get squashed into a single group.
48 ASSERT_THAT(Serialized
, Not(Contains("nullability")));