Add --quiet to gn_unittests

When logging it to a file to try to list errors, and in CI, the logs are
10 lines of failures surrounded by hundreds of lines of which test is
running.

Bug: None
Change-Id: I35bc672b860dfee4c8326dd68dff65d96a6a6964
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/23201
Reviewed-by: Takuto Ikuta <tikuta@google.com>
Commit-Queue: Matt Stark <msta@google.com>
diff --git a/src/util/test/gn_test.cc b/src/util/test/gn_test.cc
index 4da821a..717c2d2 100644
--- a/src/util/test/gn_test.cc
+++ b/src/util/test/gn_test.cc
@@ -206,10 +206,13 @@
   int tests_started = 0;
 
   const char* test_filter = "*";
+  bool quiet = false;
   for (int i = 1; i < argc; ++i) {
     const char kTestFilterPrefix[] = "--gtest_filter=";
     if (strncmp(argv[i], kTestFilterPrefix, strlen(kTestFilterPrefix)) == 0) {
       test_filter = &argv[i][strlen(kTestFilterPrefix)];
+    } else if (strcmp(argv[i], "--quiet") == 0) {
+      quiet = true;
     }
   }
 
@@ -246,17 +249,25 @@
 
     ++tests_started;
     testing::Test* test = tests[i].factory();
-    printf("%s[%d/%d] %s%s", prefix, tests_started, num_active_tests,
-           tests[i].name, suffix);
+    if (!quiet) {
+      printf("%s[%d/%d] %s%s", prefix, tests_started, num_active_tests,
+             tests[i].name, suffix);
+    }
     test->SetUp();
     test->Run();
     test->TearDown();
-    if (test->Failed())
+    if (test->Failed()) {
       passed = false;
+      if (quiet) {
+        printf("FAILED: %s\n", tests[i].name);
+      }
+    }
     delete test;
   }
 
-  printf("\n%s\n", passed ? "PASSED" : "FAILED");
+  if (!quiet || !passed) {
+    printf("\n%s\n", passed ? "PASSED" : "FAILED");
+  }
   fflush(stdout);
   return passed ? EXIT_SUCCESS : EXIT_FAILURE;
 }