1//===- unittests/Basic/SanitizersTest.cpp - Test Sanitizers ---------------===//
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 "clang/Basic/Sanitizers.h"
10
11#include "gmock/gmock-matchers.h"
12#include "gtest/gtest.h"
13
14using namespace clang;
15
16using testing::Contains;
17using testing::Not;
18
19TEST(SanitizersTest, serializeSanitizers) {
20 SanitizerSet Set;
21 Set.set(K: parseSanitizerValue(Value: "memory", AllowGroups: false), Value: true);
22 Set.set(K: parseSanitizerValue(Value: "nullability-arg", AllowGroups: false), Value: true);
23
24 SmallVector<StringRef, 4> Serialized;
25 serializeSanitizerSet(Set, Values&: Serialized);
26
27 ASSERT_EQ(Serialized.size(), 2u);
28 ASSERT_THAT(Serialized, Contains("memory"));
29 ASSERT_THAT(Serialized, Contains("nullability-arg"));
30}
31
32TEST(SanitizersTest, serializeSanitizersIndividual) {
33 SanitizerSet Set;
34 Set.set(K: parseSanitizerValue(Value: "memory", AllowGroups: false), Value: true);
35 Set.set(K: parseSanitizerValue(Value: "nullability-arg", AllowGroups: false), Value: true);
36 Set.set(K: parseSanitizerValue(Value: "nullability-assign", AllowGroups: false), Value: true);
37 Set.set(K: parseSanitizerValue(Value: "nullability-return", AllowGroups: false), Value: true);
38
39 SmallVector<StringRef, 4> Serialized;
40 serializeSanitizerSet(Set, Values&: Serialized);
41
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")));
49}
50

source code of clang/unittests/Basic/SanitizersTest.cpp