17 #include <gtest/gtest.h>
22 TEST(CLParserTest, ShowIncludes) {
26 ASSERT_EQ(
"c:\\Some Files\\foobar.h",
28 "c:\\Some Files\\foobar.h",
""));
29 ASSERT_EQ(
"c:\\initspaces.h",
31 "c:\\initspaces.h",
""));
32 ASSERT_EQ(
"c:\\initspaces.h",
35 "Non-default prefix: inc file:"));
38 TEST(CLParserTest, FilterInputFilename) {
45 "src\\cl_helper.cc(166) : fatal error C1075: end "
46 "of file found ..."));
49 TEST(CLParserTest, ParseSimple) {
51 string output = parser.
Parse(
53 "Note: inc file prefix: foo.h\r\n"
55 "Note: inc file prefix:");
57 ASSERT_EQ(
"foo\nbar\n", output);
59 ASSERT_EQ(
"foo.h", *parser.
includes_.begin());
62 TEST(CLParserTest, ParseFilenameFilter) {
64 string output = parser.
Parse(
68 ASSERT_EQ(
"cl: warning\n", output);
71 TEST(CLParserTest, ParseSystemInclude) {
73 string output = parser.
Parse(
74 "Note: including file: c:\\Program Files\\foo.h\r\n"
75 "Note: including file: d:\\Microsoft Visual Studio\\bar.h\r\n"
76 "Note: including file: path.h\r\n",
80 ASSERT_EQ(
"", output);
82 ASSERT_EQ(
"path.h", *parser.
includes_.begin());
85 TEST(CLParserTest, DuplicatedHeader) {
87 string output = parser.
Parse(
88 "Note: including file: foo.h\r\n"
89 "Note: including file: bar.h\r\n"
90 "Note: including file: foo.h\r\n",
93 ASSERT_EQ(
"", output);
97 TEST(CLParserTest, DuplicatedHeaderPathConverted) {
99 string output = parser.
Parse(
100 "Note: including file: sub/foo.h\r\n"
101 "Note: including file: bar.h\r\n"
102 "Note: including file: sub\\foo.h\r\n",
105 ASSERT_EQ(
"", output);
109 TEST(CLParserTest, SpacesInFilename) {
110 ASSERT_EQ(
"sub\\some\\ sdk\\foo.h",
114 TEST(MSVCHelperTest, EnvBlock) {
115 char env_block[] =
"foo=bar\0";
119 cl.
Run(
"cmd /c \"echo foo is %foo%", &output);
120 ASSERT_EQ(
"foo is bar\r\n", output);
123 TEST(MSVCHelperTest, NoReadOfStderr) {
126 cl.
Run(
"cmd /c \"echo to stdout&& echo to stderr 1>&2", &output);
127 ASSERT_EQ(
"to stdout\r\n", output);
static bool FilterInputFilename(string line)
Parse a line of cl.exe output and return true if it looks like it's printing an input filename...
static string FilterShowIncludes(const string &line, const string &deps_prefix)
Parse a line of cl.exe output and extract /showIncludes info.
int Run(const string &command, string *output)
Start a process and gather its raw output.
TEST(CLParserTest, ShowIncludes)
Visual Studio's cl.exe requires some massaging to work with Ninja; for example, it emits include info...
string Parse(const string &output, const string &deps_prefix)
Parse the full output of cl, returning the output (if any) that should printed.
Wraps a synchronous execution of a CL subprocess.
string EscapeForDepfile(const string &path)
void SetEnvBlock(void *env_block)
Set the environment block (as suitable for CreateProcess) to be used by Run().