|
Ninja
|
00001 // Copyright 2011 Google Inc. All Rights Reserved. 00002 // 00003 // Licensed under the Apache License, Version 2.0 (the "License"); 00004 // you may not use this file except in compliance with the License. 00005 // You may obtain a copy of the License at 00006 // 00007 // http://www.apache.org/licenses/LICENSE-2.0 00008 // 00009 // Unless required by applicable law or agreed to in writing, software 00010 // distributed under the License is distributed on an "AS IS" BASIS, 00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 // See the License for the specific language governing permissions and 00013 // limitations under the License. 00014 00015 #ifndef NINJA_TEST_H_ 00016 #define NINJA_TEST_H_ 00017 00018 #include <gtest/gtest.h> 00019 00020 #include "disk_interface.h" 00021 #include "state.h" 00022 00023 // Support utilites for tests. 00024 00025 struct Node; 00026 00027 /// A base test fixture that includes a State object with a 00028 /// builtin "cat" rule. 00029 struct StateTestWithBuiltinRules : public testing::Test { 00030 StateTestWithBuiltinRules(); 00031 Node* GetNode(const string& path); 00032 00033 State state_; 00034 }; 00035 00036 void AssertParse(State* state, const char* input); 00037 00038 /// An implementation of DiskInterface that uses an in-memory representation 00039 /// of disk state. It also logs file accesses and directory creations 00040 /// so it can be used by tests to verify disk access patterns. 00041 struct VirtualFileSystem : public DiskInterface { 00042 /// "Create" a file with a given mtime and contents. 00043 void Create(const string& path, int time, const string& contents); 00044 00045 // DiskInterface 00046 virtual int Stat(const string& path); 00047 virtual bool MakeDir(const string& path); 00048 virtual string ReadFile(const string& path, string* err); 00049 virtual int RemoveFile(const string& path); 00050 00051 /// An entry for a single in-memory file. 00052 struct Entry { 00053 int mtime; 00054 string contents; 00055 }; 00056 00057 vector<string> directories_made_; 00058 vector<string> files_read_; 00059 typedef map<string, Entry> FileMap; 00060 FileMap files_; 00061 set<string> files_removed_; 00062 }; 00063 00064 #endif // NINJA_TEST_H_
1.7.5.1