Ninja
msvc_helper_test.cc
Go to the documentation of this file.
00001 // Copyright 2011 Google Inc. All Rights Reserved.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //     http://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #include "msvc_helper.h"
00016 
00017 #include <gtest/gtest.h>
00018 
00019 #include "test.h"
00020 #include "util.h"
00021 
00022 TEST(CLParserTest, ShowIncludes) {
00023   ASSERT_EQ("", CLParser::FilterShowIncludes(""));
00024 
00025   ASSERT_EQ("", CLParser::FilterShowIncludes("Sample compiler output"));
00026   ASSERT_EQ("c:\\Some Files\\foobar.h",
00027             CLParser::FilterShowIncludes("Note: including file: "
00028                                          "c:\\Some Files\\foobar.h"));
00029   ASSERT_EQ("c:\\initspaces.h",
00030             CLParser::FilterShowIncludes("Note: including file:    "
00031                                          "c:\\initspaces.h"));
00032 }
00033 
00034 TEST(CLParserTest, FilterInputFilename) {
00035   ASSERT_TRUE(CLParser::FilterInputFilename("foobar.cc"));
00036   ASSERT_TRUE(CLParser::FilterInputFilename("foo bar.cc"));
00037   ASSERT_TRUE(CLParser::FilterInputFilename("baz.c"));
00038   ASSERT_TRUE(CLParser::FilterInputFilename("FOOBAR.CC"));
00039 
00040   ASSERT_FALSE(CLParser::FilterInputFilename(
00041                    "src\\cl_helper.cc(166) : fatal error C1075: end "
00042                    "of file found ..."));
00043 }
00044 
00045 TEST(CLParserTest, ParseSimple) {
00046   CLParser parser;
00047   string output = parser.Parse(
00048       "foo\r\n"
00049       "Note: including file:  foo.h\r\n"
00050       "bar\r\n");
00051 
00052   ASSERT_EQ("foo\nbar\n", output);
00053   ASSERT_EQ(1u, parser.includes_.size());
00054   ASSERT_EQ("foo.h", *parser.includes_.begin());
00055 }
00056 
00057 TEST(CLParserTest, ParseFilenameFilter) {
00058   CLParser parser;
00059   string output = parser.Parse(
00060       "foo.cc\r\n"
00061       "cl: warning\r\n");
00062   ASSERT_EQ("cl: warning\n", output);
00063 }
00064 
00065 TEST(CLParserTest, ParseSystemInclude) {
00066   CLParser parser;
00067   string output = parser.Parse(
00068       "Note: including file: c:\\Program Files\\foo.h\r\n"
00069       "Note: including file: d:\\Microsoft Visual Studio\\bar.h\r\n"
00070       "Note: including file: path.h\r\n");
00071   // We should have dropped the first two includes because they look like
00072   // system headers.
00073   ASSERT_EQ("", output);
00074   ASSERT_EQ(1u, parser.includes_.size());
00075   ASSERT_EQ("path.h", *parser.includes_.begin());
00076 }
00077 
00078 TEST(CLParserTest, DuplicatedHeader) {
00079   CLParser parser;
00080   string output = parser.Parse(
00081       "Note: including file: foo.h\r\n"
00082       "Note: including file: bar.h\r\n"
00083       "Note: including file: foo.h\r\n");
00084   // We should have dropped one copy of foo.h.
00085   ASSERT_EQ("", output);
00086   ASSERT_EQ(2u, parser.includes_.size());
00087 }
00088 
00089 TEST(CLParserTest, DuplicatedHeaderPathConverted) {
00090   CLParser parser;
00091   string output = parser.Parse(
00092       "Note: including file: sub/foo.h\r\n"
00093       "Note: including file: bar.h\r\n"
00094       "Note: including file: sub\\foo.h\r\n");
00095   // We should have dropped one copy of foo.h.
00096   ASSERT_EQ("", output);
00097   ASSERT_EQ(2u, parser.includes_.size());
00098 }
00099 
00100 TEST(CLParserTest, SpacesInFilename) {
00101   ASSERT_EQ("sub\\some\\ sdk\\foo.h",
00102             EscapeForDepfile("sub\\some sdk\\foo.h"));
00103 }
00104 
00105 TEST(MSVCHelperTest, EnvBlock) {
00106   char env_block[] = "foo=bar\0";
00107   CLWrapper cl;
00108   cl.SetEnvBlock(env_block);
00109   string output;
00110   cl.Run("cmd /c \"echo foo is %foo%", &output);
00111   ASSERT_EQ("foo is bar\r\n", output);
00112 }