25 #include <sys/types.h> 34 virtual void SetUp() {
44 TEST_F(BuildLogTest, WriteRead) {
46 "build out: cat mid\n" 47 "build mid: cat in\n");
72 TEST_F(BuildLogTest, FirstWriteAddsSignature) {
73 const char kExpectedVersion[] =
"# ninja log vX\n";
74 const size_t kVersionPos = strlen(kExpectedVersion) - 2;
85 if (contents.size() >= kVersionPos)
86 contents[kVersionPos] =
'X';
97 if (contents.size() >= kVersionPos)
98 contents[kVersionPos] =
'X';
102 TEST_F(BuildLogTest, DoubleEntry) {
104 fprintf(f,
"# ninja log v4\n");
105 fprintf(f,
"0\t1\t2\tout\tcommand abc\n");
106 fprintf(f,
"3\t4\t5\tout\tcommand def\n");
121 "build out: cat mid\n" 122 "build mid: cat in\n");
140 for (off_t size = statbuf.st_size; size > 0; --size) {
157 TEST_F(BuildLogTest, ObsoleteOldVersion) {
159 fprintf(f,
"# ninja log v3\n");
160 fprintf(f,
"123 456 0 out command\n");
166 ASSERT_NE(err.find(
"version"), string::npos);
169 TEST_F(BuildLogTest, SpacesInOutputV4) {
171 fprintf(f,
"# ninja log v4\n");
172 fprintf(f,
"123\t456\t456\tout with space\tcommand\n");
188 TEST_F(BuildLogTest, DuplicateVersionHeader) {
193 fprintf(f,
"# ninja log v4\n");
194 fprintf(f,
"123\t456\t456\tout\tcommand\n");
195 fprintf(f,
"# ninja log v4\n");
196 fprintf(f,
"456\t789\t789\tout2\tcommand2\n");
219 TEST_F(BuildLogTest, VeryLongInputLine) {
223 fprintf(f,
"# ninja log v4\n");
224 fprintf(f,
"123\t456\t456\tout\tcommand start");
225 for (
size_t i = 0; i < (512 << 10) / strlen(
" more_command"); ++i)
226 fputs(
" more_command", f);
228 fprintf(f,
"456\t789\t789\tout2\tcommand2\n");
247 TEST_F(BuildLogTest, MultiTargetEdge) {
249 "build out out.d: cat\n");
267 struct BuildLogRecompactTest :
public BuildLogTest {
268 virtual bool IsPathDead(
StringPiece s)
const {
return s ==
"out2"; }
271 TEST_F(BuildLogRecompactTest, Recompact) {
273 "build out: cat in\n" 274 "build out2: cat in\n");
282 for (
int i = 0; i < 200; ++i)
const Entries & entries() const
void AssertParse(State *state, const char *input, ManifestParserOptions opts)
bool RecordCommand(Edge *edge, int start_time, int end_time, TimeStamp mtime=0)
StringPiece represents a slice of a string whose memory is managed externally.
Store a log of every command ran for every build.
A base test fixture that includes a State object with a builtin "cat" rule.
virtual bool IsPathDead(StringPiece s) const =0
Return if a given output is no longer part of the build manifest.
bool OpenForWrite(const string &path, const BuildLogUser &user, string *err)
const char kTestFilename[]
int ReadFile(const string &path, string *contents, string *err)
Read a file to a string (in text mode: with CRLF conversion on Windows).
bool Truncate(const string &path, size_t size, string *err)
Truncates a file to the given size.
LogEntry * LookupByOutput(const string &path)
Lookup a previously-run command by its output path.
#define ASSERT_NO_FATAL_FAILURE(a)
bool Load(const string &path, string *err)
Load the on-disk log.
void AssertHash(const char *expected, uint64_t actual)
Can answer questions about the manifest for the BuildLog.