Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Unified Diff: build/android/gyp/util/md5_check_test.py

Issue 1361733002: Make javac invocations incremental when possible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@apkbuilder
Patch Set: add flag and disable by default Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/gyp/util/md5_check.py ('k') | build/config/android/config.gni » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/gyp/util/md5_check_test.py
diff --git a/build/android/gyp/util/md5_check_test.py b/build/android/gyp/util/md5_check_test.py
index 8df8054c2b31b3e00b6a1e307844f87998003877..312d4a98cbb82a0f016c96f8301a9bf2cc1573f1 100755
--- a/build/android/gyp/util/md5_check_test.py
+++ b/build/android/gyp/util/md5_check_test.py
@@ -3,32 +3,41 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import fnmatch
import tempfile
import unittest
+import zipfile
import md5_check # pylint: disable=W0403
+def _WriteZipFile(path, entries):
+ with zipfile.ZipFile(path, 'w') as zip_file:
+ for subpath, data in entries:
+ zip_file.writestr(subpath, data)
+
+
class TestMd5Check(unittest.TestCase):
def setUp(self):
self.called = False
+ self.changes = None
def testCallAndRecordIfStale(self):
input_strings = ['string1', 'string2']
- input_file1 = tempfile.NamedTemporaryFile()
- input_file2 = tempfile.NamedTemporaryFile()
+ input_file1 = tempfile.NamedTemporaryFile(suffix='.txt')
+ input_file2 = tempfile.NamedTemporaryFile(suffix='.zip')
file1_contents = 'input file 1'
- file2_contents = 'input file 2'
input_file1.write(file1_contents)
input_file1.flush()
- input_file2.write(file2_contents)
- input_file2.flush()
+ # Test out empty zip file to start.
+ _WriteZipFile(input_file2.name, [])
input_files = [input_file1.name, input_file2.name]
record_path = tempfile.NamedTemporaryFile(suffix='.stamp')
def CheckCallAndRecord(should_call, message, force=False,
- outputs_specified=False, outputs_missing=False):
+ outputs_specified=False, outputs_missing=False,
+ expected_changes=None, added_or_modified_only=None):
output_paths = None
if outputs_specified:
output_file1 = tempfile.NamedTemporaryFile()
@@ -37,43 +46,74 @@ class TestMd5Check(unittest.TestCase):
output_paths = [output_file1.name]
self.called = False
- def MarkCalled():
- self.called = True
+ self.changes = None
+ if expected_changes or added_or_modified_only is not None:
+ def MarkCalled(changes):
+ self.called = True
+ self.changes = changes
+ else:
+ def MarkCalled():
+ self.called = True
+
md5_check.CallAndRecordIfStale(
MarkCalled,
record_path=record_path.name,
input_paths=input_files,
input_strings=input_strings,
output_paths=output_paths,
- force=force)
- self.failUnlessEqual(should_call, self.called, message)
-
- CheckCallAndRecord(True, 'should call when record doesn\'t exist')
+ force=force,
+ pass_changes=(expected_changes or added_or_modified_only) is not None)
+ self.assertEqual(should_call, self.called, message)
+ if expected_changes:
+ description = self.changes.DescribeDifference()
+ self.assertTrue(fnmatch.fnmatch(description, expected_changes),
+ 'Expected %s to match %s' % (
+ repr(description), repr(expected_changes)))
+ if should_call and added_or_modified_only is not None:
+ self.assertEqual(added_or_modified_only,
+ self.changes.AddedOrModifiedOnly())
+
+ CheckCallAndRecord(True, 'should call when record doesn\'t exist',
+ expected_changes='Previous stamp file not found.',
+ added_or_modified_only=False)
CheckCallAndRecord(False, 'should not call when nothing changed')
- CheckCallAndRecord(False, 'should not call when nothing changed2',
+ CheckCallAndRecord(False, 'should not call when nothing changed #2',
outputs_specified=True, outputs_missing=False)
CheckCallAndRecord(True, 'should call when output missing',
- outputs_specified=True, outputs_missing=True)
- CheckCallAndRecord(True, force=True, message='should call when forced')
+ outputs_specified=True, outputs_missing=True,
+ expected_changes='Outputs do not exist:*',
+ added_or_modified_only=False)
+ CheckCallAndRecord(True, force=True, message='should call when forced',
+ expected_changes='force=True',
+ added_or_modified_only=False)
input_file1.write('some more input')
input_file1.flush()
- CheckCallAndRecord(True, 'changed input file should trigger call')
+ CheckCallAndRecord(True, 'changed input file should trigger call',
+ expected_changes='*Modified: %s' % input_file1.name,
+ added_or_modified_only=True)
input_files = input_files[::-1]
CheckCallAndRecord(False, 'reordering of inputs shouldn\'t trigger call')
input_files = input_files[:1]
- CheckCallAndRecord(True, 'removing file should trigger call')
+ CheckCallAndRecord(True, 'removing file should trigger call',
+ expected_changes='*Removed: %s' % input_file1.name,
+ added_or_modified_only=False)
- input_files.append(input_file2.name)
- CheckCallAndRecord(True, 'added input file should trigger call')
+ input_files.append(input_file1.name)
+ CheckCallAndRecord(True, 'added input file should trigger call',
+ expected_changes='*Added: %s' % input_file1.name,
+ added_or_modified_only=True)
input_strings[0] = input_strings[0] + ' a bit longer'
- CheckCallAndRecord(True, 'changed input string should trigger call')
+ CheckCallAndRecord(True, 'changed input string should trigger call',
+ expected_changes='*Input strings changed*',
+ added_or_modified_only=False)
input_strings = input_strings[::-1]
- CheckCallAndRecord(True, 'reordering of string inputs should trigger call')
+ CheckCallAndRecord(True, 'reordering of string inputs should trigger call',
+ expected_changes='*Input strings changed*')
input_strings = input_strings[:1]
CheckCallAndRecord(True, 'removing a string should trigger call')
@@ -81,6 +121,24 @@ class TestMd5Check(unittest.TestCase):
input_strings.append('a brand new string')
CheckCallAndRecord(True, 'added input string should trigger call')
+ _WriteZipFile(input_file2.name, [('path/1.txt', '1')])
+ CheckCallAndRecord(True, 'added subpath should trigger call',
+ expected_changes='*Modified: %s*Subpath added: %s' % (
+ input_file2.name, 'path/1.txt'),
+ added_or_modified_only=True)
+ _WriteZipFile(input_file2.name, [('path/1.txt', '2')])
+ CheckCallAndRecord(True, 'changed subpath should trigger call',
+ expected_changes='*Modified: %s*Subpath modified: %s' % (
+ input_file2.name, 'path/1.txt'),
+ added_or_modified_only=True)
+ CheckCallAndRecord(False, 'should not call when nothing changed')
+
+ _WriteZipFile(input_file2.name, [])
+ CheckCallAndRecord(True, 'removed subpath should trigger call',
+ expected_changes='*Modified: %s*Subpath removed: %s' % (
+ input_file2.name, 'path/1.txt'),
+ added_or_modified_only=False)
+
if __name__ == '__main__':
unittest.main()
« no previous file with comments | « build/android/gyp/util/md5_check.py ('k') | build/config/android/config.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698