summaryrefslogtreecommitdiffstats
path: root/src/disk_interface_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/disk_interface_test.cc')
-rw-r--r--src/disk_interface_test.cc99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/disk_interface_test.cc b/src/disk_interface_test.cc
index 672d57c..107726b 100644
--- a/src/disk_interface_test.cc
+++ b/src/disk_interface_test.cc
@@ -20,6 +20,8 @@
#endif
#include "disk_interface.h"
+#include "graph.h"
+#include "test.h"
using namespace std;
@@ -157,4 +159,101 @@ TEST_F(DiskInterfaceTest, RemoveFile) {
EXPECT_EQ(1, disk_.RemoveFile("does not exist"));
}
+struct StatTest : public StateTestWithBuiltinRules,
+ public DiskInterface {
+ // DiskInterface implementation.
+ virtual int Stat(const string& path);
+ virtual bool MakeDir(const string& path) {
+ assert(false);
+ return false;
+ }
+ virtual string ReadFile(const string& path, string* err) {
+ assert(false);
+ return "";
+ }
+ virtual int RemoveFile(const string& path) {
+ assert(false);
+ return 0;
+ }
+
+ map<string, time_t> mtimes_;
+ vector<string> stats_;
+};
+
+int StatTest::Stat(const string& path) {
+ stats_.push_back(path);
+ map<string, time_t>::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(1u, stats_.size());
+ Edge* edge = out->in_edge_;
+ edge->RecomputeDirty(NULL, this, NULL);
+ ASSERT_EQ(2u, stats_.size());
+ ASSERT_EQ("out", stats_[0]);
+ ASSERT_EQ("in", stats_[1]);
+}
+
+TEST_F(StatTest, TwoStep) {
+ ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
+"build out: cat mid\n"
+"build mid: cat in\n"));
+
+ Node* out = GetNode("out");
+ out->file_->Stat(this);
+ ASSERT_EQ(1u, stats_.size());
+ Edge* edge = out->in_edge_;
+ edge->RecomputeDirty(NULL, this, NULL);
+ ASSERT_EQ(3u, stats_.size());
+ ASSERT_EQ("out", stats_[0]);
+ ASSERT_TRUE(GetNode("out")->dirty_);
+ ASSERT_EQ("mid", stats_[1]);
+ ASSERT_TRUE(GetNode("mid")->dirty_);
+ ASSERT_EQ("in", stats_[2]);
+}
+
+TEST_F(StatTest, Tree) {
+ ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
+"build out: cat mid1 mid2\n"
+"build mid1: cat in11 in12\n"
+"build mid2: cat in21 in22\n"));
+
+ Node* out = GetNode("out");
+ out->file_->Stat(this);
+ ASSERT_EQ(1u, stats_.size());
+ Edge* edge = out->in_edge_;
+ edge->RecomputeDirty(NULL, this, NULL);
+ ASSERT_EQ(1u + 6u, stats_.size());
+ ASSERT_EQ("mid1", stats_[1]);
+ ASSERT_TRUE(GetNode("mid1")->dirty_);
+ ASSERT_EQ("in11", stats_[2]);
+}
+
+TEST_F(StatTest, Middle) {
+ ASSERT_NO_FATAL_FAILURE(AssertParse(&state_,
+"build out: cat mid\n"
+"build mid: cat in\n"));
+
+ mtimes_["in"] = 1;
+ mtimes_["mid"] = 0; // missing
+ mtimes_["out"] = 1;
+
+ Node* out = GetNode("out");
+ out->file_->Stat(this);
+ ASSERT_EQ(1u, stats_.size());
+ Edge* edge = out->in_edge_;
+ edge->RecomputeDirty(NULL, this, NULL);
+ ASSERT_FALSE(GetNode("in")->dirty_);
+ ASSERT_TRUE(GetNode("mid")->dirty_);
+ ASSERT_TRUE(GetNode("out")->dirty_);
+}
+
} // namespace