Skip to content

Commit fd1e6c2

Browse files
committed
test(cpp/libclang): centralize parser integration case wiring
1 parent 4c58a23 commit fd1e6c2

21 files changed

Lines changed: 158 additions & 578 deletions

File tree

cpp/libclang/cpp_parser.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ def run_cpp_parser_action(
352352
# cpp_parser rule
353353

354354
def _cpp_parser_impl(ctx):
355+
if not has_cpp_parser_inputs(ctx.attr.target):
356+
fail("cpp_parser requires a C/C++ target with non-empty parse inputs: %s" % ctx.attr.target)
357+
355358
outputs = run_cpp_parser_action(
356359
ctx,
357360
target = ctx.attr.target,

cpp/libclang/integration_test/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,16 @@ This directory contains integration tests for the C++ libclang parser and relate
2424
## Test Workflow
2525

2626
1. Each case directory contains C++ source files, headers, a BUILD file, and an `expected.json` golden output.
27-
2. The case `cpp_parser(...)` target must set `emit_debug_json = True` so the parser emits the aggregated `debug.json` sidecar required by the test harness.
28-
3. The Rust test framework reads `debug.json` from the parser output directory and compares it to `expected.json`.
27+
2. The case calls the shared integration test macro:
28+
```starlark
29+
cpp_parser_integration_test(
30+
name = "test_case_library",
31+
target = ":case_library",
32+
expected_output = ["expected.json"],
33+
)
34+
```
35+
The macro creates the expected output filegroup and parser target, exposes `CppParserInfo.debug_json` through the test-only debug JSON target, and wires the Rust comparison test.
36+
3. The Rust test framework receives that debug JSON path and compares it to `expected.json`.
2937
4. To batch test all cases:
3038

3139
```bash

cpp/libclang/integration_test/cases/complex_class/BUILD

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13-
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
14-
load("//cpp/libclang:cpp_parser.bzl", "cpp_parser")
15-
16-
filegroup(
17-
name = "expected_output",
18-
srcs = ["expected.json"],
19-
visibility = ["//cpp/libclang/integration_test:__subpackages__"],
20-
)
13+
load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test")
2114

2215
cc_library(
2316
name = "complex_class",
@@ -26,31 +19,8 @@ cc_library(
2619
visibility = ["//cpp/libclang:__subpackages__"],
2720
)
2821

29-
cpp_parser(
30-
name = "parser",
31-
emit_debug_json = True,
32-
extra_args = [
33-
],
22+
cpp_parser_integration_test(
23+
name = "test_complex_class",
24+
expected_output = ["expected.json"],
3425
target = ":complex_class",
35-
tool = "//cpp/libclang:clang_rs_parser",
36-
visibility = ["//cpp/libclang/integration_test:__pkg__"],
37-
)
38-
39-
rust_test(
40-
name = "test_libclang_parser",
41-
srcs = [
42-
"run_test.rs",
43-
],
44-
data = [
45-
":expected_output",
46-
":parser",
47-
],
48-
env = {
49-
"TEST_OUTPUT_PATH": "$(rootpath :parser)",
50-
"EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)",
51-
},
52-
visibility = ["//cpp/libclang:__pkg__"],
53-
deps = [
54-
"//cpp/libclang/integration_test:libclang_test_framework",
55-
],
5626
)

cpp/libclang/integration_test/cases/include_3rdparty/BUILD

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13-
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
14-
load("//cpp/libclang:cpp_parser.bzl", "cpp_parser")
15-
16-
filegroup(
17-
name = "expected_output",
18-
srcs = ["expected.json"],
19-
visibility = ["//cpp/libclang/integration_test:__subpackages__"],
20-
)
13+
load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test")
2114

2215
cc_library(
2316
name = "include_3rdparty",
@@ -29,31 +22,8 @@ cc_library(
2922
],
3023
)
3124

32-
cpp_parser(
33-
name = "parser",
34-
emit_debug_json = True,
35-
extra_args = [
36-
],
25+
cpp_parser_integration_test(
26+
name = "test_include_3rdparty",
27+
expected_output = ["expected.json"],
3728
target = ":include_3rdparty",
38-
tool = "//cpp/libclang:clang_rs_parser",
39-
visibility = ["//cpp/libclang/integration_test:__pkg__"],
40-
)
41-
42-
rust_test(
43-
name = "test_libclang_parser",
44-
srcs = [
45-
"run_test.rs",
46-
],
47-
data = [
48-
":expected_output",
49-
":parser",
50-
],
51-
env = {
52-
"TEST_OUTPUT_PATH": "$(rootpath :parser)",
53-
"EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)",
54-
},
55-
visibility = ["//cpp/libclang:__pkg__"],
56-
deps = [
57-
"//cpp/libclang/integration_test:libclang_test_framework",
58-
],
5929
)

cpp/libclang/integration_test/cases/method_parameter_type/BUILD

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,16 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13-
load("@rules_rust//rust:defs.bzl", "rust_test")
14-
load("//cpp/libclang:cpp_parser.bzl", "cpp_parser")
15-
16-
filegroup(
17-
name = "expected_output",
18-
srcs = ["expected.json"],
19-
visibility = ["//cpp/libclang/integration_test:__subpackages__"],
20-
)
13+
load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test")
2114

2215
cc_library(
2316
name = "method_parameter_type",
2417
srcs = ["transport.cpp"],
2518
visibility = ["//cpp/libclang:__subpackages__"],
2619
)
2720

28-
cpp_parser(
29-
name = "parser",
30-
emit_debug_json = True,
31-
extra_args = [],
21+
cpp_parser_integration_test(
22+
name = "test_method_parameter_type",
23+
expected_output = ["expected.json"],
3224
target = ":method_parameter_type",
33-
tool = "//cpp/libclang:clang_rs_parser",
34-
visibility = ["//cpp/libclang/integration_test:__pkg__"],
35-
)
36-
37-
rust_test(
38-
name = "test_libclang_parser",
39-
srcs = [
40-
"run_test.rs",
41-
],
42-
data = [
43-
":expected_output",
44-
":parser",
45-
],
46-
env = {
47-
"TEST_OUTPUT_PATH": "$(rootpath :parser)",
48-
"EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)",
49-
},
50-
visibility = ["//cpp/libclang:__pkg__"],
51-
deps = [
52-
"//cpp/libclang/integration_test:libclang_test_framework",
53-
],
5425
)

cpp/libclang/integration_test/cases/method_return_type/BUILD

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,16 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13-
load("@rules_rust//rust:defs.bzl", "rust_test")
14-
load("//cpp/libclang:cpp_parser.bzl", "cpp_parser")
15-
16-
filegroup(
17-
name = "expected_output",
18-
srcs = ["expected.json"],
19-
visibility = ["//cpp/libclang/integration_test:__subpackages__"],
20-
)
13+
load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test")
2114

2215
cc_library(
2316
name = "method_return_type",
2417
srcs = ["transport.cpp"],
2518
visibility = ["//cpp/libclang:__subpackages__"],
2619
)
2720

28-
cpp_parser(
29-
name = "parser",
30-
emit_debug_json = True,
31-
extra_args = [],
21+
cpp_parser_integration_test(
22+
name = "test_method_return_type",
23+
expected_output = ["expected.json"],
3224
target = ":method_return_type",
33-
tool = "//cpp/libclang:clang_rs_parser",
34-
visibility = ["//cpp/libclang/integration_test:__pkg__"],
35-
)
36-
37-
rust_test(
38-
name = "test_libclang_parser",
39-
srcs = [
40-
"run_test.rs",
41-
],
42-
data = [
43-
":expected_output",
44-
":parser",
45-
],
46-
env = {
47-
"TEST_OUTPUT_PATH": "$(rootpath :parser)",
48-
"EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)",
49-
},
50-
visibility = ["//cpp/libclang:__pkg__"],
51-
deps = [
52-
"//cpp/libclang/integration_test:libclang_test_framework",
53-
],
5425
)

cpp/libclang/integration_test/cases/nest_namespace_class/BUILD

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,16 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13-
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
14-
load("//cpp/libclang:cpp_parser.bzl", "cpp_parser")
15-
16-
filegroup(
17-
name = "expected_output",
18-
srcs = ["expected.json"],
19-
visibility = ["//cpp/libclang/integration_test:__subpackages__"],
20-
)
13+
load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test")
2114

2215
cc_library(
2316
name = "nest_namespace_class",
2417
srcs = glob(["*.cpp"]),
2518
visibility = ["//cpp/libclang:__subpackages__"],
2619
)
2720

28-
cpp_parser(
29-
name = "parser",
30-
emit_debug_json = True,
31-
extra_args = [
32-
],
21+
cpp_parser_integration_test(
22+
name = "test_nest_namespace_class",
23+
expected_output = ["expected.json"],
3324
target = ":nest_namespace_class",
34-
tool = "//cpp/libclang:clang_rs_parser",
35-
visibility = ["//cpp/libclang/integration_test:__pkg__"],
36-
)
37-
38-
rust_test(
39-
name = "test_libclang_parser",
40-
srcs = [
41-
"run_test.rs",
42-
],
43-
data = [
44-
":expected_output",
45-
":parser",
46-
],
47-
env = {
48-
"TEST_OUTPUT_PATH": "$(rootpath :parser)",
49-
"EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)",
50-
},
51-
visibility = ["//cpp/libclang:__pkg__"],
52-
deps = [
53-
"//cpp/libclang/integration_test:libclang_test_framework",
54-
],
5525
)

cpp/libclang/integration_test/cases/relationship_aggregation/BUILD

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,16 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13-
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
14-
load("//cpp/libclang:cpp_parser.bzl", "cpp_parser")
15-
16-
filegroup(
17-
name = "expected_output",
18-
srcs = ["expected.json"],
19-
visibility = ["//cpp/libclang/integration_test:__subpackages__"],
20-
)
13+
load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test")
2114

2215
cc_library(
2316
name = "relationship_aggregation",
2417
srcs = ["aggregation.cpp"],
2518
visibility = ["//cpp/libclang:__subpackages__"],
2619
)
2720

28-
cpp_parser(
29-
name = "parser",
30-
emit_debug_json = True,
31-
extra_args = [
32-
],
21+
cpp_parser_integration_test(
22+
name = "test_relationship_aggregation",
23+
expected_output = ["expected.json"],
3324
target = ":relationship_aggregation",
34-
tool = "//cpp/libclang:clang_rs_parser",
35-
visibility = ["//cpp/libclang/integration_test:__pkg__"],
36-
)
37-
38-
rust_test(
39-
name = "test_libclang_parser",
40-
srcs = [
41-
"run_test.rs",
42-
],
43-
data = [
44-
":expected_output",
45-
":parser",
46-
],
47-
env = {
48-
"TEST_OUTPUT_PATH": "$(rootpath :parser)",
49-
"EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)",
50-
},
51-
visibility = ["//cpp/libclang:__pkg__"],
52-
deps = [
53-
"//cpp/libclang/integration_test:libclang_test_framework",
54-
],
5525
)

cpp/libclang/integration_test/cases/relationship_association/BUILD

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,16 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13-
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
14-
load("//cpp/libclang:cpp_parser.bzl", "cpp_parser")
15-
16-
filegroup(
17-
name = "expected_output",
18-
srcs = ["expected.json"],
19-
visibility = ["//cpp/libclang/integration_test:__subpackages__"],
20-
)
13+
load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test")
2114

2215
cc_library(
2316
name = "relationship_association",
2417
srcs = ["association.cpp"],
2518
visibility = ["//cpp/libclang:__subpackages__"],
2619
)
2720

28-
cpp_parser(
29-
name = "parser",
30-
emit_debug_json = True,
31-
extra_args = [
32-
],
21+
cpp_parser_integration_test(
22+
name = "test_relationship_association",
23+
expected_output = ["expected.json"],
3324
target = ":relationship_association",
34-
tool = "//cpp/libclang:clang_rs_parser",
35-
visibility = ["//cpp/libclang/integration_test:__pkg__"],
36-
)
37-
38-
rust_test(
39-
name = "test_libclang_parser",
40-
srcs = [
41-
"run_test.rs",
42-
],
43-
data = [
44-
":expected_output",
45-
":parser",
46-
],
47-
env = {
48-
"TEST_OUTPUT_PATH": "$(rootpath :parser)",
49-
"EXPECTED_OUTPUT_PATH": "$(rootpath :expected_output)",
50-
},
51-
visibility = ["//cpp/libclang:__pkg__"],
52-
deps = [
53-
"//cpp/libclang/integration_test:libclang_test_framework",
54-
],
5525
)

0 commit comments

Comments
 (0)