Mercurial > hg > CbC > CbC_llvm
comparison unittests/Support/SpecialCaseListTest.cpp @ 83:60c9769439b8 LLVM3.7
LLVM 3.7
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 18 Feb 2015 14:55:36 +0900 |
parents | 54457678186b |
children | 1172e4bd9c6f |
comparison
equal
deleted
inserted
replaced
78:af83660cff7b | 83:60c9769439b8 |
---|---|
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 | 9 |
10 #include "llvm/Support/FileSystem.h" | |
10 #include "llvm/Support/MemoryBuffer.h" | 11 #include "llvm/Support/MemoryBuffer.h" |
11 #include "llvm/Support/SpecialCaseList.h" | 12 #include "llvm/Support/SpecialCaseList.h" |
12 #include "gtest/gtest.h" | 13 #include "gtest/gtest.h" |
13 | 14 |
14 using namespace llvm; | 15 using namespace llvm; |
28 auto SCL = makeSpecialCaseList(List, Error); | 29 auto SCL = makeSpecialCaseList(List, Error); |
29 assert(SCL); | 30 assert(SCL); |
30 assert(Error == ""); | 31 assert(Error == ""); |
31 return SCL; | 32 return SCL; |
32 } | 33 } |
34 | |
35 std::string makeSpecialCaseListFile(StringRef Contents) { | |
36 int FD; | |
37 SmallString<64> Path; | |
38 sys::fs::createTemporaryFile("SpecialCaseListTest", "temp", FD, Path); | |
39 raw_fd_ostream OF(FD, true, true); | |
40 OF << Contents; | |
41 OF.close(); | |
42 return Path.str(); | |
43 } | |
33 }; | 44 }; |
34 | 45 |
35 TEST_F(SpecialCaseListTest, Basic) { | 46 TEST_F(SpecialCaseListTest, Basic) { |
36 std::unique_ptr<SpecialCaseList> SCL = | 47 std::unique_ptr<SpecialCaseList> SCL = |
37 makeSpecialCaseList("# This is a comment.\n" | 48 makeSpecialCaseList("# This is a comment.\n" |
47 EXPECT_FALSE(SCL->inSection("src", "hi")); | 58 EXPECT_FALSE(SCL->inSection("src", "hi")); |
48 EXPECT_FALSE(SCL->inSection("fun", "hello")); | 59 EXPECT_FALSE(SCL->inSection("fun", "hello")); |
49 EXPECT_FALSE(SCL->inSection("src", "hello", "category")); | 60 EXPECT_FALSE(SCL->inSection("src", "hello", "category")); |
50 } | 61 } |
51 | 62 |
52 TEST_F(SpecialCaseListTest, GlobalInitCompat) { | 63 TEST_F(SpecialCaseListTest, GlobalInit) { |
53 std::unique_ptr<SpecialCaseList> SCL = | 64 std::unique_ptr<SpecialCaseList> SCL = |
54 makeSpecialCaseList("global:foo=init\n"); | 65 makeSpecialCaseList("global:foo=init\n"); |
55 EXPECT_FALSE(SCL->inSection("global", "foo")); | |
56 EXPECT_FALSE(SCL->inSection("global", "bar")); | |
57 EXPECT_TRUE(SCL->inSection("global", "foo", "init")); | |
58 EXPECT_FALSE(SCL->inSection("global", "bar", "init")); | |
59 | |
60 SCL = makeSpecialCaseList("global-init:foo\n"); | |
61 EXPECT_FALSE(SCL->inSection("global", "foo")); | 66 EXPECT_FALSE(SCL->inSection("global", "foo")); |
62 EXPECT_FALSE(SCL->inSection("global", "bar")); | 67 EXPECT_FALSE(SCL->inSection("global", "bar")); |
63 EXPECT_TRUE(SCL->inSection("global", "foo", "init")); | 68 EXPECT_TRUE(SCL->inSection("global", "foo", "init")); |
64 EXPECT_FALSE(SCL->inSection("global", "bar", "init")); | 69 EXPECT_FALSE(SCL->inSection("global", "bar", "init")); |
65 | 70 |
67 EXPECT_FALSE(SCL->inSection("type", "t1")); | 72 EXPECT_FALSE(SCL->inSection("type", "t1")); |
68 EXPECT_FALSE(SCL->inSection("type", "t2")); | 73 EXPECT_FALSE(SCL->inSection("type", "t2")); |
69 EXPECT_FALSE(SCL->inSection("type", "t1", "init")); | 74 EXPECT_FALSE(SCL->inSection("type", "t1", "init")); |
70 EXPECT_TRUE(SCL->inSection("type", "t2", "init")); | 75 EXPECT_TRUE(SCL->inSection("type", "t2", "init")); |
71 | 76 |
72 SCL = makeSpecialCaseList("global-init-type:t2\n"); | |
73 EXPECT_FALSE(SCL->inSection("type", "t1")); | |
74 EXPECT_FALSE(SCL->inSection("type", "t2")); | |
75 EXPECT_FALSE(SCL->inSection("type", "t1", "init")); | |
76 EXPECT_TRUE(SCL->inSection("type", "t2", "init")); | |
77 | |
78 SCL = makeSpecialCaseList("src:hello=init\n"); | 77 SCL = makeSpecialCaseList("src:hello=init\n"); |
79 EXPECT_FALSE(SCL->inSection("src", "hello")); | |
80 EXPECT_FALSE(SCL->inSection("src", "bye")); | |
81 EXPECT_TRUE(SCL->inSection("src", "hello", "init")); | |
82 EXPECT_FALSE(SCL->inSection("src", "bye", "init")); | |
83 | |
84 SCL = makeSpecialCaseList("global-init-src:hello\n"); | |
85 EXPECT_FALSE(SCL->inSection("src", "hello")); | 78 EXPECT_FALSE(SCL->inSection("src", "hello")); |
86 EXPECT_FALSE(SCL->inSection("src", "bye")); | 79 EXPECT_FALSE(SCL->inSection("src", "bye")); |
87 EXPECT_TRUE(SCL->inSection("src", "hello", "init")); | 80 EXPECT_TRUE(SCL->inSection("src", "hello", "init")); |
88 EXPECT_FALSE(SCL->inSection("src", "bye", "init")); | 81 EXPECT_FALSE(SCL->inSection("src", "bye", "init")); |
89 } | 82 } |
102 } | 95 } |
103 | 96 |
104 TEST_F(SpecialCaseListTest, InvalidSpecialCaseList) { | 97 TEST_F(SpecialCaseListTest, InvalidSpecialCaseList) { |
105 std::string Error; | 98 std::string Error; |
106 EXPECT_EQ(nullptr, makeSpecialCaseList("badline", Error)); | 99 EXPECT_EQ(nullptr, makeSpecialCaseList("badline", Error)); |
107 EXPECT_EQ("Malformed line 1: 'badline'", Error); | 100 EXPECT_EQ("malformed line 1: 'badline'", Error); |
108 EXPECT_EQ(nullptr, makeSpecialCaseList("src:bad[a-", Error)); | 101 EXPECT_EQ(nullptr, makeSpecialCaseList("src:bad[a-", Error)); |
109 EXPECT_EQ("Malformed regex in line 1: 'bad[a-': invalid character range", | 102 EXPECT_EQ("malformed regex in line 1: 'bad[a-': invalid character range", |
110 Error); | 103 Error); |
111 EXPECT_EQ(nullptr, makeSpecialCaseList("src:a.c\n" | 104 EXPECT_EQ(nullptr, makeSpecialCaseList("src:a.c\n" |
112 "fun:fun(a\n", | 105 "fun:fun(a\n", |
113 Error)); | 106 Error)); |
114 EXPECT_EQ("Malformed regex in line 2: 'fun(a': parentheses not balanced", | 107 EXPECT_EQ("malformed regex in line 2: 'fun(a': parentheses not balanced", |
115 Error); | 108 Error); |
116 EXPECT_EQ(nullptr, SpecialCaseList::create("unexisting", Error)); | 109 std::vector<std::string> Files(1, "unexisting"); |
117 EXPECT_EQ(0U, Error.find("Can't open file 'unexisting':")); | 110 EXPECT_EQ(nullptr, SpecialCaseList::create(Files, Error)); |
111 EXPECT_EQ(0U, Error.find("can't open file 'unexisting':")); | |
118 } | 112 } |
119 | 113 |
120 TEST_F(SpecialCaseListTest, EmptySpecialCaseList) { | 114 TEST_F(SpecialCaseListTest, EmptySpecialCaseList) { |
121 std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList(""); | 115 std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList(""); |
122 EXPECT_FALSE(SCL->inSection("foo", "bar")); | 116 EXPECT_FALSE(SCL->inSection("foo", "bar")); |
123 } | 117 } |
124 | 118 |
119 TEST_F(SpecialCaseListTest, MultipleBlacklists) { | |
120 std::vector<std::string> Files; | |
121 Files.push_back(makeSpecialCaseListFile("src:bar\n" | |
122 "src:*foo*\n" | |
123 "src:ban=init\n")); | |
124 Files.push_back(makeSpecialCaseListFile("src:baz\n" | |
125 "src:*fog*\n")); | |
126 auto SCL = SpecialCaseList::createOrDie(Files); | |
127 EXPECT_TRUE(SCL->inSection("src", "bar")); | |
128 EXPECT_TRUE(SCL->inSection("src", "baz")); | |
129 EXPECT_FALSE(SCL->inSection("src", "ban")); | |
130 EXPECT_TRUE(SCL->inSection("src", "ban", "init")); | |
131 EXPECT_TRUE(SCL->inSection("src", "tomfoolery")); | |
132 EXPECT_TRUE(SCL->inSection("src", "tomfoglery")); | |
125 } | 133 } |
126 | 134 |
127 | 135 } |