Skip to content

Commit

Permalink
Duplicate tests and docs related to unittest.bzl from bazel_skylib to…
Browse files Browse the repository at this point in the history
… rules_testing in anticipation of their being deleted from bazel_skylib.

FUTURE_COPYBARA_INTEGRATE_REVIEW=#100 from bazelbuild:lberki-update-stardoc c78f471
PiperOrigin-RevId: 641939750
  • Loading branch information
A Googler authored and Blaze Rules Copybara committed Sep 13, 2024
1 parent caa0cb0 commit c280f09
Show file tree
Hide file tree
Showing 16 changed files with 1,288 additions and 43 deletions.
2 changes: 1 addition & 1 deletion docgen/docgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

"""Rules to help generate rules_testing docs."""

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
load("//@bazel_skylib/rules:build_test.bzl", "build_test")

def sphinx_stardocs(name, bzl_libraries, **kwargs):
"""Generate Sphinx-friendly markdown docs using Stardoc for bzl libraries.
Expand Down
606 changes: 606 additions & 0 deletions docs/source/unittest_doc.md

Large diffs are not rendered by default.

25 changes: 17 additions & 8 deletions lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//@bazel_skylib:bzl_library.bzl", "bzl_library")
load("//lib/private:util.bzl", "do_nothing")

licenses(["notice"])
Expand Down Expand Up @@ -57,9 +57,9 @@ bzl_library(
visibility = ["//visibility:public"],
deps = [
":unittest",
"@bazel_skylib//lib:paths",
"@bazel_skylib//lib:types",
"@bazel_skylib//rules:write_file",
"//@bazel_skylib/lib:paths",
"//@bazel_skylib/lib:types",
"//@bazel_skylib/rules:write_file",
],
)

Expand All @@ -69,10 +69,10 @@ bzl_library(
srcs = ["unittest.bzl"],
visibility = ["//visibility:public"],
deps = [
"@bazel_skylib//lib:new_sets",
"@bazel_skylib//lib:partial",
"@bazel_skylib//lib:sets",
"@bazel_skylib//lib:types",
"//@bazel_skylib/lib:new_sets",
"//@bazel_skylib/lib:partial",
"//@bazel_skylib/lib:sets",
"//@bazel_skylib/lib:types",
],
)

Expand All @@ -85,6 +85,12 @@ bzl_library(
],
)

bzl_library(
name = "unittest_bzl",
srcs = ["unittest.bzl"],
visibility = ["//visibility:public"],
)

bzl_library(
name = "test_suite_bzl",
srcs = ["test_suite.bzl"],
Expand All @@ -105,6 +111,7 @@ filegroup(
":util_bzl",
],
visibility = [
"//tests:__pkg__",
"//tools/build_defs/python/tests/base_rules:__pkg__",
],
)
Expand All @@ -113,10 +120,12 @@ exports_files(
srcs = [
"analysis_test.bzl",
"truth.bzl",
"unittest.bzl",
"util.bzl",
],
visibility = [
"//docgen:__pkg__",
"//tests:__pkg__",
],
)

Expand Down
10 changes: 5 additions & 5 deletions lib/private/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//@bazel_skylib:bzl_library.bzl", "bzl_library")

licenses(["notice"])

Expand Down Expand Up @@ -42,7 +42,7 @@ bzl_library(
deps = [
":check_util_bzl",
":truth_common_bzl",
"@bazel_skylib//lib:types",
"//@bazel_skylib/lib:types",
],
)

Expand Down Expand Up @@ -73,7 +73,7 @@ bzl_library(
deps = [
":check_util_bzl",
":truth_common_bzl",
"@bazel_skylib//lib:types",
"//@bazel_skylib/lib:types",
],
)

Expand All @@ -89,7 +89,7 @@ bzl_library(
srcs = [
"truth_common.bzl",
],
deps = ["@bazel_skylib//lib:types"],
deps = ["//@bazel_skylib/lib:types"],
)

bzl_library(
Expand All @@ -103,7 +103,7 @@ bzl_library(
":matching_bzl",
":ordered_bzl",
":truth_common_bzl",
"@bazel_skylib//lib:types",
"//@bazel_skylib/lib:types",
],
)

Expand Down
4 changes: 2 additions & 2 deletions lib/private/analysis_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
Support for testing analysis phase logic, such as rules.
"""

load("@bazel_skylib//lib:dicts.bzl", "dicts")
load("@bazel_skylib//lib:types.bzl", "types")
load("//@bazel_skylib/lib:dicts.bzl", "dicts")
load("//@bazel_skylib/lib:types.bzl", "types")
load("//lib:truth.bzl", "truth")
load("//lib:util.bzl", "recursive_testing_aspect", "testing_aspect")
load("//lib/private:target_subject.bzl", "PROVIDER_SUBJECT_FACTORIES")
Expand Down
2 changes: 1 addition & 1 deletion lib/private/check_util.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Helper functions to perform checks."""

load("@bazel_skylib//lib:types.bzl", "types")
load("//@bazel_skylib/lib:types.bzl", "types")
load(":compare_util.bzl", "MatchResult", "compare_contains_exactly_predicates")
load(":failure_messages.bzl", "format_failure_unexpected_values")
load(":matching.bzl", "matching")
Expand Down
2 changes: 1 addition & 1 deletion lib/private/int_subject.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""# IntSubject"""

