Make gn_unittests quiet when there's no errors

--- BEFORE ---

.../gn$ ninja -C out && out/gn_unittests
ninja: Entering directory `out'
ninja: no work to do.
[225/434] NinjaBinaryTargetWriterTest.DupeObjFileErrorERROR Duplicate object file
The target //foo:bar
generates two object files with the same name:
  obj/bar.a.o

It could be you accidentally have a file listed twice in the
sources. Or, depending on how your toolchain maps sources to
object files, two source files with the same name in different
directories could map to the same object file.

In the latter case, either rename one of the files or move one of
the sources to a separate source_set to avoid them both being in
the same target.
[320/434] StringUtils.ExpandStringLiteralIdentifier
hello
hello #1
hello #1/two
hello #1
hello #1one
hello #11
one11
{
  one = 1
}
[1]

A

�
\
\b
"$\
[321/434] StringUtils.ExpandStringLiteralExpressionhello #1
hello #1
[434/434] XmlElementWriter.TestXmlEscape
PASSED

--- AFTER ---

.../gn$ ninja -C out && out/gn_unittests
ninja: Entering directory `out'
ninja: no work to do.
[434/434] XmlElementWriter.TestXmlEscape
PASSED

Change-Id: I373254af11f962e6876963507e8f10e0e258d28d
Reviewed-on: https://gn-review.googlesource.com/1360
Reviewed-by: Brett Wilson <brettw@chromium.org>
diff --git a/tools/gn/ninja_binary_target_writer_unittest.cc b/tools/gn/ninja_binary_target_writer_unittest.cc
index 5fa5639..388c96f 100644
--- a/tools/gn/ninja_binary_target_writer_unittest.cc
+++ b/tools/gn/ninja_binary_target_writer_unittest.cc
@@ -983,10 +983,14 @@
 
   EXPECT_FALSE(scheduler().is_failed());
 
+  scheduler().SuppressOutputForTesting(true);
+
   std::ostringstream out;
   NinjaBinaryTargetWriter writer(&target, out);
   writer.Run();
 
+  scheduler().SuppressOutputForTesting(false);
+
   // Should have issued an error.
   EXPECT_TRUE(scheduler().is_failed());
 }
diff --git a/tools/gn/scheduler.cc b/tools/gn/scheduler.cc
index cf66dc7..0feb4a1 100644
--- a/tools/gn/scheduler.cc
+++ b/tools/gn/scheduler.cc
@@ -21,6 +21,7 @@
       verbose_logging_(false),
       pool_work_count_cv_(&pool_work_count_lock_),
       is_failed_(false),
+      suppress_output_for_testing_(false),
       has_been_shutdown_(false) {
   g_scheduler = this;
 }
@@ -166,6 +167,11 @@
   }
 }
 
+void Scheduler::SuppressOutputForTesting(bool suppress) {
+  base::AutoLock lock(lock_);
+  suppress_output_for_testing_ = suppress;
+}
+
 void Scheduler::LogOnMainThread(const std::string& verb,
                                 const std::string& msg) {
   OutputString(verb, DECORATION_YELLOW);
@@ -173,7 +179,8 @@
 }
 
 void Scheduler::FailWithErrorOnMainThread(const Err& err) {
-  err.PrintToStdout();
+  if (!suppress_output_for_testing_)
+    err.PrintToStdout();
   runner_.Quit();
 }
 
diff --git a/tools/gn/scheduler.h b/tools/gn/scheduler.h
index 02c1d8a..447551e 100644
--- a/tools/gn/scheduler.h
+++ b/tools/gn/scheduler.h
@@ -90,6 +90,8 @@
   void IncrementWorkCount();
   void DecrementWorkCount();
 
+  void SuppressOutputForTesting(bool suppress);
+
  private:
   void LogOnMainThread(const std::string& verb, const std::string& msg);
   void FailWithErrorOnMainThread(const Err& err);
@@ -127,6 +129,8 @@
   mutable base::Lock lock_;
   bool is_failed_;
 
+  bool suppress_output_for_testing_;
+
   // Used to track whether the worker pool has been shutdown. This is necessary
   // to clean up after tests that make a scheduler but don't run the message
   // loop.
diff --git a/tools/gn/string_utils_unittest.cc b/tools/gn/string_utils_unittest.cc
index 372e227..77d8f42 100644
--- a/tools/gn/string_utils_unittest.cc
+++ b/tools/gn/string_utils_unittest.cc
@@ -54,7 +54,6 @@
 
   if (!success)
     return true;  // Don't check result on failure.
-  printf("%s\n", result.string_value().c_str());
   return result.string_value() == expected;
 }