-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathBlocklistTest.cpp
119 lines (109 loc) · 6.43 KB
/
BlocklistTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//===------- BlocklistTest.cpp --------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "gtest/gtest.h"
#include "swift/AST/SearchPathOptions.h"
#include "swift/Basic/Defer.h"
#include "swift/Basic/BlockList.h"
#include "swift/Basic/SourceManager.h"
using namespace swift;
static std::string createFilename(StringRef base, StringRef name) {
SmallString<256> path = base;
llvm::sys::path::append(path, name);
return llvm::Twine(path).str();
}
static bool emitFileWithContents(StringRef path, StringRef contents,
std::string *pathOut = nullptr) {
int FD;
if (llvm::sys::fs::openFileForWrite(path, FD))
return true;
if (pathOut)
*pathOut = path.str();
llvm::raw_fd_ostream file(FD, /*shouldClose=*/true);
file << contents;
return false;
}
static bool emitFileWithContents(StringRef base, StringRef name,
StringRef contents,
std::string *pathOut = nullptr) {
return emitFileWithContents(createFilename(base, name), contents, pathOut);
}
TEST(BlocklistTest, testYamlParsing) {
SmallString<256> temp;
ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory(
"BlocklistTest.testYamlParsing", temp));
SWIFT_DEFER { llvm::sys::fs::remove_directories(temp); };
SourceManager sm;
BlockListStore store(sm);
std::string path1, path2;
ASSERT_FALSE(emitFileWithContents(temp, "block1.yaml",
"---\n"
"ShouldUseBinaryModule:\n"
" ModuleName:\n"
" - M1 #rdar12345\n"
" - M2 #rdar12345\n"
" - M3\n"
" - M4\n"
" ProjectName:\n"
" - P1\n"
" - P2\n"
" - P3 #rdar12344\n"
" - P4\n"
"---\n"
"ShouldUseTextualModule:\n"
" ModuleName:\n"
" - M1_2 #rdar12345\n"
" - M2_2 #rdar12345\n"
" - M3_2\n"
" - M4_2\n"
" ProjectName:\n"
" - P1_2\n"
" - P2_2\n"
" - P3_2 #rdar12344\n"
" - P4_2\n",
&path1));
ASSERT_FALSE(emitFileWithContents(temp, "block2.yml",
"---\n"
"ShouldUseBinaryModule:\n"
" ModuleName:\n"
" - M1_block2 #rdar12345\n"
" ProjectName:\n"
" - P1_block2\n"
"---\n"
"ShouldUseTextualModule:\n"
" ModuleName:\n"
" - M1_2_block2 #rdar12345\n"
" ProjectName:\n"
" - P1_2_block2\n",
&path2));
store.addConfigureFilePath(path1);
store.addConfigureFilePath(path2);
ASSERT_TRUE(store.hasBlockListAction("M1", BlockListKeyKind::ModuleName, BlockListAction::ShouldUseBinaryModule));
ASSERT_TRUE(store.hasBlockListAction("M2", BlockListKeyKind::ModuleName, BlockListAction::ShouldUseBinaryModule));
ASSERT_TRUE(store.hasBlockListAction("P1", BlockListKeyKind::ProjectName, BlockListAction::ShouldUseBinaryModule));
ASSERT_TRUE(store.hasBlockListAction("P2", BlockListKeyKind::ProjectName, BlockListAction::ShouldUseBinaryModule));
ASSERT_TRUE(store.hasBlockListAction("M1_2", BlockListKeyKind::ModuleName, BlockListAction::ShouldUseTextualModule));
ASSERT_TRUE(store.hasBlockListAction("M2_2", BlockListKeyKind::ModuleName, BlockListAction::ShouldUseTextualModule));
ASSERT_TRUE(store.hasBlockListAction("P1_2", BlockListKeyKind::ProjectName, BlockListAction::ShouldUseTextualModule));
ASSERT_TRUE(store.hasBlockListAction("P2_2", BlockListKeyKind::ProjectName, BlockListAction::ShouldUseTextualModule));
ASSERT_FALSE(store.hasBlockListAction("P1", BlockListKeyKind::ModuleName, BlockListAction::ShouldUseBinaryModule));
ASSERT_FALSE(store.hasBlockListAction("P2", BlockListKeyKind::ModuleName, BlockListAction::ShouldUseBinaryModule));
ASSERT_FALSE(store.hasBlockListAction("M1", BlockListKeyKind::ProjectName, BlockListAction::ShouldUseBinaryModule));
ASSERT_FALSE(store.hasBlockListAction("M2", BlockListKeyKind::ProjectName, BlockListAction::ShouldUseBinaryModule));
ASSERT_TRUE(store.hasBlockListAction("M1_block2", BlockListKeyKind::ModuleName, BlockListAction::ShouldUseBinaryModule));
ASSERT_TRUE(store.hasBlockListAction("P1_block2", BlockListKeyKind::ProjectName, BlockListAction::ShouldUseBinaryModule));
ASSERT_TRUE(store.hasBlockListAction("M1_2_block2", BlockListKeyKind::ModuleName, BlockListAction::ShouldUseTextualModule));
ASSERT_TRUE(store.hasBlockListAction("P1_2_block2", BlockListKeyKind::ProjectName, BlockListAction::ShouldUseTextualModule));
ASSERT_FALSE(store.hasBlockListAction("M1_block2", BlockListKeyKind::ProjectName, BlockListAction::ShouldUseBinaryModule));
ASSERT_FALSE(store.hasBlockListAction("P1_block2", BlockListKeyKind::ModuleName, BlockListAction::ShouldUseBinaryModule));
ASSERT_FALSE(store.hasBlockListAction("M1_2_block2", BlockListKeyKind::ProjectName, BlockListAction::ShouldUseTextualModule));
ASSERT_FALSE(store.hasBlockListAction("P1_2_block2", BlockListKeyKind::ModuleName, BlockListAction::ShouldUseTextualModule));
}