Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

* `TargetSubject.provider()` and `TargetSubject.has_provider()` accept a
`provider_name` for better error messaging.

* Added `FileSubject.basename()` and `FileSubject.actual`
### Added

* Nothing yet
Expand Down
16 changes: 16 additions & 0 deletions lib/private/file_subject.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def _file_subject_new(file, meta):
# buildifier: disable=uninitialized
public = struct(
# keep sorted start
actual = file,
basename = lambda *a, **k: _file_subject_basename(self, *a, **k),
equals = lambda *a, **k: _file_subject_equals(self, *a, **k),
path = lambda *a, **k: _file_subject_path(self, *a, **k),
short_path_equals = lambda *a, **k: _file_subject_short_path_equals(self, *a, **k),
Expand All @@ -40,6 +42,19 @@ def _file_subject_new(file, meta):
self = struct(file = file, meta = meta, public = public)
return public

def _file_subject_basename(self):
"""Returns a `StrSubject` asserting on the files `basename` value.

Method: FileSubject.basename

Returns:
[`StrSubject`] object.
"""
return StrSubject.new(
self.file.basename,
meta = self.meta.derive("basename()"),
)

def _file_subject_equals(self, expected):
"""Asserts that `expected` references the same file as `self`.

Expand Down Expand Up @@ -100,5 +115,6 @@ FileSubject = struct(
new = _file_subject_new,
equals = _file_subject_equals,
path = _file_subject_path,
basename = _file_subject_basename,
short_path_equals = _file_subject_short_path_equals,
)
1 change: 1 addition & 0 deletions tests/truth_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ def _file_subject_test(env, target):
expect = truth.expect(fake_env)
subject = expect.that_file(target.files.to_list()[0])
subject.short_path_equals(package + "/testdata/file1.txt")
subject.basename().equals("file1.txt")
_assert_no_failures(fake_env, env = env)

subject.short_path_equals("landon-and-hope-forever.txt")
Expand Down
Loading