mirror of
https://github.com/facebook/sapling.git
synced 2025-01-06 04:43:19 +03:00
Refactor GlobTest into finer-grained tests.
Summary: I think this makes it easier to reason about the coverage of the space of inputs to `glob()`. Reviewed By: chadaustin Differential Revision: D7741509 fbshipit-source-id: 5882d859df95279189512716004263dd5320ff3f
This commit is contained in:
parent
a24cffb99b
commit
bc16b45635
@ -15,16 +15,11 @@ from .lib import testcase
|
||||
class GlobTest(testcase.EdenRepoTest):
|
||||
def populate_repo(self) -> None:
|
||||
self.repo.write_file('hello', 'hola\n')
|
||||
self.repo.write_file('README', 'docs\n')
|
||||
self.repo.write_file('adir/file', 'foo!\n')
|
||||
self.repo.write_file('bdir/file', 'bar!\n')
|
||||
self.repo.symlink('slink', 'hello')
|
||||
self.commit1 = self.repo.commit('Initial commit.')
|
||||
|
||||
self.repo.write_file('bdir/file', 'bar?\n')
|
||||
self.repo.write_file('cdir/subdir/new.txt', 'and improved')
|
||||
self.repo.remove_file('README')
|
||||
self.commit2 = self.repo.commit('Commit 2.')
|
||||
self.repo.commit('Commit 1.')
|
||||
|
||||
def setUp(self) -> None:
|
||||
super().setUp()
|
||||
@ -32,37 +27,50 @@ class GlobTest(testcase.EdenRepoTest):
|
||||
self.client.open()
|
||||
self.addCleanup(self.client.close)
|
||||
|
||||
def test_glob(self) -> None:
|
||||
def test_exact_path_component_match(self) -> None:
|
||||
self.assertEqual(['hello'], self.client.glob(self.mount, ['hello']))
|
||||
|
||||
def test_wildcard_path_component_match(self) -> None:
|
||||
self.assertEqual(['hello'], self.client.glob(self.mount, ['hel*']))
|
||||
self.assertEqual(['adir'], self.client.glob(self.mount, ['ad*']))
|
||||
self.assertEqual(
|
||||
['adir/file'], self.client.glob(self.mount, ['a*/file'])
|
||||
)
|
||||
self.assertCountEqual(
|
||||
['adir/file', 'bdir/file'],
|
||||
self.client.glob(self.mount, ['**/file'])
|
||||
|
||||
def test_no_accidental_substring_match(self) -> None:
|
||||
self.assertEqual(
|
||||
[],
|
||||
self.client.glob(self.mount, ['hell']),
|
||||
msg='No accidental substring match'
|
||||
)
|
||||
|
||||
def test_match_all_files_in_directory(self) -> None:
|
||||
self.assertEqual(
|
||||
['adir/file'], self.client.glob(self.mount, ['adir/*'])
|
||||
)
|
||||
|
||||
def test_overlapping_globs(self) -> None:
|
||||
self.assertCountEqual(
|
||||
['adir/file', 'bdir/file'],
|
||||
self.client.glob(self.mount, ['adir/*', '**/file']),
|
||||
msg='De-duplicate results from multiple globs'
|
||||
)
|
||||
self.assertEqual(['hello'], self.client.glob(self.mount, ['hello']))
|
||||
self.assertEqual(
|
||||
[],
|
||||
self.client.glob(self.mount, ['hell']),
|
||||
msg="No accidental substring match"
|
||||
)
|
||||
self.assertEqual(['hello'], self.client.glob(self.mount, ['hel*']))
|
||||
self.assertEqual(['adir'], self.client.glob(self.mount, ['ad*']))
|
||||
self.assertEqual(
|
||||
['adir/file'], self.client.glob(self.mount, ['adir/**/*'])
|
||||
|
||||
def test_recursive_wildcard_prefix(self) -> None:
|
||||
self.assertCountEqual(
|
||||
['adir/file', 'bdir/file'],
|
||||
self.client.glob(self.mount, ['**/file'])
|
||||
)
|
||||
|
||||
def test_recursive_wildcard_suffix(self) -> None:
|
||||
self.assertEqual(
|
||||
['adir/file'], self.client.glob(self.mount, ['adir/**'])
|
||||
)
|
||||
self.assertEqual(
|
||||
['adir/file'], self.client.glob(self.mount, ['adir/**/*'])
|
||||
)
|
||||
|
||||
def test_malformed_query(self) -> None:
|
||||
with self.assertRaises(EdenError) as ctx:
|
||||
self.client.glob(self.mount, ['adir['])
|
||||
self.assertIn('unterminated bracket sequence', str(ctx.exception))
|
||||
|
Loading…
Reference in New Issue
Block a user