Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
hlopko committed Mar 2, 2021
1 parent 1b7885a commit d5e5a16
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/rustc_env_files/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package(default_visibility = ["//visibility:public"])
rust_binary(
name = "hello_env",
srcs = ["src/main.rs"],
deps = ["@examples//hello_lib"],
rustc_env_files = [":generate_rustc_env_file"],
deps = ["@examples//hello_lib"],
)

genrule(
Expand Down
4 changes: 4 additions & 0 deletions test/unit/interleaved_cc_info/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
load(":interleaved_cc_info_test.bzl", "interleaved_cc_info_test_suite")

############################ UNIT TESTS #############################
interleaved_cc_info_test_suite(name = "interleaved_cc_info_test_suite")
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
89 changes: 89 additions & 0 deletions test/unit/interleaved_cc_info/interleaved_cc_info_test.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""Unittests for rust rules."""

load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
load("//rust:defs.bzl", "rust_common", "rust_library")
load("@rules_cc//cc:defs.bzl", "cc_library")

def _interleaving_cc_link_order_test_impl(ctx):
env = analysistest.begin(ctx)
tut = analysistest.target_under_test(env)
cc_info = tut[CcInfo]
linker_inputs = cc_info.linking_context.linker_inputs.to_list()
a = linker_inputs[0]
b = linker_inputs[1]
c = linker_inputs[2]
d = linker_inputs[3]
e = linker_inputs[4]

asserts.equals(env, "a", a.owner.name)
asserts.equals(env, "b", b.owner.name)
asserts.equals(env, "c", c.owner.name)
asserts.equals(env, "d", d.owner.name)
asserts.equals(env, "e", e.owner.name)

return analysistest.end(env)

interleaving_cc_link_order_test = analysistest.make(_interleaving_cc_link_order_test_impl)

def _interleaving_rust_link_order_test_impl(ctx):
env = analysistest.begin(ctx)
tut = analysistest.target_under_test(env)
dep_info = tut[rust_common.dep_info]
return analysistest.end(env)

interleaving_rust_link_order_test = analysistest.make(_interleaving_rust_link_order_test_impl)


def _interleaving_cc_link_order_test():
rust_library(
name = "a",
srcs = ["a.rs"],
deps = [":b"],
)
cc_library(
name = "b",
srcs = ["b.cc"],
deps = [":c"],
)
rust_library(
name = "c",
srcs = ["c.rs"],
deps = [":d"],
)
cc_library(
name = "d",
srcs = ["d.cc"],
deps = [":e"],
)
rust_library(
name = "e",
srcs = ["e.rs"],
)


interleaving_cc_link_order_test(
name = "interleaving_cc_link_order_test",
target_under_test = ":a",
)

interleaving_rust_link_order_test(
name = "interleaving_rust_link_order_test",
target_under_test = ":a",
)

def interleaved_cc_info_test_suite(name):
"""Entry-point macro called from the BUILD file.
Args:
name: Name of the macro.
"""
_interleaving_cc_link_order_test()
_interleaving_rust_link_order_test()

native.test_suite(
name = name,
tests = [
":interleaving_cc_link_order_test",
":interleaving_rust_link_order_test",
],
)

0 comments on commit d5e5a16

Please sign in to comment.