From a01dd9d21b98f29d120d1ed138da4a4caf91c65f Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Wed, 20 Oct 2010 21:29:16 -0700 Subject: [PATCH] first stat test --- ninja.h | 2 +- ninja_test.cc | 45 ++++++++++++++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/ninja.h b/ninja.h index def68d9..a69b712 100644 --- a/ninja.h +++ b/ninja.h @@ -56,7 +56,7 @@ struct FileStat { } bool status_known() const { - return mtime_ == -1; + return mtime_ != -1; } string path_; diff --git a/ninja_test.cc b/ninja_test.cc index 5a8a893..c02ac73 100644 --- a/ninja_test.cc +++ b/ninja_test.cc @@ -133,18 +133,23 @@ struct StateTestWithBuiltinRules : public testing::Test { StateTestWithBuiltinRules() { AssertParse(&state_, "rule cat\n" -"command cat @in > $out\n" -"\n" -"build cat1: cat in1\n" -"build cat2: cat in1 in2\n" -"build cat12: cat cat1 cat2\n"); +"command cat @in > $out\n"); } + + Node* GetNode(const string& path) { + return state_.stat_cache()->GetFile(path)->node_; + } + State state_; }; struct BuildTest : public StateTestWithBuiltinRules, public Shell { BuildTest() : builder_(&state_), now_(1) { + AssertParse(&state_, +"build cat1: cat in1\n" +"build cat2: cat in1 in2\n" +"build cat12: cat cat1 cat2\n"); } void Dirty(const string& path); @@ -158,7 +163,7 @@ struct BuildTest : public StateTestWithBuiltinRules, }; void BuildTest::Dirty(const string& path) { - state_.stat_cache()->GetFile(path)->node_->MarkDirty(); + GetNode(path)->MarkDirty(); } bool BuildTest::RunCommand(Edge* edge) { @@ -260,6 +265,32 @@ TEST_F(BuildTest, Chain) { ASSERT_EQ(2, commands_ran_.size()); // 3->4, 4->5 } -typedef StateTestWithBuiltinRules StatTest; +struct StatTest : public StateTestWithBuiltinRules, + public StatHelper { + virtual int Stat(const string& path); + + map mtimes_; + vector stats_; +}; + +int StatTest::Stat(const string& path) { + stats_.push_back(path); + map::iterator i = mtimes_.find(path); + if (i == mtimes_.end()) + return 0; // File not found. + return i->second; +} + TEST_F(StatTest, Simple) { + ASSERT_NO_FATAL_FAILURE(AssertParse(&state_, +"build out: cat in\n")); + + Node* out = GetNode("out"); + out->file_->Stat(this); + ASSERT_EQ(1, stats_.size()); + Edge* edge = out->in_edge_; + edge->RecomputeDirty(this); + ASSERT_EQ(2, stats_.size()); + ASSERT_EQ("out", stats_[0]); + ASSERT_EQ("in", stats_[1]); } -- 2.7.4