Author: dannas
Date: Fri Jul 30 07:09:57 2010
New Revision: 980665
URL: http://svn.apache.org/viewvc?rev=980665&view=rev
Log:
Add a test for applying patches with offset searching.
The test is a copy-paste of the existing patch_test nr 3,
patch_offset(), adjusted to use properties instead of text.
* subversion/tests/cmdline/patch_tests.py
(patch_prop_offset): New
(test_list): Add the new test.
Modified:
subversion/trunk/subversion/tests/cmdline/patch_tests.py
Modified: subversion/trunk/subversion/tests/cmdline/patch_tests.py
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/patch_tests.py?rev=980665&r1=980664&r2=980665&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/patch_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/patch_tests.py Fri Jul 30
07:09:57 2010
@@ -2598,6 +2598,219 @@ def patch_add_path_with_props(sbox):
1, # check-props
1) # dry-run
+def patch_prop_offset(sbox):
+ "property patch with offset searching"
+
+ sbox.build()
+ wc_dir = sbox.wc_dir
+
+ patch_file_path = make_patch_path(sbox)
+ iota_path = os.path.join(wc_dir, 'iota')
+
+ prop1_content = ''.join([
+ "Dear internet user,\n",
+ # The missing line here will cause the first hunk to match early
+ "We wish to congratulate you over your email success in our computer\n",
+ "Balloting. This is a Millennium Scientific Electronic Computer Draw\n",
+ "in which email addresses were used. All participants were selected\n",
+ "through a computer ballot system drawn from over 100,000 company\n",
+ "and 50,000,000 individual email addresses from all over the world.\n",
+ "\n",
+ "Your email address drew and have won the sum of 750,000 Euros\n",
+ "( Seven Hundred and Fifty Thousand Euros) in cash credited to\n",
+ "file with\n",
+ " REFERENCE NUMBER: ESP/WIN/008/05/10/MA;\n",
+ "These extra lines will cause the second hunk to match late\n",
+ "These extra lines will cause the second hunk to match late\n",
+ "These extra lines will cause the second hunk to match late\n",
+ "These extra lines will cause the second hunk to match late\n",
+ "These extra lines will cause the second hunk to match late\n",
+ " WINNING NUMBER : 14-17-24-34-37-45-16\n",
+ " BATCH NUMBERS :\n",
+ " EULO/1007/444/606/08;\n",
+ " SERIAL NUMBER: 45327\n",
+ "and PROMOTION DATE: 13th June. 2009\n",
+ "\n",
+ "To claim your winning prize, you are to contact the appointed\n",
+ "agent below as soon as possible for the immediate release of your\n",
+ "winnings with the below details.\n",
+ "\n",
+ "Again, we wish to congratulate you over your email success in our\n"
+ "computer Balloting.\n",
+ ])
+
+ # prop2's content will make both a late and early match possible.
+ # The hunk to be applied is replicated here for reference:
+ # ## -5,6 +5,7 ##
+ # property
+ # property
+ # property
+ # +x
+ # property
+ # property
+ # property
+ #
+ # This hunk wants to be applied at line 5, but that isn't
+ # possible because line 8 ("zzz") does not match "property".
+ # The early match happens at line 2 (offset 3 = 5 - 2).
+ # The late match happens at line 9 (offset 4 = 9 - 5).
+ # Subversion will pick the early match in this case because it
+ # is closer to line 5.
+ prop2_content = ''.join([
+ "property\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "zzz\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "property\n"
+ ])
+
+ # Set iota prop contents
+ svntest.main.run_svn(None, 'propset', 'prop1', prop1_content,
+ iota_path)
+ svntest.main.run_svn(None, 'propset', 'prop2', prop2_content,
+ iota_path)
+ expected_output = svntest.wc.State(wc_dir, {
+ 'iota' : Item(verb='Sending'),
+ })
+ expected_status = svntest.actions.get_virginal_state(wc_dir, 1)
+ expected_status.tweak('iota', wc_rev=2)
+ svntest.actions.run_and_verify_commit(wc_dir, expected_output,
+ expected_status, None, wc_dir)
+
+ # Apply patch
+
+ unidiff_patch = [
+ "Index: iota\n",
+ "===================================================================\n",
+ "--- iota (revision XYZ)\n",
+ "+++ iota (working copy)\n",
+ "\n",
+ "Property changes on: iota\n",
+ "-------------------------------------------------------------------\n",
+ "Modified: prop1\n",
+ "## -6,6 +6,9 ##\n",
+ " through a computer ballot system drawn from over 100,000 company\n",
+ " and 50,000,000 individual email addresses from all over the world.\n",
+ " \n",
+ "+It is a promotional program aimed at encouraging internet users;\n",
+ "+therefore you do not need to buy ticket to enter for it.\n",
+ "+\n",
+ " Your email address drew and have won the sum of 750,000 Euros\n",
+ " ( Seven Hundred and Fifty Thousand Euros) in cash credited to\n",
+ " file with\n",
+ "## -14,11 +17,8 ##\n",
+ " BATCH NUMBERS :\n",
+ " EULO/1007/444/606/08;\n",
+ " SERIAL NUMBER: 45327\n",
+ "-and PROMOTION DATE: 13th June. 2009\n",
+ "+and PROMOTION DATE: 14th June. 2009\n",
+ " \n",
+ " To claim your winning prize, you are to contact the appointed\n",
+ " agent below as soon as possible for the immediate release of your\n",
+ " winnings with the below details.\n",
+ "-\n",
+ "-Again, we wish to congratulate you over your email success in our\n",
+ "-computer Balloting.\n",
+ "Modified: prop2\n",
+ "## -5,6 +5,7 ##\n",
+ " property\n",
+ " property\n",
+ " property\n",
+ "+x\n",
+ " property\n",
+ " property\n",
+ " property\n",
+ ]
+
+ svntest.main.file_write(patch_file_path, ''.join(unidiff_patch))
+
+ prop1_content = ''.join([
+ "Dear internet user,\n",
+ "We wish to congratulate you over your email success in our computer\n",
+ "Balloting. This is a Millennium Scientific Electronic Computer Draw\n",
+ "in which email addresses were used. All participants were selected\n",
+ "through a computer ballot system drawn from over 100,000 company\n",
+ "and 50,000,000 individual email addresses from all over the world.\n",
+ "\n",
+ "It is a promotional program aimed at encouraging internet users;\n",
+ "therefore you do not need to buy ticket to enter for it.\n",
+ "\n",
+ "Your email address drew and have won the sum of 750,000 Euros\n",
+ "( Seven Hundred and Fifty Thousand Euros) in cash credited to\n",
+ "file with\n",
+ " REFERENCE NUMBER: ESP/WIN/008/05/10/MA;\n",
+ "These extra lines will cause the second hunk to match late\n",
+ "These extra lines will cause the second hunk to match late\n",
+ "These extra lines will cause the second hunk to match late\n",
+ "These extra lines will cause the second hunk to match late\n",
+ "These extra lines will cause the second hunk to match late\n",
+ " WINNING NUMBER : 14-17-24-34-37-45-16\n",
+ " BATCH NUMBERS :\n",
+ " EULO/1007/444/606/08;\n",
+ " SERIAL NUMBER: 45327\n",
+ "and PROMOTION DATE: 14th June. 2009\n",
+ "\n",
+ "To claim your winning prize, you are to contact the appointed\n",
+ "agent below as soon as possible for the immediate release of your\n",
+ "winnings with the below details.\n",
+ ])
+
+ prop2_content = ''.join([
+ "property\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "x\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "zzz\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ "property\n",
+ ])
+
+ os.chdir(wc_dir)
+
+ expected_output = [
+ ' U iota\n',
+ '> applied hunk ## -6,6 +6,9 ## with offset -1 (prop1)\n',
+ '> applied hunk ## -14,11 +17,8 ## with offset 4 (prop1)\n',
+ '> applied hunk ## -5,6 +5,7 ## with offset -3 (prop2)\n',
+ ]
+
+ expected_disk = svntest.main.greek_state.copy()
+ expected_disk.tweak('iota', props = {'prop1' : prop1_content,
+ 'prop2' : prop2_content})
+
+ expected_status = svntest.actions.get_virginal_state('.', 1)
+ expected_status.tweak('iota', status=' M', wc_rev=2)
+
+ expected_skip = wc.State('', { })
+
+ svntest.actions.run_and_verify_patch('.', os.path.abspath(patch_file_path),
+ expected_output,
+ expected_disk,
+ expected_status,
+ expected_skip,
+ None, # expected err
+ 1, # check-props
+ 1) # dry-run
+
########################################################################
#Run the tests
@@ -2625,6 +2838,7 @@ test_list = [ None,
patch_same_twice,
XFail(patch_dir_properties),
XFail(patch_add_path_with_props),
+ patch_prop_offset,
]
if __name__ == '__main__':