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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/test/expectations/parser.h"
#include <string>
#include <vector>
#include "base/compiler_specific.h"
#include "testing/gtest/include/gtest/gtest.h"
using test_expectations::Parser;
class TestExpectationParserTest : public testing::Test,
public Parser::Delegate {
public:
virtual void EmitExpectation(
const test_expectations::Expectation& expectation) OVERRIDE {
expectations_.push_back(expectation);
}
virtual void OnSyntaxError(const std::string& message) OVERRIDE {
syntax_error_ = message;
}
virtual void OnDataError(const std::string& error) OVERRIDE {
data_errors_.push_back(error);
}
protected:
std::vector<test_expectations::Expectation> expectations_;
std::string syntax_error_;
std::vector<std::string> data_errors_;
};
TEST_F(TestExpectationParserTest, Basic) {
Parser(this,
"http://crbug.com/1234 [ Win-8 ] DouglasTest.PoopsOk = Timeout").
Parse();
EXPECT_TRUE(syntax_error_.empty());
EXPECT_EQ(0u, data_errors_.size());
ASSERT_EQ(1u, expectations_.size());
EXPECT_EQ("DouglasTest.PoopsOk", expectations_[0].test_name);
EXPECT_EQ(test_expectations::RESULT_TIMEOUT, expectations_[0].result);
EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED,
expectations_[0].configuration);
ASSERT_EQ(1u, expectations_[0].platforms.size());
EXPECT_EQ("Win", expectations_[0].platforms[0].name);
EXPECT_EQ("8", expectations_[0].platforms[0].variant);
}
TEST_F(TestExpectationParserTest, MultiModifier) {
Parser(this, "BUG [ Win-XP Mac ] OhMy.MeOhMy = Failure").Parse();
EXPECT_TRUE(syntax_error_.empty());
EXPECT_EQ(0u, data_errors_.size());
ASSERT_EQ(1u, expectations_.size());
EXPECT_EQ("OhMy.MeOhMy", expectations_[0].test_name);
EXPECT_EQ(test_expectations::RESULT_FAILURE,
expectations_[0].result);
EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED,
expectations_[0].configuration);
ASSERT_EQ(2u, expectations_[0].platforms.size());
EXPECT_EQ("Win", expectations_[0].platforms[0].name);
EXPECT_EQ("XP", expectations_[0].platforms[0].variant);
EXPECT_EQ("Mac", expectations_[0].platforms[1].name);
EXPECT_EQ("", expectations_[0].platforms[1].variant);
}
TEST_F(TestExpectationParserTest, EmptyModifier) {
Parser(this,
"BUG [] First.Test = Failure\n"
"BUG2 [ ] Second.Test = Crash").Parse();
EXPECT_EQ(0u, data_errors_.size());
ASSERT_EQ(2u, expectations_.size());
EXPECT_EQ("First.Test", expectations_[0].test_name);
EXPECT_EQ(test_expectations::RESULT_FAILURE,
expectations_[0].result);
EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED,
expectations_[0].configuration);
EXPECT_EQ(0u, expectations_[0].platforms.size());
EXPECT_EQ("Second.Test", expectations_[1].test_name);
EXPECT_EQ(test_expectations::RESULT_CRASH,
expectations_[1].result);
EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED,
expectations_[1].configuration);
EXPECT_EQ(0u, expectations_[1].platforms.size());
}
TEST_F(TestExpectationParserTest, MultiLine) {
Parser(this,
"BUG [ Linux ] Line.First = Failure\n"
"\n"
"# A test comment.\n"
"BUG2 [ Release ] Line.Second = Skip").Parse();
EXPECT_TRUE(syntax_error_.empty());
EXPECT_EQ(0u, data_errors_.size());
ASSERT_EQ(2u, expectations_.size());
EXPECT_EQ("Line.First", expectations_[0].test_name);
EXPECT_EQ(test_expectations::RESULT_FAILURE, expectations_[0].result);
EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED,
expectations_[0].configuration);
ASSERT_EQ(1u, expectations_[0].platforms.size());
EXPECT_EQ("Linux", expectations_[0].platforms[0].name);
EXPECT_EQ("", expectations_[0].platforms[0].variant);
EXPECT_EQ("Line.Second", expectations_[1].test_name);
EXPECT_EQ(test_expectations::RESULT_SKIP, expectations_[1].result);
EXPECT_EQ(test_expectations::CONFIGURATION_RELEASE,
expectations_[1].configuration);
EXPECT_EQ(0u, expectations_[1].platforms.size());
}
TEST_F(TestExpectationParserTest, MultiLineWithComments) {
Parser(this,
" # Comment for your thoughts\n"
" \t \n"
"BUG [ Mac-10.8 Debug] Foo=Bar =Skip # Why not another comment?\n"
"BUG2 [Win-XP\tWin-Vista ] Cow.GoesMoo =\tTimeout\n\n").Parse();
EXPECT_TRUE(syntax_error_.empty()) << syntax_error_;
EXPECT_EQ(0u, data_errors_.size());
ASSERT_EQ(2u, expectations_.size());
EXPECT_EQ("Foo=Bar", expectations_[0].test_name);
EXPECT_EQ(test_expectations::RESULT_SKIP, expectations_[0].result);
EXPECT_EQ(test_expectations::CONFIGURATION_DEBUG,
expectations_[0].configuration);
ASSERT_EQ(1u, expectations_[0].platforms.size());
EXPECT_EQ("Mac", expectations_[0].platforms[0].name);
EXPECT_EQ("10.8", expectations_[0].platforms[0].variant);
EXPECT_EQ("Cow.GoesMoo", expectations_[1].test_name);
EXPECT_EQ(test_expectations::RESULT_TIMEOUT, expectations_[1].result);
EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED,
expectations_[1].configuration);
ASSERT_EQ(2u, expectations_[1].platforms.size());
EXPECT_EQ("Win", expectations_[1].platforms[0].name);
EXPECT_EQ("XP", expectations_[1].platforms[0].variant);
EXPECT_EQ("Win", expectations_[1].platforms[0].name);
EXPECT_EQ("Vista", expectations_[1].platforms[1].variant);
}
TEST_F(TestExpectationParserTest, WeirdSpaces) {
Parser(this, " BUG [Linux] Weird = Skip ").Parse();
EXPECT_EQ(1u, expectations_.size());
EXPECT_TRUE(syntax_error_.empty());
EXPECT_EQ(0u, data_errors_.size());
}
TEST_F(TestExpectationParserTest, SyntaxErrors) {
const char* kErrors[] = {
"Foo [ dfasd",
"Foo [Linux] # This is an illegal comment",
"Foo [Linux] Bar # Another illegal comment.",
"Foo [Linux] Bar = # Another illegal comment.",
"Foo[Linux]Bar=Failure",
"Foo\n[Linux] Bar = Failure",
"Foo [\nLinux] Bar = Failure",
"Foo [Linux\n] Bar = Failure",
"Foo [ Linux ] \n Bar = Failure",
"Foo [ Linux ] Bar =\nFailure",
"Foo [ Linux \n ] Bar =\nFailure",
};
for (size_t i = 0; i < arraysize(kErrors); ++i) {
Parser(this, kErrors[i]).Parse();
EXPECT_FALSE(syntax_error_.empty())
<< "Should have error for #" << i << ": " << kErrors[i];
syntax_error_.clear();
}
}
TEST_F(TestExpectationParserTest, DataErrors) {
const char* kOneError[] = {
"http://crbug.com/1234 [MagicBrowzR] BadModifier = Timeout",
"________ [Linux] BadResult = WhatNow",
"http://wkb.ug/1234 [Debug Release Win-7] MultipleConfigs = Skip",
};
for (size_t i = 0; i < arraysize(kOneError); ++i) {
Parser(this, kOneError[i]).Parse();
EXPECT_EQ(1u, data_errors_.size()) << kOneError[i];
data_errors_.clear();
}
const char* kTwoErrors[] = {
". [Mac-TurningIntoiOS] BadModifierVariant.BadResult = Foobar",
"1234 [ Debug Release OS/2 ] MultipleConfigs.BadModifier = Pass",
};
for (size_t i = 0; i < arraysize(kTwoErrors); ++i) {
Parser(this, kTwoErrors[i]).Parse();
EXPECT_EQ(2u, data_errors_.size()) << kTwoErrors[i];
data_errors_.clear();
}
}
|