1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/test/expectations/parser.h"
10 #include "base/compiler_specific.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 using test_expectations::Parser
;
15 class TestExpectationParserTest
: public testing::Test
,
16 public Parser::Delegate
{
19 const test_expectations::Expectation
& expectation
) override
{
20 expectations_
.push_back(expectation
);
23 void OnSyntaxError(const std::string
& message
) override
{
24 syntax_error_
= message
;
27 void OnDataError(const std::string
& error
) override
{
28 data_errors_
.push_back(error
);
32 std::vector
<test_expectations::Expectation
> expectations_
;
33 std::string syntax_error_
;
34 std::vector
<std::string
> data_errors_
;
37 TEST_F(TestExpectationParserTest
, Basic
) {
39 "http://crbug.com/1234 [ Win-8 ] DouglasTest.PoopsOk = Timeout").
41 EXPECT_TRUE(syntax_error_
.empty());
42 EXPECT_EQ(0u, data_errors_
.size());
44 ASSERT_EQ(1u, expectations_
.size());
45 EXPECT_EQ("DouglasTest.PoopsOk", expectations_
[0].test_name
);
46 EXPECT_EQ(test_expectations::RESULT_TIMEOUT
, expectations_
[0].result
);
47 EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED
,
48 expectations_
[0].configuration
);
50 ASSERT_EQ(1u, expectations_
[0].platforms
.size());
51 EXPECT_EQ("Win", expectations_
[0].platforms
[0].name
);
52 EXPECT_EQ("8", expectations_
[0].platforms
[0].variant
);
55 TEST_F(TestExpectationParserTest
, MultiModifier
) {
56 Parser(this, "BUG [ Win-XP Mac ] OhMy.MeOhMy = Failure").Parse();
57 EXPECT_TRUE(syntax_error_
.empty());
58 EXPECT_EQ(0u, data_errors_
.size());
60 ASSERT_EQ(1u, expectations_
.size());
61 EXPECT_EQ("OhMy.MeOhMy", expectations_
[0].test_name
);
62 EXPECT_EQ(test_expectations::RESULT_FAILURE
,
63 expectations_
[0].result
);
64 EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED
,
65 expectations_
[0].configuration
);
67 ASSERT_EQ(2u, expectations_
[0].platforms
.size());
69 EXPECT_EQ("Win", expectations_
[0].platforms
[0].name
);
70 EXPECT_EQ("XP", expectations_
[0].platforms
[0].variant
);
72 EXPECT_EQ("Mac", expectations_
[0].platforms
[1].name
);
73 EXPECT_EQ("", expectations_
[0].platforms
[1].variant
);
76 TEST_F(TestExpectationParserTest
, EmptyModifier
) {
78 "BUG [] First.Test = Failure\n"
79 "BUG2 [ ] Second.Test = Crash").Parse();
80 EXPECT_EQ(0u, data_errors_
.size());
82 ASSERT_EQ(2u, expectations_
.size());
84 EXPECT_EQ("First.Test", expectations_
[0].test_name
);
85 EXPECT_EQ(test_expectations::RESULT_FAILURE
,
86 expectations_
[0].result
);
87 EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED
,
88 expectations_
[0].configuration
);
89 EXPECT_EQ(0u, expectations_
[0].platforms
.size());
91 EXPECT_EQ("Second.Test", expectations_
[1].test_name
);
92 EXPECT_EQ(test_expectations::RESULT_CRASH
,
93 expectations_
[1].result
);
94 EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED
,
95 expectations_
[1].configuration
);
96 EXPECT_EQ(0u, expectations_
[1].platforms
.size());
99 TEST_F(TestExpectationParserTest
, MultiLine
) {
101 "BUG [ Linux ] Line.First = Failure\n"
103 "# A test comment.\n"
104 "BUG2 [ Release ] Line.Second = Skip").Parse();
105 EXPECT_TRUE(syntax_error_
.empty());
106 EXPECT_EQ(0u, data_errors_
.size());
108 ASSERT_EQ(2u, expectations_
.size());
109 EXPECT_EQ("Line.First", expectations_
[0].test_name
);
110 EXPECT_EQ(test_expectations::RESULT_FAILURE
, expectations_
[0].result
);
111 EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED
,
112 expectations_
[0].configuration
);
114 ASSERT_EQ(1u, expectations_
[0].platforms
.size());
115 EXPECT_EQ("Linux", expectations_
[0].platforms
[0].name
);
116 EXPECT_EQ("", expectations_
[0].platforms
[0].variant
);
118 EXPECT_EQ("Line.Second", expectations_
[1].test_name
);
119 EXPECT_EQ(test_expectations::RESULT_SKIP
, expectations_
[1].result
);
120 EXPECT_EQ(test_expectations::CONFIGURATION_RELEASE
,
121 expectations_
[1].configuration
);
122 EXPECT_EQ(0u, expectations_
[1].platforms
.size());
125 TEST_F(TestExpectationParserTest
, MultiLineWithComments
) {
127 " # Comment for your thoughts\n"
129 "BUG [ Mac-10.8 Debug] Foo=Bar =Skip # Why not another comment?\n"
130 "BUG2 [Win-XP\tWin-Vista ] Cow.GoesMoo =\tTimeout\n\n").Parse();
131 EXPECT_TRUE(syntax_error_
.empty()) << syntax_error_
;
132 EXPECT_EQ(0u, data_errors_
.size());
134 ASSERT_EQ(2u, expectations_
.size());
135 EXPECT_EQ("Foo=Bar", expectations_
[0].test_name
);
136 EXPECT_EQ(test_expectations::RESULT_SKIP
, expectations_
[0].result
);
137 EXPECT_EQ(test_expectations::CONFIGURATION_DEBUG
,
138 expectations_
[0].configuration
);
140 ASSERT_EQ(1u, expectations_
[0].platforms
.size());
141 EXPECT_EQ("Mac", expectations_
[0].platforms
[0].name
);
142 EXPECT_EQ("10.8", expectations_
[0].platforms
[0].variant
);
144 EXPECT_EQ("Cow.GoesMoo", expectations_
[1].test_name
);
145 EXPECT_EQ(test_expectations::RESULT_TIMEOUT
, expectations_
[1].result
);
146 EXPECT_EQ(test_expectations::CONFIGURATION_UNSPECIFIED
,
147 expectations_
[1].configuration
);
149 ASSERT_EQ(2u, expectations_
[1].platforms
.size());
150 EXPECT_EQ("Win", expectations_
[1].platforms
[0].name
);
151 EXPECT_EQ("XP", expectations_
[1].platforms
[0].variant
);
152 EXPECT_EQ("Win", expectations_
[1].platforms
[0].name
);
153 EXPECT_EQ("Vista", expectations_
[1].platforms
[1].variant
);
156 TEST_F(TestExpectationParserTest
, WeirdSpaces
) {
157 Parser(this, " BUG [Linux] Weird = Skip ").Parse();
158 EXPECT_EQ(1u, expectations_
.size());
159 EXPECT_TRUE(syntax_error_
.empty());
160 EXPECT_EQ(0u, data_errors_
.size());
163 TEST_F(TestExpectationParserTest
, SyntaxErrors
) {
164 const char* const kErrors
[] = {
166 "Foo [Linux] # This is an illegal comment",
167 "Foo [Linux] Bar # Another illegal comment.",
168 "Foo [Linux] Bar = # Another illegal comment.",
169 "Foo[Linux]Bar=Failure",
170 "Foo\n[Linux] Bar = Failure",
171 "Foo [\nLinux] Bar = Failure",
172 "Foo [Linux\n] Bar = Failure",
173 "Foo [ Linux ] \n Bar = Failure",
174 "Foo [ Linux ] Bar =\nFailure",
175 "Foo [ Linux \n ] Bar =\nFailure",
178 for (size_t i
= 0; i
< arraysize(kErrors
); ++i
) {
179 Parser(this, kErrors
[i
]).Parse();
180 EXPECT_FALSE(syntax_error_
.empty())
181 << "Should have error for #" << i
<< ": " << kErrors
[i
];
182 syntax_error_
.clear();
186 TEST_F(TestExpectationParserTest
, DataErrors
) {
187 const char* const kOneError
[] = {
188 "http://crbug.com/1234 [MagicBrowzR] BadModifier = Timeout",
189 "________ [Linux] BadResult = WhatNow",
190 "http://wkb.ug/1234 [Debug Release Win-7] MultipleConfigs = Skip",
193 for (size_t i
= 0; i
< arraysize(kOneError
); ++i
) {
194 Parser(this, kOneError
[i
]).Parse();
195 EXPECT_EQ(1u, data_errors_
.size()) << kOneError
[i
];
196 data_errors_
.clear();
199 const char* const kTwoErrors
[] = {
200 ". [Mac-TurningIntoiOS] BadModifierVariant.BadResult = Foobar",
201 "1234 [ Debug Release OS/2 ] MultipleConfigs.BadModifier = Pass",
204 for (size_t i
= 0; i
< arraysize(kTwoErrors
); ++i
) {
205 Parser(this, kTwoErrors
[i
]).Parse();
206 EXPECT_EQ(2u, data_errors_
.size()) << kTwoErrors
[i
];
207 data_errors_
.clear();