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 struct GraphTest : public StateTestWithBuiltinRules {
20 VirtualFileSystem fs_;
23 TEST_F(GraphTest, MissingImplicit) {
24 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
25 "build out: cat in | implicit\n"));
26 fs_.Create("in", 1, "");
27 fs_.Create("out", 1, "");
29 Edge* edge = GetNode("out")->in_edge_;
31 EXPECT_TRUE(edge->RecomputeDirty(&state_, &fs_, &err));
34 // A missing implicit dep does not make the output dirty.
35 EXPECT_FALSE(GetNode("out")->dirty_);
38 TEST_F(GraphTest, FunkyMakefilePath) {
39 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
42 " command = cat $in > $out\n"
43 "build out.o: catdep foo.cc\n"));
44 fs_.Create("implicit.h", 2, "");
45 fs_.Create("foo.cc", 1, "");
46 fs_.Create("out.o.d", 1, "out.o: ./foo/../implicit.h\n");
47 fs_.Create("out.o", 1, "");
49 Edge* edge = GetNode("out.o")->in_edge_;
51 EXPECT_TRUE(edge->RecomputeDirty(&state_, &fs_, &err));
54 // implicit.h has changed, though our depfile refers to it with a
55 // non-canonical path; we should still find it.
56 EXPECT_TRUE(GetNode("out.o")->dirty_);
59 TEST_F(GraphTest, ExplicitImplicit) {
60 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
63 " command = cat $in > $out\n"
64 "build implicit.h: cat data\n"
65 "build out.o: catdep foo.cc || implicit.h\n"));
66 fs_.Create("data", 2, "");
67 fs_.Create("implicit.h", 1, "");
68 fs_.Create("foo.cc", 1, "");
69 fs_.Create("out.o.d", 1, "out.o: implicit.h\n");
70 fs_.Create("out.o", 1, "");
72 Edge* edge = GetNode("out.o")->in_edge_;
74 EXPECT_TRUE(edge->RecomputeDirty(&state_, &fs_, &err));
77 // We have both an implicit and an explicit dep on implicit.h.
78 // The implicit dep should "win" (in the sense that it should cause
79 // the output to be dirty).
80 EXPECT_TRUE(GetNode("out.o")->dirty_);
83 TEST_F(GraphTest, PathWithCurrentDirectory) {
84 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
87 " command = cat $in > $out\n"
88 "build ./out.o: catdep ./foo.cc\n"));
89 fs_.Create("foo.cc", 1, "");
90 fs_.Create("out.o.d", 1, "out.o: foo.cc\n");
91 fs_.Create("out.o", 1, "");
93 Edge* edge = GetNode("out.o")->in_edge_;
95 EXPECT_TRUE(edge->RecomputeDirty(&state_, &fs_, &err));
98 EXPECT_FALSE(GetNode("out.o")->dirty_);
101 TEST_F(GraphTest, RootNodes) {
102 ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
103 "build out1: cat in1\n"
104 "build mid1: cat in1\n"
105 "build out2: cat mid1\n"
106 "build out3 out4: cat mid1\n"));
109 vector<Node*> root_nodes = state_.RootNodes(&err);
110 EXPECT_EQ(4, root_nodes.size());
111 for (size_t i = 0; i < root_nodes.size(); ++i) {
112 string name = root_nodes[i]->file_->path_;
113 EXPECT_EQ("out", name.substr(0, 3));