Skip to content

Commit f074e98

Browse files
author
Vinh Tran
committed
Introduce @rules_testing to write Starlark tests
1 parent 50b9ef3 commit f074e98

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

WORKSPACE.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,10 @@ http_archive(
7676
#
7777
# load("@bazelci_rules//:rbe_repo.bzl", "rbe_preconfig")
7878
# rbe_preconfig(name = "buildkite_config", toolchain = "ubuntu2004-bazel-java11")
79+
80+
http_archive(
81+
name = "rules_testing",
82+
sha256 = "b84ed8546f1969d700ead4546de9f7637e0f058d835e47e865dcbb13c4210aed",
83+
strip_prefix = "rules_testing-0.5.0",
84+
url = "https://github.com/bazelbuild/rules_testing/releases/download/v0.5.0/rules_testing-v0.5.0.tar.gz",
85+
)

test/bindgen/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# BUILD
2+
load(":cc_bindgen_test.bzl", "cc_bindgen_test_suite")
3+
4+
cc_bindgen_test_suite(name = "cc_bindgen_test_suite")

test/bindgen/cc_bindgen_test.bzl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
load("@rules_rust//bindgen:defs.bzl", "rust_bindgen_library")
3+
load("@rules_rust//rust:defs.bzl", "rust_binary")
4+
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
5+
6+
def _test_cc_linkopt_impl(env, target):
7+
# Assert
8+
env.expect.that_action(target.actions[0]) \
9+
.contains_at_least_args(["--codegen=link-arg=-framework"])
10+
11+
def _test_cc_linkopt(name):
12+
# Arrange
13+
cc_library(
14+
name = name + "_cc",
15+
srcs = ["simple.cc"],
16+
hdrs = ["simple.h"],
17+
linkopts = ["-framework"],
18+
tags = ["manual"],
19+
)
20+
rust_bindgen_library(
21+
name = name + "_rust_bindgen",
22+
cc_lib = name + "_cc",
23+
header = "simple.h",
24+
tags = ["manual"],
25+
edition = "2021",
26+
)
27+
rust_binary(
28+
name = name + "_rust_binary",
29+
srcs = ["main.rs"],
30+
deps = [name + "_rust_bindgen"],
31+
tags = ["manual"],
32+
edition = "2021",
33+
)
34+
35+
# Act
36+
# Use targets attr to also verify `rust_bindgen_library` not having
37+
# the linkopt after https://github.com/bazelbuild/rules_testing/issues/67
38+
# is released
39+
analysis_test(
40+
name = name,
41+
target = name + "_rust_binary",
42+
impl = _test_cc_linkopt_impl,
43+
)
44+
45+
def cc_bindgen_test_suite(name):
46+
test_suite(
47+
name = name,
48+
tests = [
49+
_test_cc_linkopt,
50+
],
51+
)

test/bindgen/simple.cc

Whitespace-only changes.

test/bindgen/simple.h

Whitespace-only changes.

0 commit comments

Comments
 (0)