Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ggj][infra][5/5] support goldens updates for AST integration test #347

Merged
merged 16 commits into from
Oct 1, 2020
Merged
9 changes: 8 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,23 @@ java_binary(
name = "junit_runner",
srcs = [
"//src/test/java/com/google/api/generator/gapic/dummy:dummy_files",
"//src/test/java/com/google/api/generator/engine:engine_files",
"//src/test/java/com/google/api/generator/test/framework:framework_files",
],
data = ["//src/test/java/com/google/api/generator/gapic/dummy/goldens:goldens_files"],
data = [
"//src/test/java/com/google/api/generator/gapic/dummy/goldens:goldens_files",
"//src/test/java/com/google/api/generator/engine/goldens:goldens_files",
],
jvm_flags = ["-Xmx512m"],
main_class = "com.google.api.generator.test.framework.SingleJUnitTestRunner",
visibility = ["//visibility:public"],
deps = [
"//src/main/java/com/google/api/generator/engine/ast",
"//src/main/java/com/google/api/generator/engine/writer",
"//src/test/java/com/google/api/generator/test/framework",
"//src/main/java/com/google/api/generator/engine/lexicon",
"@com_google_guava_guava//:com_google_guava_guava",
"@com_google_truth_truth//jar",
"@io_github_java_diff_utils//jar",
"@junit_junit//jar",
"@org_hamcrest_hamcrest_core//jar",
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/google/api/generator/engine/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("//:rules_bazel/java/java_diff_test.bzl", "updated_golden")

package(default_visibility = ["//visibility:public"])

filegroup(
Expand Down Expand Up @@ -25,3 +27,15 @@ TESTS = [
"@junit_junit//jar",
],
) for test_name in TESTS]

TEST_CLASS_NAME = "com.google.api.generator.engine.JavaCodeGeneratorTest"

# Run `bazel run src/test/java/com/google/api/generator/engine:JavaCodeGeneratorTest_update`
# to update goldens as expected generated code.
updated_golden(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not part of this PR, but just noticed this. Can we change this (separately) to update_golden as was proposed in the original doc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sg, was following Vadym's suggestion to make all the name of bazel target a "noun" instead of "verb". But i'm open to change it back in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed this in PR #357

name = "JavaCodeGeneratorTest_update",
srcs = [
":engine_files",
],
test_class_name = TEST_CLASS_NAME,
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.google.api.generator.engine.ast.WhileStatement;
import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.test.framework.Assert;
import com.google.api.generator.test.framework.Utils;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
Expand Down Expand Up @@ -172,6 +173,8 @@ public void validJavaClass() {
.build();
JavaWriterVisitor javaWriterVisitor = new JavaWriterVisitor();
libraryServiceStubClass.accept(javaWriterVisitor);
Utils.saveCodegenToFile(
this.getClass(), "JavaCodeGeneratorTest.golden", javaWriterVisitor.write());
Path goldenFilePath = Paths.get(GOLDENFILES_DIRECTORY, "JavaCodeGeneratorTest.golden");
Assert.assertCodeEquals(goldenFilePath, javaWriterVisitor.write());
}
Expand Down