tint_cmd: Flush stderr after emitting non-error diagnostics

And before we emit the output program to stdout. This is important to
ensure that the output is emitted immediately rather than buffered,
especially since we write to both stdout and stderr. For example, we
emit diagnostics to stderr, but the wgsl program to stdout, and without
flushing, the ordering of this output is not guaranteed. We depend on
this ordering for our Tint e2e tests (comparing saved output to emitted
output), and on the Dawn LUCI bots, these tests failed because
diagnostic messages were emitted after the wgsl program.

Bug: dawn:2435
Change-Id: I036ab8531f859b842c0bc229c085dfc22e6cd6e1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/179142
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/tint/cmd/common/helper.cc b/src/tint/cmd/common/helper.cc
index a1fbaf0..4c11c09 100644
--- a/src/tint/cmd/common/helper.cc
+++ b/src/tint/cmd/common/helper.cc
@@ -276,6 +276,9 @@
             tint::StyledTextPrinter::Create(stderr)->Print(
                 formatter.Format(info.program.Diagnostics()));
         }
+        // Flush any diagnostics written to stderr. We depend on these being emitted to the console
+        // before the program for end-to-end tests.
+        fflush(stderr);
     }
 
     if (!info.program.IsValid()) {