aboutsummaryrefslogtreecommitdiff
path: root/tests/unittest_tests.bzl
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittest_tests.bzl')
-rw-r--r--tests/unittest_tests.bzl119
1 files changed, 113 insertions, 6 deletions
diff --git a/tests/unittest_tests.bzl b/tests/unittest_tests.bzl
index 3d5a198..2f326a0 100644
--- a/tests/unittest_tests.bzl
+++ b/tests/unittest_tests.bzl
@@ -14,11 +14,13 @@
"""Unit tests for unittest.bzl."""
-load("//lib:unittest.bzl", "analysistest", "asserts", "unittest")
+load("//lib:partial.bzl", "partial")
+load("//lib:unittest.bzl", "analysistest", "asserts", "loadingtest", "unittest")
###################################
-####### fail_basic_test ###########
+####### basic_failing_test ########
###################################
+
def _basic_failing_test(ctx):
"""Unit tests for a basic library verification test that fails."""
env = unittest.begin(ctx)
@@ -30,6 +32,27 @@ def _basic_failing_test(ctx):
basic_failing_test = unittest.make(_basic_failing_test)
###################################
+####### failure_message_test ######
+###################################
+
+def _failure_message_test(ctx):
+ """Failing unit test with arbitrary content in the message."""
+ env = unittest.begin(ctx)
+
+ if not ctx.attr.message:
+ unittest.fail(env, "Message must be non-empty.")
+ asserts.equals(env, "", ctx.attr.message)
+
+ return unittest.end(env)
+
+failure_message_test = unittest.make(
+ _failure_message_test,
+ attrs = {
+ "message": attr.string(),
+ },
+)
+
+###################################
####### basic_passing_test ########
###################################
def _basic_passing_test(ctx):
@@ -42,6 +65,19 @@ def _basic_passing_test(ctx):
basic_passing_test = unittest.make(_basic_passing_test)
+#################################################
+####### basic_passing_short_timeout_test ########
+#################################################
+def _basic_passing_short_timeout_test(ctx):
+ """Unit tests for a basic library verification test."""
+ env = unittest.begin(ctx)
+
+ asserts.equals(env, ctx.attr.timeout, "short")
+
+ return unittest.end(env)
+
+basic_passing_short_timeout_test = unittest.make(_basic_passing_short_timeout_test)
+
###################################
####### change_setting_test #######
###################################
@@ -54,7 +90,10 @@ def _change_setting_test(ctx):
return analysistest.end(env)
-_ChangeSettingInfo = provider()
+_ChangeSettingInfo = provider(
+ doc = "min_os_version for change_setting_test",
+ fields = ["min_os_version"],
+)
def _change_setting_fake_rule(ctx):
return [_ChangeSettingInfo(min_os_version = ctx.fragments.cpp.minimum_os_version())]
@@ -83,7 +122,7 @@ def _failure_testing_test(ctx):
return analysistest.end(env)
def _failure_testing_fake_rule(ctx):
- ignore = [ctx]
+ _ignore = [ctx] # @unused
fail("This rule should never work")
failure_testing_fake_rule = rule(
@@ -107,7 +146,7 @@ def _fail_unexpected_passing_test(ctx):
return analysistest.end(env)
def _fail_unexpected_passing_fake_rule(ctx):
- _ignore = [ctx]
+ _ignore = [ctx] # @unused
return []
fail_unexpected_passing_fake_rule = rule(
@@ -177,10 +216,58 @@ inspect_actions_test = analysistest.make(
_inspect_actions_test,
)
+####################################
+####### inspect_aspect_test #######
+####################################
+_AddedByAspectInfo = provider(
+ doc = "Example provider added by example aspect",
+ fields = {
+ "value": "(str)",
+ },
+)
+
+def _example_aspect_impl(target, ctx):
+ _ignore = [target, ctx] # @unused
+ return [
+ _AddedByAspectInfo(value = "attached by aspect"),
+ ]
+
+example_aspect = aspect(
+ implementation = _example_aspect_impl,
+)
+
+def _inspect_aspect_test(ctx):
+ """Test verifying aspect run on a target."""
+ env = analysistest.begin(ctx)
+
+ tut = env.ctx.attr.target_under_test
+ asserts.equals(env, "attached by aspect", tut[_AddedByAspectInfo].value)
+ return analysistest.end(env)
+
+def _inspect_aspect_fake_rule(ctx):
+ out_file = ctx.actions.declare_file("out.txt")
+ ctx.actions.run_shell(
+ command = "echo 'hello' > %s" % out_file.basename,
+ outputs = [out_file],
+ )
+ return [DefaultInfo(files = depset([out_file]))]
+
+inspect_aspect_fake_rule = rule(
+ implementation = _inspect_aspect_fake_rule,
+)
+
+inspect_aspect_test = analysistest.make(
+ _inspect_aspect_test,
+ extra_target_under_test_aspects = [example_aspect],
+)
+
########################################
####### inspect_output_dirs_test #######
########################################
-_OutputDirInfo = provider(fields = ["bin_path"])
+_OutputDirInfo = provider(
+ doc = "bin_path for inspect_output_dirs_test",
+ fields = ["bin_path"],
+)
def _inspect_output_dirs_test(ctx):
"""Test verifying output directories used by a test."""
@@ -221,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
@@ -234,6 +328,7 @@ def unittest_passing_tests_suite():
unittest.suite(
"unittest_tests",
basic_passing_test,
+ partial.make(basic_passing_short_timeout_test, timeout = "short"),
)
change_setting_test(
@@ -272,6 +367,15 @@ def unittest_passing_tests_suite():
tags = ["manual"],
)
+ inspect_aspect_test(
+ name = "inspect_aspect_test",
+ target_under_test = ":inspect_aspect_fake_target",
+ )
+ inspect_aspect_fake_rule(
+ name = "inspect_aspect_fake_target",
+ tags = ["manual"],
+ )
+
inspect_output_dirs_test(
name = "inspect_output_dirs_test",
target_under_test = ":inspect_output_dirs_fake_target",
@@ -280,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)