From 900bf30f673db46c6d3c3e5f37c08ce89f3ca73c Mon Sep 17 00:00:00 2001 From: Evan Martin Date: Sat, 30 Oct 2010 12:43:23 -0700 Subject: [PATCH] make DiskInterface pure virtual --- ninja.h | 13 +++++++++---- ninja_jumble.cc | 6 +++--- ninja_test.cc | 10 +++++++++- parsers_test.cc | 13 +++++++++++++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/ninja.h b/ninja.h index 596112f..66aa807 100644 --- a/ninja.h +++ b/ninja.h @@ -13,16 +13,21 @@ using namespace std; struct DiskInterface { // stat() a file, returning the mtime, or 0 if missing and -1 on other errors. - virtual int Stat(const string& path); + virtual int Stat(const string& path) = 0; // Create a directory, returning false on failure. - virtual bool MakeDir(const string& path); + virtual bool MakeDir(const string& path) = 0; // Read a file to a string. Fill in |err| on error. - virtual string ReadFile(const string& path, string* err); + virtual string ReadFile(const string& path, string* err) = 0; // Create all the parent directories for path; like mkdir -p `basename path`. bool MakeDirs(const string& path); }; +struct RealDiskInterface : public DiskInterface { + virtual int Stat(const string& path); + virtual bool MakeDir(const string& path); + virtual string ReadFile(const string& path, string* err); +}; struct Node; struct FileStat { @@ -180,6 +185,6 @@ struct Builder { State* state_; Plan plan_; - DiskInterface default_disk_interface_; + RealDiskInterface default_disk_interface_; DiskInterface* disk_interface_; }; diff --git a/ninja_jumble.cc b/ninja_jumble.cc index 5462a5b..e9da25e 100644 --- a/ninja_jumble.cc +++ b/ninja_jumble.cc @@ -30,7 +30,7 @@ string ReadFile(const string& path, string* err) { return text; } -int DiskInterface::Stat(const string& path) { +int RealDiskInterface::Stat(const string& path) { struct stat st; if (stat(path.c_str(), &st) < 0) { if (errno == ENOENT) { @@ -69,11 +69,11 @@ bool DiskInterface::MakeDirs(const string& path) { return MakeDir(dir); } -string DiskInterface::ReadFile(const string& path, string* err) { +string RealDiskInterface::ReadFile(const string& path, string* err) { return ::ReadFile(path, err); } -bool DiskInterface::MakeDir(const string& path) { +bool RealDiskInterface::MakeDir(const string& path) { if (mkdir(path.c_str(), 0777) < 0) { fprintf(stderr, "mkdir(%s): %s\n", path.c_str(), strerror(errno)); return false; diff --git a/ninja_test.cc b/ninja_test.cc index 7d59be3..e9146ba 100644 --- a/ninja_test.cc +++ b/ninja_test.cc @@ -312,6 +312,14 @@ 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 ""; + } map mtimes_; vector stats_; @@ -413,7 +421,7 @@ public: string start_dir_; string temp_dir_name_; - DiskInterface disk_; + RealDiskInterface disk_; }; TEST_F(DiskInterfaceTest, Stat) { diff --git a/parsers_test.cc b/parsers_test.cc index 6f5a65c..fa1e74a 100644 --- a/parsers_test.cc +++ b/parsers_test.cc @@ -13,6 +13,19 @@ struct ParserTest : public testing::Test, ASSERT_EQ("", err); } + virtual int Stat(const string& path) { + assert(false); + return -1; + } + virtual bool MakeDir(const string& path) { + assert(false); + return false; + } + virtual string ReadFile(const string& path, string* err) { + assert(false); + return ""; + } + State state; }; -- 2.7.4