Fixing #3834, making sure test.log always exists.

Even if the test action produced no output, which it really shouldn't, Bazel should create an empty test.log file.

TESTED=unit tests
RELNOTES: Fixes #3834
PiperOrigin-RevId: 172412615
diff --git a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
index 9b7aace..bfa8cd8 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java
@@ -242,12 +242,12 @@
 
       // e.g. test.dir/file
       PathFragment relativeToTestDirectory = testOutputPath.relativeTo(testRoot);
-      
+
       // e.g. attempt_1.dir/file
       String destinationPathFragmentStr =
           relativeToTestDirectory.getSafePathString().replaceFirst("test", attemptPrefix);
       PathFragment destinationPathFragment = PathFragment.create(destinationPathFragmentStr);
-      
+
       // e.g. /attemptsDir/attempt_1.dir/file
       Path destinationPath = attemptsDir.getRelative(destinationPathFragment);
       destinationPath.getParentDirectory().createDirectory();
@@ -316,6 +316,10 @@
       StandaloneTestResult standaloneTestResult =
           executeTest(action, spawn, actionExecutionContext.withFileOutErr(fileOutErr));
       appendStderr(fileOutErr.getOutputPath(), fileOutErr.getErrorPath());
+      if (!fileOutErr.hasRecordedOutput()) {
+        // Touch the output file so that test.log can get created.
+        FileSystemUtils.touchFile(fileOutErr.getOutputPath());
+      }
       return standaloneTestResult;
     }
   }
@@ -370,6 +374,7 @@
             .setTestPassed(false)
             .setStatus(e.hasTimedOut() ? BlazeTestStatus.TIMEOUT : BlazeTestStatus.FAILED)
             .addFailedLogs(testLogPath.getPathString());
+        spawnResults = ImmutableSet.of(e.getSpawnResult());
       } finally {
         long duration = actionExecutionContext.getClock().currentTimeMillis() - startTime;
         builder.setStartTimeMillisEpoch(startTime);