Ninja
clparser_test.cc
Go to the documentation of this file.
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14 
15 #include "clparser.h"
16 
17 #include "test.h"
18 #include "util.h"
19 
20 using namespace std;
21 
22 TEST(CLParserTest, ShowIncludes) {
24 
25  ASSERT_EQ("", CLParser::FilterShowIncludes("Sample compiler output", ""));
26  ASSERT_EQ("c:\\Some Files\\foobar.h",
27  CLParser::FilterShowIncludes("Note: including file: "
28  "c:\\Some Files\\foobar.h", ""));
29  ASSERT_EQ("c:\\initspaces.h",
30  CLParser::FilterShowIncludes("Note: including file: "
31  "c:\\initspaces.h", ""));
32  ASSERT_EQ("c:\\initspaces.h",
33  CLParser::FilterShowIncludes("Non-default prefix: inc file: "
34  "c:\\initspaces.h",
35  "Non-default prefix: inc file:"));
36 }
37 
38 TEST(CLParserTest, FilterInputFilename) {
43 
45  "src\\cl_helper.cc(166) : fatal error C1075: end "
46  "of file found ..."));
47 }
48 
49 TEST(CLParserTest, ParseSimple) {
50  CLParser parser;
51  string output, err;
52  ASSERT_TRUE(parser.Parse(
53  "foo\r\n"
54  "Note: inc file prefix: foo.h\r\n"
55  "bar\r\n",
56  "Note: inc file prefix:", &output, &err));
57 
58  ASSERT_EQ("foo\nbar\n", output);
59  ASSERT_EQ(1u, parser.includes_.size());
60  ASSERT_EQ("foo.h", *parser.includes_.begin());
61 }
62 
63 TEST(CLParserTest, ParseFilenameFilter) {
64  CLParser parser;
65  string output, err;
66  ASSERT_TRUE(parser.Parse(
67  "foo.cc\r\n"
68  "cl: warning\r\n",
69  "", &output, &err));
70  ASSERT_EQ("cl: warning\n", output);
71 }
72 
73 TEST(CLParserTest, ParseSystemInclude) {
74  CLParser parser;
75  string output, err;
76  ASSERT_TRUE(parser.Parse(
77  "Note: including file: c:\\Program Files\\foo.h\r\n"
78  "Note: including file: d:\\Microsoft Visual Studio\\bar.h\r\n"
79  "Note: including file: path.h\r\n",
80  "", &output, &err));
81  // We should have dropped the first two includes because they look like
82  // system headers.
83  ASSERT_EQ("", output);
84  ASSERT_EQ(1u, parser.includes_.size());
85  ASSERT_EQ("path.h", *parser.includes_.begin());
86 }
87 
88 TEST(CLParserTest, DuplicatedHeader) {
89  CLParser parser;
90  string output, err;
91  ASSERT_TRUE(parser.Parse(
92  "Note: including file: foo.h\r\n"
93  "Note: including file: bar.h\r\n"
94  "Note: including file: foo.h\r\n",
95  "", &output, &err));
96  // We should have dropped one copy of foo.h.
97  ASSERT_EQ("", output);
98  ASSERT_EQ(2u, parser.includes_.size());
99 }
100 
101 TEST(CLParserTest, DuplicatedHeaderPathConverted) {
102  CLParser parser;
103  string output, err;
104 
105  // This isn't inline in the Parse() call below because the #ifdef in
106  // a macro expansion would confuse MSVC2013's preprocessor.
107  const char kInput[] =
108  "Note: including file: sub/./foo.h\r\n"
109  "Note: including file: bar.h\r\n"
110 #ifdef _WIN32
111  "Note: including file: sub\\foo.h\r\n";
112 #else
113  "Note: including file: sub/foo.h\r\n";
114 #endif
115  ASSERT_TRUE(parser.Parse(kInput, "", &output, &err));
116  // We should have dropped one copy of foo.h.
117  ASSERT_EQ("", output);
118  ASSERT_EQ(2u, parser.includes_.size());
119 }
std::set< std::string > includes_
Definition: clparser.h:48
#define ASSERT_FALSE(a)
Definition: test.h:95
TEST(CLParserTest, ShowIncludes)
#define ASSERT_EQ(a, b)
Definition: test.h:81
static bool FilterInputFilename(std::string line)
Parse a line of cl.exe output and return true if it looks like it&#39;s printing an input filename...
Definition: clparser.cc:69
Visual Studio&#39;s cl.exe requires some massaging to work with Ninja; for example, it emits include info...
Definition: clparser.h:25
bool Parse(const std::string &output, const std::string &deps_prefix, std::string *filtered_output, std::string *err)
Parse the full output of cl, filling filtered_output with the text that should be printed (if any)...
Definition: clparser.cc:79
#define ASSERT_TRUE(a)
Definition: test.h:93
static std::string FilterShowIncludes(const std::string &line, const std::string &deps_prefix)
Parse a line of cl.exe output and extract /showIncludes info.
Definition: clparser.cc:44