Add a BuildLog test that checks that very long command liens don't crash.
authorNico Weber <nicolasweber@gmx.de>
Thu, 10 May 2012 03:25:48 +0000 (20:25 -0700)
committerNico Weber <nicolasweber@gmx.de>
Thu, 10 May 2012 03:25:48 +0000 (20:25 -0700)
src/build_log_test.cc

index 332a73edbc7c6ed3fad2634b3c3aba5265613ebb..199e016528ccbfc65925eb4ad6438208c616bfa5 100644 (file)
@@ -216,3 +216,31 @@ TEST_F(BuildLogTest, DuplicateVersionHeader) {
   ASSERT_EQ(789, e->restat_mtime);
   ASSERT_EQ("command2", e->command);
 }
+
+TEST_F(BuildLogTest, VeryLongInputLine) {
+  // Ninja's build log buffer is currently 256kB. Lines longer than that are
+  // silently ignored, but don't affect parsing of other lines.
+  FILE* f = fopen(kTestFilename, "wb");
+  fprintf(f, "# ninja log v4\n");
+  fprintf(f, "123\t456\t456\tout\tcommand start");
+  for (size_t i = 0; i < (512 << 10) / strlen(" more_command"); ++i)
+    fputs(" more_command", f);
+  fprintf(f, "\n");
+  fprintf(f, "456\t789\t789\tout2\tcommand2\n");
+  fclose(f);
+
+  string err;
+  BuildLog log;
+  EXPECT_TRUE(log.Load(kTestFilename, &err));
+  ASSERT_EQ("", err);
+
+  BuildLog::LogEntry* e = log.LookupByOutput("out");
+  ASSERT_EQ(NULL, e);
+
+  e = log.LookupByOutput("out2");
+  ASSERT_TRUE(e);
+  ASSERT_EQ(456, e->start_time);
+  ASSERT_EQ(789, e->end_time);
+  ASSERT_EQ(789, e->restat_mtime);
+  ASSERT_EQ("command2", e->command);
+}