Skip to content

Commit c821488

Browse files
verios-googlePINS Team
andauthored
Changed build file to have proper golden test targets (#72)
PiperOrigin-RevId: 468293606 Co-authored-by: PINS Team <copybara-servicebot@google.com>
1 parent 01d952b commit c821488

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

e2e_tests/p4check.bzl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,20 @@ To auto-generate or update, run `bazel run <target> -- --update`.
153153
),
154154
},
155155
)
156+
157+
def cmd_diff_test(name, actual_cmd, expected, tools = [], data = [], visibility = None):
158+
"""Runs a command to get the actual output, to compare against `expected`."""
159+
native.genrule(
160+
name = name + "_output",
161+
visibility = visibility,
162+
srcs = data,
163+
outs = [name + ".actual"],
164+
tools = tools,
165+
cmd = actual_cmd + " > '$@'",
166+
testonly = True,
167+
)
168+
diff_test(
169+
name = name,
170+
actual = name + ".actual",
171+
expected = expected,
172+
)

gutils/BUILD.bazel

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ cc_library(
7979
"ordered_map.h",
8080
],
8181
visibility = ["//visibility:public"],
82-
deps = [
83-
"@com_google_absl//absl/container:btree",
84-
],
82+
deps = ["@com_google_absl//absl/container:btree"],
8583
)
8684

8785
cc_library(

p4_constraints/backend/BUILD.bazel

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("//third_party/p4lang_p4_constraints/e2e_tests:p4check.bzl", "diff_test")
1+
load("//third_party/p4lang_p4_constraints/e2e_tests:p4check.bzl", "cmd_diff_test")
22

33
package(
44
default_visibility = ["//visibility:public"],
@@ -88,16 +88,18 @@ cc_library(
8888
],
8989
)
9090

91-
cc_binary(
91+
# go/golden-test-with-coverage
92+
cc_test(
9293
name = "interpreter_golden_test_runner",
93-
testonly = True,
9494
srcs = ["interpreter_golden_test_runner.cc"],
95+
linkstatic = True,
9596
deps = [
9697
":constraint_info",
9798
":interpreter",
9899
"//gutils:ordered_map",
99100
"//gutils:parse_text_proto",
100101
"//gutils:status",
102+
"//net/proto2/io/public:io",
101103
"//p4_constraints:ast_cc_proto",
102104
"//p4_constraints/frontend:lexer",
103105
"//p4_constraints/frontend:parser",
@@ -108,18 +110,11 @@ cc_binary(
108110
],
109111
)
110112

111-
genrule(
112-
name = "interpreter_golden_test_runner_output",
113-
testonly = True,
114-
outs = ["interpreter_golden_test_runner.output"],
115-
cmd = "$(location :interpreter_golden_test_runner) > $(OUTS)",
116-
tools = [":interpreter_golden_test_runner"],
117-
)
118-
119-
diff_test(
113+
cmd_diff_test(
120114
name = "interpreter_golden_test",
121-
actual = ":interpreter_golden_test_runner_output",
122-
expected = "interpreter_golden_test_runner.expected",
115+
actual_cmd = "$(execpath :interpreter_golden_test_runner)",
116+
expected = ":interpreter_golden_test_runner.expected",
117+
tools = [":interpreter_golden_test_runner"],
123118
)
124119

125120
cc_test(

0 commit comments

Comments
 (0)