38 virtual void Run() = 0;
43 bool Check(
bool condition,
const char* file,
int line,
const char* error);
50 #define TEST_F_(x, y, name) \ 51 struct y : public x { \ 52 static testing::Test* Create() { return g_current_test = new y; } \ 55 struct Register##y { \ 56 Register##y() { RegisterTest(y::Create, name); } \ 58 Register##y g_register_##y; \ 61 #define TEST_F(x, y) TEST_F_(x, x##y, #x "." #y) 62 #define TEST(x, y) TEST_F_(testing::Test, x##y, #x "." #y) 64 #define EXPECT_EQ(a, b) \ 65 g_current_test->Check(a == b, __FILE__, __LINE__, #a " == " #b) 66 #define EXPECT_NE(a, b) \ 67 g_current_test->Check(a != b, __FILE__, __LINE__, #a " != " #b) 68 #define EXPECT_GT(a, b) \ 69 g_current_test->Check(a > b, __FILE__, __LINE__, #a " > " #b) 70 #define EXPECT_LT(a, b) \ 71 g_current_test->Check(a < b, __FILE__, __LINE__, #a " < " #b) 72 #define EXPECT_GE(a, b) \ 73 g_current_test->Check(a >= b, __FILE__, __LINE__, #a " >= " #b) 74 #define EXPECT_LE(a, b) \ 75 g_current_test->Check(a <= b, __FILE__, __LINE__, #a " <= " #b) 76 #define EXPECT_TRUE(a) \ 77 g_current_test->Check(static_cast<bool>(a), __FILE__, __LINE__, #a) 78 #define EXPECT_FALSE(a) \ 79 g_current_test->Check(!static_cast<bool>(a), __FILE__, __LINE__, #a) 81 #define ASSERT_EQ(a, b) \ 82 if (!EXPECT_EQ(a, b)) { g_current_test->AddAssertionFailure(); return; } 83 #define ASSERT_NE(a, b) \ 84 if (!EXPECT_NE(a, b)) { g_current_test->AddAssertionFailure(); return; } 85 #define ASSERT_GT(a, b) \ 86 if (!EXPECT_GT(a, b)) { g_current_test->AddAssertionFailure(); return; } 87 #define ASSERT_LT(a, b) \ 88 if (!EXPECT_LT(a, b)) { g_current_test->AddAssertionFailure(); return; } 89 #define ASSERT_GE(a, b) \ 90 if (!EXPECT_GE(a, b)) { g_current_test->AddAssertionFailure(); return; } 91 #define ASSERT_LE(a, b) \ 92 if (!EXPECT_LE(a, b)) { g_current_test->AddAssertionFailure(); return; } 93 #define ASSERT_TRUE(a) \ 94 if (!EXPECT_TRUE(a)) { g_current_test->AddAssertionFailure(); return; } 95 #define ASSERT_FALSE(a) \ 96 if (!EXPECT_FALSE(a)) { g_current_test->AddAssertionFailure(); return; } 97 #define ASSERT_NO_FATAL_FAILURE(a) \ 99 int fail_count = g_current_test->AssertionFailures(); \ 101 if (fail_count != g_current_test->AssertionFailures()) { \ 102 g_current_test->AddAssertionFailure(); \ 138 void Create(
const string& path,
const string& contents);
147 virtual TimeStamp Stat(
const string& path,
string* err)
const;
148 virtual bool WriteFile(
const string& path,
const string& contents);
149 virtual bool MakeDir(
const string& path);
150 virtual Status ReadFile(
const string& path,
string* contents,
string* err);
184 #endif // NINJA_TEST_H_ map< string, Entry > FileMap
An implementation of DiskInterface that uses an in-memory representation of disk state.
void VerifyGraph(const State &state)
Node * GetNode(const string &path)
Short way to get a Node by its path from state_.
int Tick()
Tick "time" forwards; subsequent file operations will be newer than previous ones.
void AssertParse(State *state, const char *input, ManifestParserOptions=ManifestParserOptions())
Information about a node in the dependency graph: the file, whether it's dirty, mtime, etc.
set< string > files_removed_
virtual bool WriteFile(const string &path, const string &contents)
Create a file, with the specified name and contents Returns true on success, false on failure...
Interface for accessing the disk.
int now_
A simple fake timestamp for file operations.
StateTestWithBuiltinRules()
void Create(const string &path, const string &contents)
"Create" a file with contents.
set< string > files_created_
vector< string > directories_made_
A base test fixture that includes a State object with a builtin "cat" rule.
void AssertHash(const char *expected, uint64_t actual)
void AddCatRule(State *state)
Add a "cat" rule to state.
testing::Test * g_current_test
string start_dir_
The temp directory containing our dir.
void AddAssertionFailure()
virtual bool MakeDir(const string &path)
Create a directory, returning false on failure.
Status
Result of ReadFile.
bool Check(bool condition, const char *file, int line, const char *error)
void Cleanup()
Clean up the temporary directory.
int AssertionFailures() const
virtual TimeStamp Stat(const string &path, string *err) const
stat() a file, returning the mtime, or 0 if missing and -1 on other errors.
An entry for a single in-memory file.
virtual Status ReadFile(const string &path, string *contents, string *err)
Read and store in given string.
void CreateAndEnter(const string &name)
Create a temporary directory and chdir into it.
Global state (file status) for a single run.
vector< string > files_read_
virtual int RemoveFile(const string &path)
Remove the file named path.
unsigned long long uint64_t
string temp_dir_name_
The subdirectory name for our dir, or empty if it hasn't been set up.
void RegisterTest(testing::Test *(*)(), const char *)