Skip to content

Commit 20f6024

Browse files
committed
add more tests
1 parent a2d7aba commit 20f6024

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

python/private/repo_utils.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ repo_utils = struct(
535535
mkdir = _mkdir,
536536
norm_path = _norm_path,
537537
relative_to = _relative_to,
538+
is_relative_to = _is_relative_to,
538539
repo_root_relative_path = _repo_root_relative_path,
539540
which_checked = _which_checked,
540541
which_unchecked = _which_unchecked,

tests/repo_utils/repo_utils_test.bzl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,18 @@ def _test_relative_to(env):
3636
_tests.append(_test_relative_to)
3737

3838
def _test_is_relative_to(env):
39-
# Note: `_is_relative_to` isn't publicly exported in `repo_utils` struct natively.
40-
# Actually wait, `is_relative_to` is not exported by repo_utils.bzl!
41-
# Let's skip testing `_is_relative_to` directly in this suite unless we export it or we don't need to test it directly.
42-
pass
39+
mock_mrctx_linux = mocks.rctx(os_name = "linux")
40+
mock_mrctx_win = mocks.rctx(os_name = "windows")
41+
42+
# Case-sensitive matching (Linux)
43+
env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_linux, "foo/bar/baz", "foo/bar")).equals(True)
44+
env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_linux, "foo/bar/baz", "qux")).equals(False)
45+
46+
# Case-insensitive matching (Windows)
47+
env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_win, "C:/Foo/Bar/Baz", "c:/foo/bar")).equals(True)
48+
env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_win, "C:/Foo/Bar/Baz", "D:/Foo")).equals(False)
49+
50+
_tests.append(_test_is_relative_to)
4351

4452
def repo_utils_test_suite(name):
4553
"""Create the test suite.

0 commit comments

Comments
 (0)