This repository was archived by the owner on May 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathjava_diff_test.bzl
More file actions
84 lines (78 loc) · 2.49 KB
/
Copy pathjava_diff_test.bzl
File metadata and controls
84 lines (78 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def _overwrite_golden_impl(ctx):
test_class = ctx.attr.test_class
inputs = ctx.files.srcs
goldens_output_zip = ctx.outputs.goldens_output_zip
test_runner = ctx.executable.test_runner
# Generate the goldens from tests.
generate_goldens_script = """
mkdir local_tmp
TEST_OUTPUT_HOME="$(pwd)/local_tmp" {test_runner_path} $@
cd local_tmp
# Zip all files under local_tmp with all nested parent folders except for local_tmp itself.
# Zip files because there are cases that one Junit test can produce multiple goldens.
zip -r ../{goldens_output_zip} .
""".format(
test_runner_path = test_runner.path,
goldens_output_zip = goldens_output_zip.path,
)
ctx.actions.run_shell(
inputs = inputs,
outputs = [goldens_output_zip],
arguments = [test_class],
tools = [test_runner],
command = generate_goldens_script,
)
# Overwrite the goldens.
golden_update_script_content = """
#!/bin/bash
cd ${{BUILD_WORKSPACE_DIRECTORY}}
unzip -ao {goldens_output_zip} -d src/test/java
""".format(
goldens_output_zip = goldens_output_zip.path,
)
ctx.actions.write(
output = ctx.outputs.golden_update_script,
content = golden_update_script_content,
is_executable = True,
)
return [DefaultInfo(executable = ctx.outputs.golden_update_script)]
overwrite_golden = rule(
attrs = {
"test_class": attr.string(mandatory = True),
"srcs": attr.label_list(
allow_files = True,
mandatory = True,
),
"test_runner": attr.label(
mandatory = True,
executable = True,
cfg = "host",
),
},
outputs = {
"goldens_output_zip": "%{name}.zip",
"golden_update_script": "%{name}.sh",
},
executable = True,
implementation = _overwrite_golden_impl,
)
def golden_update(
name,
srcs,
test_class,
data = [],
deps = []):
golden_junit_runner_name = "%s_junit_runner" % name
native.java_binary(
name = golden_junit_runner_name,
srcs = srcs,
data = data,
main_class = "com.google.api.generator.test.framework.SingleJUnitTestRunner",
deps = ["//src/test/java/com/google/api/generator/test/framework:junit_runner"] + deps,
)
overwrite_golden(
name = name,
test_class = test_class,
test_runner = ":%s" % golden_junit_runner_name,
srcs = srcs + data,
)