tests: add DepsetFileSubject.not_contains test
This is to prevent regressions as found by the latest refactoring.
* Also fixes a bug in the test's `_assert_failure` function: it was
using Skylib's unittest.bzl assert functions, which assume a
unittest.bzl-style `env` value, and would error because
the `env.failures` attribute was removed a few changes ago. Fixed
by switching it to use the rule_testing analysis_test-created env
object `env.fail` api to register failures.
PiperOrigin-RevId: 518812864
diff --git a/tests/truth_tests.bzl b/tests/truth_tests.bzl
index 738b837..77d57b4 100644
--- a/tests/truth_tests.bzl
+++ b/tests/truth_tests.bzl
@@ -814,6 +814,20 @@
env = env,
)
+ subject.not_contains("does-not-contain")
+ _assert_no_failures(
+ fake_env,
+ env = env,
+ msg = "DepsetFilesubject.not_contains success test",
+ )
+ subject.not_contains("{package}/testdata/file1.txt")
+ _assert_failure(
+ fake_env,
+ ["expected not to contain any of", "file1.txt"],
+ env = env,
+ msg = "DepsetFilesubject.not_contains failure test",
+ )
+
_end(env, fake_env)
_suite.append(depset_file_subject_test)
@@ -1305,27 +1319,25 @@
fake_env.reset()
def _assert_failure(fake_env, expected_strs, *, env, msg = ""):
- ut_asserts.true(
- env,
- len(fake_env.failures) == 1,
- msg = "expected exactly 1 failure, but found none",
- )
+ if len(fake_env.failures) != 1:
+ env.fail("expected exactly 1 failure, but found {}".format(len(fake_env.failures)))
+
if len(fake_env.failures) > 0:
failure = fake_env.failures[0]
for expected in expected_strs:
- ut_asserts.true(
- env,
- expected in failure,
- msg = ("\nFailure message incorrect:\n{}\n" +
- "===== EXPECTED ERROR SUBSTRING =====\n{}\n" +
- "===== END EXPECTED ERROR SUBSTRING =====\n" +
- "===== ACTUAL FAILURE MESSAGE =====\n{}\n" +
- "===== END ACTUAL FAILURE MESSAGE =====").format(
+ if expected not in failure:
+ env.fail((
+ "\nFailure message incorrect:\n{}\n" +
+ "===== EXPECTED ERROR SUBSTRING =====\n{}\n" +
+ "===== END EXPECTED ERROR SUBSTRING =====\n" +
+ "===== ACTUAL FAILURE MESSAGE =====\n{}\n" +
+ "===== END ACTUAL FAILURE MESSAGE ====="
+ ).format(
msg,
expected,
failure,
- ),
- )
+ ))
+
fake_env.reset()
def _test_helper_impl(ctx):