private void updateGoldenFile(Compilation compilation, String className, String relativePath)
      throws IOException {
    Path goldenFileRootPath = Paths.get(GOLDEN_FILE_ROOT);
    Path goldenFilePath = goldenFileRootPath.resolve(relativePath);
    checkState(
        Files.isRegularFile(goldenFilePath) && Files.isWritable(goldenFilePath),
        "%s does not exist or can't be written",
        goldenFilePath);

    JavaFileObject newJavaFileObject =
        compilation
            .generatedSourceFile(className)
            .orElseThrow(() -> new IllegalStateException("No generated file for " + className));
    // We can't use Files.readString here because this test must run on Java 8.
    String oldContent = new String(Files.readAllBytes(goldenFilePath), UTF_8);
    String newContent =
        newJavaFileObject.getCharContent(/* ignoreEncodingErrors= */ false).toString();

    // We want to preserve the copyright notice and some minor Google-internal things that are
    // stripped from the open-source version. So keep text from the old golden file before the
    // class declaration.
    int oldPosition = indexOfClassStartIn(oldContent, "original " + relativePath);
    int newPosition = indexOfClassStartIn(newContent, "generated " + relativePath);
    String updatedContent =
        oldContent.substring(0, oldPosition) + newContent.substring(newPosition);
    // We can't use Files.writeString here because this test must run on Java 8.
    Files.write(goldenFilePath, updatedContent.getBytes(UTF_8));
    System.err.println("Updated " + goldenFilePath);
  }
Runs a golden-file test, and optionally updates the golden file if the test fails.

<p>If the golden file does not match current generated output, and the environment variable
{@value #GOLDEN_FILE_ROOT_ENV} is set to the root directory for resources, then the golden file
will be rewritten to match the generated output.

@param inputResources resource names for the sources that the test will compile
@param expectedOutput map where each key is the name of an expected generated file, and each
    corresponding value is the name of the resource with the text that should have been
    generated
factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java