Skip to content

Commit d641b9e

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

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
load(":bindgen_test.bzl", "bindgen_test_suite")
2+
3+
bindgen_test_suite(name = "cc_bindgen_test_suite")

test/bindgen/bindgen_test.bzl

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

test/bindgen/simple.cc

Whitespace-only changes.

test/bindgen/simple.h

Whitespace-only changes.

0 commit comments

Comments
 (0)