1 // Copyright 2011 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
20 TEST(CLParserTest, ShowIncludes) {
21 ASSERT_EQ("", CLParser::FilterShowIncludes("", ""));
23 ASSERT_EQ("", CLParser::FilterShowIncludes("Sample compiler output", ""));
24 ASSERT_EQ("c:\\Some Files\\foobar.h",
25 CLParser::FilterShowIncludes("Note: including file: "
26 "c:\\Some Files\\foobar.h", ""));
27 ASSERT_EQ("c:\\initspaces.h",
28 CLParser::FilterShowIncludes("Note: including file: "
29 "c:\\initspaces.h", ""));
30 ASSERT_EQ("c:\\initspaces.h",
31 CLParser::FilterShowIncludes("Non-default prefix: inc file: "
33 "Non-default prefix: inc file:"));
36 TEST(CLParserTest, FilterInputFilename) {
37 ASSERT_TRUE(CLParser::FilterInputFilename("foobar.cc"));
38 ASSERT_TRUE(CLParser::FilterInputFilename("foo bar.cc"));
39 ASSERT_TRUE(CLParser::FilterInputFilename("baz.c"));
40 ASSERT_TRUE(CLParser::FilterInputFilename("FOOBAR.CC"));
42 ASSERT_FALSE(CLParser::FilterInputFilename(
43 "src\\cl_helper.cc(166) : fatal error C1075: end "
44 "of file found ..."));
47 TEST(CLParserTest, ParseSimple) {
50 ASSERT_TRUE(parser.Parse(
52 "Note: inc file prefix: foo.h\r\n"
54 "Note: inc file prefix:", &output, &err));
56 ASSERT_EQ("foo\nbar\n", output);
57 ASSERT_EQ(1u, parser.includes_.size());
58 ASSERT_EQ("foo.h", *parser.includes_.begin());
61 TEST(CLParserTest, ParseFilenameFilter) {
64 ASSERT_TRUE(parser.Parse(
68 ASSERT_EQ("cl: warning\n", output);
71 TEST(CLParserTest, ParseSystemInclude) {
74 ASSERT_TRUE(parser.Parse(
75 "Note: including file: c:\\Program Files\\foo.h\r\n"
76 "Note: including file: d:\\Microsoft Visual Studio\\bar.h\r\n"
77 "Note: including file: path.h\r\n",
79 // We should have dropped the first two includes because they look like
81 ASSERT_EQ("", output);
82 ASSERT_EQ(1u, parser.includes_.size());
83 ASSERT_EQ("path.h", *parser.includes_.begin());
86 TEST(CLParserTest, DuplicatedHeader) {
89 ASSERT_TRUE(parser.Parse(
90 "Note: including file: foo.h\r\n"
91 "Note: including file: bar.h\r\n"
92 "Note: including file: foo.h\r\n",
94 // We should have dropped one copy of foo.h.
95 ASSERT_EQ("", output);
96 ASSERT_EQ(2u, parser.includes_.size());
99 TEST(CLParserTest, DuplicatedHeaderPathConverted) {
103 // This isn't inline in the Parse() call below because the #ifdef in
104 // a macro expansion would confuse MSVC2013's preprocessor.
105 const char kInput[] =
106 "Note: including file: sub/./foo.h\r\n"
107 "Note: including file: bar.h\r\n"
109 "Note: including file: sub\\foo.h\r\n";
111 "Note: including file: sub/foo.h\r\n";
113 ASSERT_TRUE(parser.Parse(kInput, "", &output, &err));
114 // We should have dropped one copy of foo.h.
115 ASSERT_EQ("", output);
116 ASSERT_EQ(2u, parser.includes_.size());