Skip to content

Commit 48ddda3

Browse files
Rachel Goldfingercopybara-github
authored andcommitted
This change moves several tests from CcProtoTest.java to Starlark-based analysis tests in cc_proto_library.bzl
PiperOrigin-RevId: 863340736
1 parent 2aa094e commit 48ddda3

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

bazel/tests/BUILD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
22
load("//bazel:proto_descriptor_set.bzl", "proto_descriptor_set")
33
load("//bazel:proto_library.bzl", "proto_library")
44
load(":bazel_proto_library_tests.bzl", "bazel_proto_library_test_suite")
5+
load(":cc_proto_library_tests.bzl", "cc_proto_library_test_suite")
56
load(":cc_toolchain_tests.bzl", "cc_toolchain_test_suite")
67
load(":java_proto_library_tests.bzl", "java_proto_library_test_suite")
78
load(":proto_common_check_collocated_tests.bzl", "proto_common_check_collocated_test_suite")
@@ -28,6 +29,8 @@ java_proto_library_test_suite(name = "java_proto_library_test_suite")
2829

2930
py_proto_library_test_suite(name = "py_proto_library_test_suite")
3031

32+
cc_proto_library_test_suite(name = "cc_proto_library_tests")
33+
3134
proto_library(
3235
name = "empty_proto_library",
3336
)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Protocol Buffers - Google's data interchange format
2+
# Copyright 2025 Google Inc. All rights reserved.
3+
#
4+
# Use of this source code is governed by a BSD-style
5+
# license that can be found in the LICENSE file or at
6+
# https://developers.google.com/open-source/licenses/bsd
7+
"""Tests for `cc_proto_library`."""
8+
9+
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
10+
load("@rules_cc//cc:defs.bzl", "cc_library")
11+
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
12+
load("@rules_testing//lib:truth.bzl", "matching")
13+
load("@rules_testing//lib:util.bzl", "util")
14+
load("//bazel:cc_proto_library.bzl", "cc_proto_library")
15+
load("//bazel:proto_library.bzl", "proto_library")
16+
17+
def cc_proto_library_test_suite(name):
18+
test_suite(
19+
name = name,
20+
tests = [
21+
_test_link_order_with_mixed_deps,
22+
_test_link_order_with_mixed_deps_and_intermediate_library,
23+
],
24+
)
25+
26+
def _test_link_order_with_mixed_deps(name):
27+
util.helper_target(cc_library, name = name + "_a", srcs = ["a.cc"])
28+
util.helper_target(proto_library, name = name + "_b", srcs = ["b.proto"])
29+
util.helper_target(cc_proto_library, name = name + "_bc", deps = [":" + name + "_b"])
30+
util.helper_target(cc_library, name = name + "_c", srcs = ["c.cc"])
31+
util.helper_target(
32+
cc_binary,
33+
name = name + "_foo",
34+
srcs = ["foo.cc"],
35+
deps = [
36+
":" + name + "_a",
37+
":" + name + "_bc",
38+
":" + name + "_c",
39+
],
40+
)
41+
42+
analysis_test(
43+
name = name,
44+
target = ":" + name + "_foo",
45+
impl = _test_link_order_with_mixed_deps_impl,
46+
)
47+
48+
def _test_link_order_with_mixed_deps_impl(env, target):
49+
action = env.expect.that_target(target).action_named("CppLink")
50+
action.inputs().contains_at_least_predicates([
51+
matching.file_basename_contains("libtest_link_order_with_mixed_deps_a"),
52+
matching.file_basename_contains("libtest_link_order_with_mixed_deps_b"),
53+
matching.file_basename_contains("libtest_link_order_with_mixed_deps_c"),
54+
matching.file_basename_contains("libtest_link_order_with_mixed_deps_foo"),
55+
])
56+
57+
def _test_link_order_with_mixed_deps_and_intermediate_library(name):
58+
util.helper_target(cc_library, name = name + "_a", srcs = ["a.cc"])
59+
util.helper_target(proto_library, name = name + "_b", srcs = ["b.proto"])
60+
util.helper_target(cc_proto_library, name = name + "_bc", deps = [":" + name + "_b"])
61+
util.helper_target(cc_library, name = name + "_c", srcs = ["c.cc"])
62+
util.helper_target(
63+
cc_library,
64+
name = name + "_lib",
65+
srcs = ["lib.cc"],
66+
deps = [
67+
":" + name + "_a",
68+
":" + name + "_bc",
69+
":" + name + "_c",
70+
],
71+
)
72+
util.helper_target(
73+
cc_binary,
74+
name = name + "_foo",
75+
srcs = ["foo.cc"],
76+
deps = [":" + name + "_lib"],
77+
)
78+
79+
analysis_test(
80+
name = name,
81+
target = ":" + name + "_foo",
82+
impl = _test_link_order_with_mixed_deps_and_intermediate_library_impl,
83+
)
84+
85+
def _test_link_order_with_mixed_deps_and_intermediate_library_impl(env, target):
86+
action = env.expect.that_target(target).action_named("CppLink")
87+
action.inputs().contains_at_least_predicates([
88+
matching.file_basename_contains("libtest_link_order_with_mixed_deps_a"),
89+
matching.file_basename_contains("libtest_link_order_with_mixed_deps_b"),
90+
matching.file_basename_contains("libtest_link_order_with_mixed_deps_c"),
91+
matching.file_basename_contains("libtest_link_order_with_mixed_deps_foo"),
92+
matching.file_basename_contains("libtest_link_order_with_mixed_deps_lib"),
93+
])

0 commit comments

Comments
 (0)