summaryrefslogtreecommitdiffstats
path: root/src/build_log_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/build_log_test.cc')
-rw-r--r--src/build_log_test.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/build_log_test.cc b/src/build_log_test.cc
index 9b729c7..08c3083 100644
--- a/src/build_log_test.cc
+++ b/src/build_log_test.cc
@@ -14,6 +14,7 @@
#include "build_log.h"
+#include "util.h"
#include "test.h"
#ifdef _WIN32
@@ -65,6 +66,36 @@ TEST_F(BuildLogTest, WriteRead) {
ASSERT_EQ("out", e1->output);
}
+TEST_F(BuildLogTest, FirstWriteAddsSignature) {
+ const char kExpectedVersion[] = "# ninja log vX\n";
+ const size_t kVersionPos = strlen(kExpectedVersion) - 2; // Points at 'X'.
+
+ BuildLog log;
+ string contents, err;
+
+ EXPECT_TRUE(log.OpenForWrite(kTestFilename, &err));
+ ASSERT_EQ("", err);
+ log.Close();
+
+ ASSERT_EQ(0, ReadFile(kTestFilename, &contents, &err));
+ ASSERT_EQ("", err);
+ if (contents.size() >= kVersionPos)
+ contents[kVersionPos] = 'X';
+ EXPECT_EQ(kExpectedVersion, contents);
+
+ // Opening the file anew shouldn't add a second version string.
+ EXPECT_TRUE(log.OpenForWrite(kTestFilename, &err));
+ ASSERT_EQ("", err);
+ log.Close();
+
+ contents.clear();
+ ASSERT_EQ(0, ReadFile(kTestFilename, &contents, &err));
+ ASSERT_EQ("", err);
+ if (contents.size() >= kVersionPos)
+ contents[kVersionPos] = 'X';
+ EXPECT_EQ(kExpectedVersion, contents);
+}
+
TEST_F(BuildLogTest, DoubleEntry) {
FILE* f = fopen(kTestFilename, "wb");
fprintf(f, "# ninja log v3\n");