mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 22:37:37 +03:00
Update Hg integration tests to use assert_status().
Summary: `HgExtensionTestBase.assert_status()` was added in D4814422, but it was only applied to `update_test.py`. This change updates the docstring (it appears to have been copy/pasted from a nearby method), and makes use of it in the other integration tests. Reviewed By: wez Differential Revision: D5050775 fbshipit-source-id: bb70740b6f455a84e7a22c3286c8ddbe2462f816
This commit is contained in:
parent
460ec77a8b
commit
f766fe0a87
@ -21,37 +21,55 @@ class AddTest(HgExtensionTestBase):
|
||||
self.touch('dir1/b.txt')
|
||||
self.mkdir('dir2')
|
||||
self.touch('dir2/c.txt')
|
||||
self.assertEqual('? dir1/b.txt\n? dir2/c.txt\n', self.status())
|
||||
self.assert_status({
|
||||
'dir1/b.txt': '?',
|
||||
'dir2/c.txt': '?',
|
||||
})
|
||||
|
||||
# `hg add dir2` should ensure only things under dir2 are added.
|
||||
self.hg('add', 'dir2')
|
||||
self.assertEqual('A dir2/c.txt\n? dir1/b.txt\n', self.status())
|
||||
self.assert_status({
|
||||
'dir1/b.txt': '?',
|
||||
'dir2/c.txt': 'A',
|
||||
})
|
||||
|
||||
# This is the equivalent of `hg forget dir1/a.txt`.
|
||||
self.hg('rm', '--force', 'dir1/a.txt')
|
||||
self.write_file('dir1/a.txt', 'original contents')
|
||||
self.touch('dir1/a.txt')
|
||||
self.assertEqual('A dir2/c.txt\nR dir1/a.txt\n? dir1/b.txt\n',
|
||||
self.status())
|
||||
self.assert_status({
|
||||
'dir1/a.txt': 'R',
|
||||
'dir1/b.txt': '?',
|
||||
'dir2/c.txt': 'A',
|
||||
})
|
||||
|
||||
# Running `hg add .` should remove the removal marker from dir1/a.txt
|
||||
# because dir1/a.txt is still on disk.
|
||||
self.hg('add')
|
||||
self.assertEqual('A dir1/b.txt\nA dir2/c.txt\n', self.status())
|
||||
self.assert_status({
|
||||
'dir1/b.txt': 'A',
|
||||
'dir2/c.txt': 'A',
|
||||
})
|
||||
|
||||
self.hg('rm', 'dir1/a.txt')
|
||||
self.write_file('dir1/a.txt', 'different contents')
|
||||
# Running `hg add dir1` should remove the removal marker from
|
||||
# dir1/a.txt, but `hg status` should also reflect that it is modified.
|
||||
self.hg('add', 'dir1')
|
||||
self.assertEqual('M dir1/a.txt\nA dir1/b.txt\nA dir2/c.txt\n',
|
||||
self.status())
|
||||
self.assert_status({
|
||||
'dir1/a.txt': 'M',
|
||||
'dir1/b.txt': 'A',
|
||||
'dir2/c.txt': 'A',
|
||||
})
|
||||
|
||||
self.hg('rm', '--force', 'dir1/a.txt')
|
||||
# This should not add dir1/a.txt back because it is not on disk.
|
||||
self.hg('add', 'dir1')
|
||||
self.assertEqual('A dir1/b.txt\nA dir2/c.txt\nR dir1/a.txt\n',
|
||||
self.status())
|
||||
self.assert_status({
|
||||
'dir1/a.txt': 'R',
|
||||
'dir1/b.txt': 'A',
|
||||
'dir2/c.txt': 'A',
|
||||
})
|
||||
|
||||
with self.assertRaises(subprocess.CalledProcessError) as context:
|
||||
self.hg('add', 'dir3')
|
||||
|
@ -121,7 +121,12 @@ class HgExtensionTestBase(testcase.EdenTestCase):
|
||||
return self.repo.status()
|
||||
|
||||
def assert_status(self, expected, msg=None, check_ignored=True):
|
||||
'''Returns the output of `hg status` as a string.'''
|
||||
'''Asserts the output of `hg status`. `expected` is a dict where keys
|
||||
are paths relative to the repo root and values are the single-character
|
||||
string that represents the status: 'M', 'A', 'R', '!', '?', 'I'.
|
||||
|
||||
'C' is not currently supported.
|
||||
'''
|
||||
args = ['status', '--print0']
|
||||
if check_ignored:
|
||||
args.append('-mardui')
|
||||
|
@ -17,26 +17,29 @@ class StatusTest(HgExtensionTestBase):
|
||||
|
||||
def test_status(self):
|
||||
'''Test various `hg status` states in the root of an Eden mount.'''
|
||||
empty_status = self.status()
|
||||
self.assertEqual('', empty_status)
|
||||
self.assert_status_empty()
|
||||
|
||||
self.touch('world.txt')
|
||||
untracked_status = self.status()
|
||||
self.assertEqual('? world.txt\n', untracked_status)
|
||||
self.assert_status({'world.txt': '?'})
|
||||
|
||||
self.hg('add', 'world.txt')
|
||||
added_status = self.status()
|
||||
self.assertEqual('A world.txt\n', added_status)
|
||||
self.assert_status({'world.txt': 'A'})
|
||||
|
||||
self.rm('hello.txt')
|
||||
missing_status = self.status()
|
||||
self.assertEqual('A world.txt\n! hello.txt\n', missing_status)
|
||||
self.assert_status({
|
||||
'hello.txt': '!',
|
||||
'world.txt': 'A',
|
||||
})
|
||||
|
||||
with open(self.get_path('hello.txt'), 'w') as f:
|
||||
f.write('new contents')
|
||||
modified_status = self.status()
|
||||
self.assertEqual('M hello.txt\nA world.txt\n', modified_status)
|
||||
self.assert_status({
|
||||
'hello.txt': 'M',
|
||||
'world.txt': 'A',
|
||||
})
|
||||
|
||||
self.hg('rm', '--force', 'hello.txt')
|
||||
removed_status = self.status()
|
||||
self.assertEqual('A world.txt\nR hello.txt\n', removed_status)
|
||||
self.assert_status({
|
||||
'hello.txt': 'R',
|
||||
'world.txt': 'A',
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user