load("@bazel_skylib//lib:types.bzl", "types")
load("//@bazel_skylib/lib:types.bzl", "types")
load(":check_util.bzl", "check_not_equals", "common_subject_is_in")
load(":truth_common.bzl", "repr_with_type")

Expand Down
2 changes: 1 addition & 1 deletion lib/private/label_subject.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""# LabelSubject"""

load("@bazel_skylib//lib:types.bzl", "types")
load("//@bazel_skylib/lib:types.bzl", "types")
load(":check_util.bzl", "common_subject_is_in")
load(":truth_common.bzl", "to_list")

Expand Down
2 changes: 1 addition & 1 deletion lib/private/truth_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Common code used by truth."""

load("@bazel_skylib//lib:types.bzl", "types")
load("//@bazel_skylib/lib:types.bzl", "types")

def mkmethod(self, method):
"""Bind a struct as the first arg to a function.
Expand Down
16 changes: 7 additions & 9 deletions lib/unit_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ Support for testing generic Starlark code, i.e. code that doesn't require
the analysis phase or instantiate rules.
"""

# We have to load the private impl to avoid a circular dependency
load("//lib/private:analysis_test.bzl", "analysis_test")

_TARGET = Label("//lib:_stub_target_for_unit_tests")

def unit_test(name, impl, attrs = {}):
Expand All @@ -38,9 +35,10 @@ def unit_test(name, impl, attrs = {}):
attrs: (dict of str to str) additional attributes to make available to
the test.
"""
analysis_test(
name = name,
impl = lambda env, target: impl(env),
target = _TARGET,
attrs = attrs,
)
# analysis_test(
# name = name,
# impl = lambda env, target: impl(env),
# target = _TARGET,
# attrs = attrs,

# )
14 changes: 7 additions & 7 deletions lib/unittest.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Unit testing support.
Unlike most Skylib files, this exports four modules:
This exports four modules:
* `unittest` contains functions to declare and define unit tests for ordinary
Starlark functions;
* `analysistest` contains functions to declare and define tests for analysis
Expand All @@ -28,20 +28,20 @@ See https://bazel.build/extending/concepts for background about macros, rules,
and the different phases of a build.
"""

load("@bazel_skylib//lib:new_sets.bzl", new_sets = "sets")
load("@bazel_skylib//lib:partial.bzl", "partial")
load("@bazel_skylib//lib:types.bzl", "types")
load("//@bazel_skylib/lib:new_sets.bzl", new_sets = "sets")
load("//@bazel_skylib/lib:partial.bzl", "partial")
load("//@bazel_skylib/lib:types.bzl", "types")

# The following function should only be called from WORKSPACE files and workspace macros.
# buildifier: disable=unnamed-macro
def register_unittest_toolchains():
"""Registers the toolchains for unittest users."""
native.register_toolchains(
"@bazel_skylib//toolchains/unittest:cmd_toolchain",
"@bazel_skylib//toolchains/unittest:bash_toolchain",
"//tests/unittest_toolchains:cmd_toolchain",
"//tests/unittest_toolchains:bash_toolchain",
)

TOOLCHAIN_TYPE = "@bazel_skylib//toolchains/unittest:toolchain_type"
TOOLCHAIN_TYPE = "//tests/unittest_toolchains:toolchain_type"

_UnittestToolchainInfo = provider(
doc = "Execution platform information for rules in the bazel_skylib repository.",
Expand Down
6 changes: 3 additions & 3 deletions lib/util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
Various utilities to aid with testing.
"""

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//lib:types.bzl", "types")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("//@bazel_skylib/lib:paths.bzl", "paths")
load("//@bazel_skylib/lib:types.bzl", "types")
load("//@bazel_skylib/rules:write_file.bzl", "write_file")
load("//lib:unittest.bzl", "analysistest")

_SKIP_CI_TAGS = [
Expand Down
27 changes: 24 additions & 3 deletions tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("//@bazel_skylib:bzl_library.bzl", "bzl_library")
load("//@bazel_skylib/rules:build_test.bzl", "build_test")
load("//@bazel_skylib/rules:common_settings.bzl", "string_flag")
load(":analysis_test_tests.bzl", "analysis_test_test_suite")
load(":truth_tests.bzl", "truth_test_suite")
load(":unit_test_tests.bzl", "unit_test_test_suite")
Expand All @@ -41,6 +41,27 @@ bzl_library(
],
)

bzl_library(
name = "unittest_tests_bzl",
srcs = ["unittest_tests.bzl"],
visibility = ["//visibility:private"],
deps = ["//lib:unittest"],
)

sh_test(
name = "unittest_e2e_test",
srcs = ["unittest_test.sh"],
data = [
":unittest_tests_bzl",
"//bazel/src/test/shell:bashunit",
"//lib:test_deps",
"//lib:unittest.bzl",
"//tests/unittest_toolchains:test_deps",
"//third_party/bazel/tools/bash/runfiles",
],
tags = ["local"],
)

analysis_test_test_suite(name = "analysis_test_test_suite")

truth_test_suite(name = "truth_tests")
Expand Down
2 changes: 1 addition & 1 deletion tests/analysis_test_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Unit tests for analysis_test.bzl."""

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("//@bazel_skylib/rules:common_settings.bzl", "BuildSettingInfo")
load("//lib:analysis_test.bzl", "analysis_test", "test_suite")
load("//lib:truth.bzl", "matching")
load("//lib:util.bzl", "TestingAspectInfo")
Expand Down
Loading

0 comments on commit c280f09

Please sign in to comment.