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.
19 TEST(CanonicalizePath, PathSamples) {
20 string path = "foo.h";
22 EXPECT_TRUE(CanonicalizePath(&path, &err));
24 EXPECT_EQ("foo.h", path);
26 path = "./foo.h"; err = "";
27 EXPECT_TRUE(CanonicalizePath(&path, &err));
29 EXPECT_EQ("foo.h", path);
31 path = "./foo/./bar.h"; err = "";
32 EXPECT_TRUE(CanonicalizePath(&path, &err));
34 EXPECT_EQ("foo/bar.h", path);
36 path = "./x/foo/../bar.h"; err = "";
37 EXPECT_TRUE(CanonicalizePath(&path, &err));
39 EXPECT_EQ("x/bar.h", path);
41 path = "./x/foo/../../bar.h"; err = "";
42 EXPECT_TRUE(CanonicalizePath(&path, &err));
44 EXPECT_EQ("bar.h", path);
46 path = "./x/../foo/../../bar.h"; err = "";
47 EXPECT_FALSE(CanonicalizePath(&path, &err));
48 EXPECT_EQ("can't canonicalize path './x/../foo/../../bar.h' that reaches "
49 "above its directory", err);
52 struct GraphTest : public StateTestWithBuiltinRules {
53 VirtualFileSystem fs_;
56 TEST_F(GraphTest, MissingImplicit) {
57 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
58 "build out: cat in | implicit\n"));
59 fs_.Create("in", 1, "");
60 fs_.Create("out", 1, "");
62 Edge* edge = GetNode("out")->in_edge_;
64 EXPECT_TRUE(edge->RecomputeDirty(&state_, &fs_, &err));
67 // A missing implicit dep does not make the output dirty.
68 EXPECT_FALSE(GetNode("out")->dirty_);
71 TEST_F(GraphTest, FunkyMakefilePath) {
72 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
75 " command = cat $in > $out\n"
76 "build out.o: catdep foo.cc\n"));
77 fs_.Create("implicit.h", 2, "");
78 fs_.Create("foo.cc", 1, "");
79 fs_.Create("out.o.d", 1, "out.o: ./foo/../implicit.h\n");
80 fs_.Create("out.o", 1, "");
82 Edge* edge = GetNode("out.o")->in_edge_;
84 EXPECT_TRUE(edge->RecomputeDirty(&state_, &fs_, &err));
87 // implicit.h has changed, though our depfile refers to it with a
88 // non-canonical path; we should still find it.
89 EXPECT_TRUE(GetNode("out.o")->dirty_);