test that runs simple plan
authorEvan Martin <martine@danga.com>
Thu, 11 Nov 2010 07:05:22 +0000 (23:05 -0800)
committerEvan Martin <martine@danga.com>
Thu, 11 Nov 2010 07:05:22 +0000 (23:05 -0800)
ninja_test.cc

index c9cde761ebb69310d3b37413e11791b781ec3e95..d110777a7644e57be0dd7b9ce0a1028f05ffe188 100644 (file)
@@ -80,6 +80,45 @@ struct StateTestWithBuiltinRules : public testing::Test {
   State state_;
 };
 
+// Though Plan doesn't use State, it's useful to have one around
+// to create Nodes and Edges.
+struct PlanTest : public StateTestWithBuiltinRules {
+  Plan plan_;
+};
+
+TEST_F(PlanTest, Basic) {
+  AssertParse(&state_,
+"build out: cat mid\n"
+"build mid: cat in\n");
+  GetNode("in")->MarkDependentsDirty();
+  string err;
+  EXPECT_TRUE(plan_.AddTarget(GetNode("out"), &err));
+  ASSERT_EQ("", err);
+  ASSERT_TRUE(plan_.more_to_do());
+
+  Edge* edge = plan_.FindWork();
+  ASSERT_TRUE(edge);
+  ASSERT_EQ("in",  edge->inputs_[0]->file_->path_);
+  ASSERT_EQ("mid", edge->outputs_[0]->file_->path_);
+
+  ASSERT_FALSE(plan_.FindWork());
+
+  GetNode("mid")->dirty_ = false;
+  plan_.EdgeFinished(edge);
+
+  edge = plan_.FindWork();
+  ASSERT_TRUE(edge);
+  ASSERT_EQ("mid", edge->inputs_[0]->file_->path_);
+  ASSERT_EQ("out", edge->outputs_[0]->file_->path_);
+
+  GetNode("out")->dirty_ = false;
+  plan_.EdgeFinished(edge);
+
+  ASSERT_FALSE(plan_.more_to_do());
+  edge = plan_.FindWork();
+  ASSERT_EQ(NULL, edge);
+}
+
 struct BuildTest : public StateTestWithBuiltinRules,
                    public Shell,
                    public DiskInterface {