OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 '''Unit tests for the 'grit build' tool. | 6 '''Unit tests for the 'grit build' tool. |
7 ''' | 7 ''' |
8 | 8 |
9 import codecs | 9 import codecs |
10 import os | 10 import os |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 second_mtime = os.stat(header).st_mtime | 294 second_mtime = os.stat(header).st_mtime |
295 | 295 |
296 os.utime(header, (UNCHANGED, UNCHANGED)) | 296 os.utime(header, (UNCHANGED, UNCHANGED)) |
297 builder.Run(DummyOpts(), ['-o', output_dir, '--write-only-new', '1']) | 297 builder.Run(DummyOpts(), ['-o', output_dir, '--write-only-new', '1']) |
298 self.failUnless(os.path.exists(header)) | 298 self.failUnless(os.path.exists(header)) |
299 third_mtime = os.stat(header).st_mtime | 299 third_mtime = os.stat(header).st_mtime |
300 | 300 |
301 self.assertTrue(abs(second_mtime - UNCHANGED) > 5) | 301 self.assertTrue(abs(second_mtime - UNCHANGED) > 5) |
302 self.assertTrue(abs(third_mtime - UNCHANGED) < 5) | 302 self.assertTrue(abs(third_mtime - UNCHANGED) < 5) |
303 | 303 |
| 304 def testGenerateDepFileWithDependOnStamp(self): |
| 305 output_dir = tempfile.mkdtemp() |
| 306 builder = build.RcBuilder() |
| 307 class DummyOpts(object): |
| 308 def __init__(self): |
| 309 self.input = util.PathFromRoot('grit/testdata/substitute.grd') |
| 310 self.verbose = False |
| 311 self.extra_verbose = False |
| 312 expected_dep_file_name = 'substitute.grd.d' |
| 313 expected_stamp_file_name = expected_dep_file_name + '.stamp' |
| 314 expected_dep_file = os.path.join(output_dir, expected_dep_file_name) |
| 315 expected_stamp_file = os.path.join(output_dir, expected_stamp_file_name) |
| 316 if os.path.isfile(expected_stamp_file): |
| 317 os.remove(expected_stamp_file) |
| 318 builder.Run(DummyOpts(), ['-o', output_dir, |
| 319 '--depdir', output_dir, |
| 320 '--depfile', expected_dep_file, |
| 321 '--depend-on-stamp']) |
| 322 self.failUnless(os.path.isfile(expected_stamp_file)) |
| 323 first_mtime = os.stat(expected_stamp_file).st_mtime |
| 324 |
| 325 # Reset mtime to very old. |
| 326 OLDTIME = 10 |
| 327 os.utime(expected_stamp_file, (OLDTIME, OLDTIME)) |
| 328 |
| 329 builder.Run(DummyOpts(), ['-o', output_dir, |
| 330 '--depdir', output_dir, |
| 331 '--depfile', expected_dep_file, |
| 332 '--depend-on-stamp']) |
| 333 self.failUnless(os.path.isfile(expected_stamp_file)) |
| 334 second_mtime = os.stat(expected_stamp_file).st_mtime |
| 335 |
| 336 # Some OS have a 2s stat resolution window, so can't do a direct comparison. |
| 337 self.assertTrue((second_mtime - OLDTIME) > 5) |
| 338 self.assertTrue(abs(second_mtime - first_mtime) < 5) |
| 339 |
| 340 self.failUnless(os.path.isfile(expected_dep_file)) |
| 341 with open(expected_dep_file) as f: |
| 342 line = f.readline() |
| 343 (dep_output_file, deps_string) = line.split(': ') |
| 344 deps = deps_string.split(' ') |
| 345 |
| 346 self.failUnlessEqual(expected_stamp_file_name, dep_output_file) |
| 347 self.failUnlessEqual(1, len(deps)) |
| 348 self.failUnlessEqual(deps[0], |
| 349 util.PathFromRoot('grit/testdata/substitute.xmb')) |
| 350 |
304 | 351 |
305 if __name__ == '__main__': | 352 if __name__ == '__main__': |
306 unittest.main() | 353 unittest.main() |
OLD | NEW |