changeset 138:40474f6c1f84

diff_cmd: more robust, add tests.
author Augie Fackler <durin42@gmail.com>
date Thu, 11 Dec 2008 19:49:36 -0600
parents 904a4b08f70f
children 89a737852d33
files diff_cmd.py tests/test_diff.py tests/test_fetch_command.py tests/test_util.py
diffstat 4 files changed, 51 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/diff_cmd.py
+++ b/diff_cmd.py
@@ -37,6 +37,13 @@ def diff_command(ui, repo, hg_repo_path,
     if o_r:
         parent = repo[o_r[-1]].parents()[0]
     base_rev, _junk = svn_commit_hashes[parent.node()]
-    it = patch.diff(repo, parent.node(), None, 
-                    opts=patch.diffopts(ui, opts))
+    it = patch.diff(repo, parent.node(), None,
+                    opts=patch.diffopts(ui, opts={'git': True,
+                                                  'show_function': False,
+                                                  'ignore_all_space': False,
+                                                  'ignore_space_change': False,
+                                                  'ignore_blank_lines': False,
+                                                  'unified': True,
+                                                  'text': False,
+                                                  }))
     ui.write(filterdiff(''.join(it), base_rev))
new file mode 100644
--- /dev/null
+++ b/tests/test_diff.py
@@ -0,0 +1,34 @@
+from mercurial import ui
+
+import diff_cmd
+
+import test_util
+
+expected_diff_output = '''Index: alpha
+===================================================================
+--- alpha\t(revision 3)
++++ alpha\t(working copy)
+@@ -1,1 +1,3 @@
+-file: alpha
++alpha
++
++added line
+Index: foo
+===================================================================
+new file mode 100644
+--- foo\t(revision 0)
++++ foo\t(working copy)
+@@ -0,0 +1,1 @@
++This is missing a newline.
+\ No newline at end of file
+'''
+
+class DiffTests(test_util.TestBase):
+    def test_diff_output(self):
+        self._load_fixture_and_fetch('two_revs.svndump')
+        self.commitchanges([('foo', 'foo', 'This is missing a newline.'),
+                            ('alpha', 'alpha', 'alpha\n\nadded line\n'),
+                            ])
+        u = ui.ui()
+        diff_cmd.diff_command(u, self.repo, self.wc_path)
+        self.assertEqual(u.stream.getvalue(), expected_diff_output)
--- a/tests/test_fetch_command.py
+++ b/tests/test_fetch_command.py
@@ -8,11 +8,6 @@ import test_util
 
 
 class TestBasicRepoLayout(test_util.TestBase):
-    def _load_fixture_and_fetch(self, fixture_name, subdir='', stupid=False):
-        return test_util.load_fixture_and_fetch(fixture_name, self.repo_path,
-                                                self.wc_path, subdir=subdir,
-                                                stupid=stupid)
-
     def test_fresh_fetch_single_rev(self):
         repo = self._load_fixture_and_fetch('single_rev.svndump')
         self.assertEqual(node.hex(repo['tip'].node()),
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -80,6 +80,9 @@ class MockUI(object):
     def warn(self, *args):
         self.stream.write(*args)
 
+    def write(self, *args):
+        self.stream.write(*args)
+
     def __getattr__(self, attr):
         return getattr(self.inner_ui, attr)
 
@@ -98,6 +101,11 @@ class TestBase(unittest.TestCase):
         os.chdir(self.oldwd)
         ui.ui = self._real_ui
 
+    def _load_fixture_and_fetch(self, fixture_name, subdir='', stupid=False):
+        return load_fixture_and_fetch(fixture_name, self.repo_path,
+                                      self.wc_path, subdir=subdir,
+                                      stupid=stupid)
+
     # define this as a property so that it reloads anytime we need it
     @property
     def repo(self):