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 std::string& path,
const std::string& contents);
147 virtual TimeStamp Stat(
const std::string& path, std::string* err)
const;
148 virtual bool WriteFile(
const std::string& path,
const std::string& contents);
149 virtual bool MakeDir(
const std::string& path);
150 virtual Status ReadFile(
const std::string& path, std::string* contents,
152 virtual int RemoveFile(
const std::string& path);
185 #endif // NINJA_TEST_H_
An implementation of DiskInterface that uses an in-memory representation of disk state.
virtual TimeStamp Stat(const std::string &path, std::string *err) const
stat() a file, returning the mtime, or 0 if missing and -1 on other errors.
void VerifyGraph(const State &state)
int Tick()
Tick "time" forwards; subsequent file operations will be newer than previous ones.
std::set< std::string > files_created_
std::vector< std::string > files_read_
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.
void Create(const std::string &path, const std::string &contents)
"Create" a file with contents.
Interface for accessing the disk.
int now_
A simple fake timestamp for file operations.
StateTestWithBuiltinRules()
void CreateAndEnter(const std::string &name)
Create a temporary directory and chdir into it.
Node * GetNode(const std::string &path)
Short way to get a Node by its path from state_.
virtual bool WriteFile(const std::string &path, const std::string &contents)
Create a file, with the specified name and contents Returns true on success, false on failure...
std::map< std::string, Entry > FileMap
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
std::set< std::string > files_removed_
std::string temp_dir_name_
The subdirectory name for our dir, or empty if it hasn't been set up.
virtual int RemoveFile(const std::string &path)
Remove the file named path.
std::string start_dir_
The temp directory containing our dir.
virtual bool MakeDir(const std::string &path)
Create a directory, returning false on failure.
void AddAssertionFailure()
std::vector< std::string > directories_made_
Status
Result of ReadFile.
virtual Status ReadFile(const std::string &path, std::string *contents, std::string *err)
Read and store in given string.
bool Check(bool condition, const char *file, int line, const char *error)
void Cleanup()
Clean up the temporary directory.
int AssertionFailures() const
An entry for a single in-memory file.
Global state (file status) for a single run.
unsigned long long uint64_t
void RegisterTest(testing::Test *(*)(), const char *)