Skip to content

Commit

Permalink
better test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Wyverald committed Apr 24, 2024
1 parent ad07db2 commit 63ad231
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
30 changes: 15 additions & 15 deletions tests/bzl_library/BUILD
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
load(":bzl_library_consumer.bzl", "bzl_library_consumer")
load("//:bzl_library.bzl", "bzl_library")
load("//rules:build_test.bzl", "build_test")

bzl_library(
name = "a_bl",
filegroup(
name = "a",
srcs = ["a.bzl"],
)

bzl_library(
name = "b_bl",
name = "b",
srcs = ["b.bzl"],
deps = [":a_bl"],
)

filegroup(
name = "a_fg",
srcs = ["a.bzl"],
bzl_library(
name = "c",
srcs = ["c.bzl"],
deps = [
":a",
":b",
],
)

bzl_library(
name = "b_fg",
srcs = ["b.bzl"],
deps = [":a_fg"],
bzl_library_consumer(
name = "consumer",
target = ":c",
)

build_test(
name = "test_bzl_library",
targets = [
":b_bl",
":b_fg",
],
targets = [":consumer"],
)
6 changes: 2 additions & 4 deletions tests/bzl_library/b.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"""b.bzl, which loads from a.bzl"""
"""b.bzl, havin' a grand time"""

load(":a.bzl", "A")

B = A + 70
B = 70
20 changes: 20 additions & 0 deletions tests/bzl_library/bzl_library_consumer.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""A rule that consumes a bzl_library target and asserts its providers are as expected."""

load("//:bzl_library.bzl", "StarlarkLibraryInfo")

def _bzl_library_consumer_impl(ctx):
files = sorted([t.basename for t in ctx.attr.target.files.to_list()])
if files != ["a.bzl", "b.bzl", "c.bzl"]:
fail("unexpected filenames from DefaultInfo: ", files)
files = sorted([t.basename for t in ctx.attr.target[StarlarkLibraryInfo].transitive_srcs.to_list()])
if files != ["a.bzl", "b.bzl", "c.bzl"]:
fail("unexpected filenames from StarlarkLibraryInfo: ", files)

bzl_library_consumer = rule(
implementation = _bzl_library_consumer_impl,
attrs = {
"target": attr.label(
providers = [[StarlarkLibraryInfo]],
),
},
)
6 changes: 6 additions & 0 deletions tests/bzl_library/c.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""c.bzl, standin' on the shoulder of giants"""

load(":a.bzl", "A")
load(":b.bzl", "B")

C = A + B

0 comments on commit 63ad231

Please sign in to comment.