Skip to content

Commit

Permalink
- avoid false negative failures due to trivial differences in diff hu…
Browse files Browse the repository at this point in the history
…nk headers

  When a hunk header refers to a single line in the "from"
  file and/or the "to" file, e.g.

    @@ -37,37 +41,43 @@
    @@ -37,39 +41,41 @@
    @@ -37,37 +41,41 @@

  some systems will avoid repeating the line number:

    @@ -37 +41,43 @@
    @@ -37,39 +41 @@
    @@ -37 +41 @@

  so we need to canonise the output to avoid false negative
  test failures.
  • Loading branch information
aspiers committed Jan 18, 2013
1 parent 479f5d5 commit ef0f24c
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions tests/test_difffiles.py
@@ -1,6 +1,7 @@
import osc.core
import osc.oscerr
import os
import re
from common import GET, OscTestCase

FIXTURES_DIR = os.path.join(os.getcwd(), 'difffile_fixtures')
Expand Down Expand Up @@ -294,18 +295,42 @@ def testDiffRemoteMissingLocalDeleted(self):
p = osc.core.Package('.')
self.__check_diff(p, '', 3)

def __check_diff(self, p, expected, revision=None):
def __check_diff(self, p, exp, revision=None):
got = ''
for i in p.get_diff(revision):
got += ''.join(i)
if (got + expected).find('\n') == -1:
self.assertEqual(got, expected)

# When a hunk header refers to a single line in the "from"
# file and/or the "to" file, e.g.
#
# @@ -37,37 +41,43 @@
# @@ -37,39 +41,41 @@
# @@ -37,37 +41,41 @@
#
# some systems will avoid repeating the line number:
#
# @@ -37 +41,43 @@
# @@ -37,39 +41 @@
# @@ -37 +41 @@
#
# so we need to canonise the output to avoid false negative
# test failures.
def __canonise_diff(diff):
diff = re.sub('^@@ -(\d+) ', '@@ -\\1,\\1 ', diff, 0, re.MULTILINE)
diff = re.sub('^(@@ -\d+,\d+) \+(\d+) ', '\\1 +\\2,\\2 ', diff, 0, re.MULTILINE)
return diff

got = __canonise_diff(got)
exp = __canonise_diff(exp)

if (got + exp).find('\n') == -1:
self.assertEqual(got, exp)
else:
start_delim = "\n" + (" 8< ".join(["-----"] * 8)) + "\n"
end_delim = "\n" + (" >8 ".join(["-----"] * 8)) + "\n\n"
self.assertEqual(got, expected,
self.assertEqual(got, exp,
"got:" + start_delim + got + end_delim +
"expected:" + start_delim + expected + end_delim)
"expected:" + start_delim + exp + end_delim)

if __name__ == '__main__':
import unittest
Expand Down

0 comments on commit ef0f24c

Please sign in to comment.