aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKevin Kress <kkress@gmail.com>2022-02-10 13:03:48 -0800
committerGitHub <noreply@github.com>2022-02-10 16:03:48 -0500
commit7270e3b345371c1b6bbb65f5598dcac48b3593bd (patch)
tree9b0756cf894537b786e7c7bfafd612b09b41d6e9 /tests
parent1e1c324391d81b3c768e4a11e50106929953f348 (diff)
downloadbazel-skylib-7270e3b345371c1b6bbb65f5598dcac48b3593bd.tar.gz
Add support for 'loading' unit tests, which evaluate a LOADING phase. (#347)
This is a relatively simple addition to unittest that statically creates rules that either explicitly fail or not depending on if the test case is valid during LOADING phase of bazel. The test conditions are evaluated entirely in loading phase, but if we want an actual test to fail rather than just `fail()` killing the build, we can use this to assert state and report test failures.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest_tests.bzl12
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/unittest_tests.bzl b/tests/unittest_tests.bzl
index 47dcee0..2f326a0 100644
--- a/tests/unittest_tests.bzl
+++ b/tests/unittest_tests.bzl
@@ -15,7 +15,7 @@
"""Unit tests for unittest.bzl."""
load("//lib:partial.bzl", "partial")
-load("//lib:unittest.bzl", "analysistest", "asserts", "unittest")
+load("//lib:unittest.bzl", "analysistest", "asserts", "loadingtest", "unittest")
###################################
####### basic_failing_test ########
@@ -308,6 +308,13 @@ inspect_output_dirs_test = analysistest.make(
},
)
+def _loading_phase_test(env):
+ loadingtest.equals(env, "self_glob", ["unittest_tests.bzl"], native.glob(["unittest_tests.bzl"]))
+
+ # now use our own calls to assert we created a test case rule and test_suite for it.
+ loadingtest.equals(env, "test_exists", True, native.existing_rule(env.name + "_self_glob") != None)
+ loadingtest.equals(env, "suite_exists", True, native.existing_rule(env.name + "_tests") != None)
+
#########################################
# buildifier: disable=unnamed-macro
@@ -377,3 +384,6 @@ def unittest_passing_tests_suite():
name = "inspect_output_dirs_fake_target",
tags = ["manual"],
)
+
+ loading_env = loadingtest.make("selftest")
+ _loading_phase_test(loading_env)