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 os | 9 import os |
10 import sys | 10 import sys |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 self.verbose = False | 42 self.verbose = False |
43 self.extra_verbose = False | 43 self.extra_verbose = False |
44 expected_dep_file = os.path.join(output_dir, 'substitute.grd.d') | 44 expected_dep_file = os.path.join(output_dir, 'substitute.grd.d') |
45 builder.Run(DummyOpts(), ['-o', output_dir, | 45 builder.Run(DummyOpts(), ['-o', output_dir, |
46 '--depdir', output_dir, | 46 '--depdir', output_dir, |
47 '--depfile', expected_dep_file]) | 47 '--depfile', expected_dep_file]) |
48 | 48 |
49 self.failUnless(os.path.isfile(expected_dep_file)) | 49 self.failUnless(os.path.isfile(expected_dep_file)) |
50 with open(expected_dep_file) as f: | 50 with open(expected_dep_file) as f: |
51 line = f.readline() | 51 line = f.readline() |
52 (dep_file_name, deps_string) = line.split(': ') | 52 (dep_output_file, deps_string) = line.split(': ') |
53 deps = deps_string.split(' ') | 53 deps = deps_string.split(' ') |
54 self.failUnlessEqual(os.path.abspath(expected_dep_file), | 54 |
55 os.path.abspath(os.path.join(output_dir, dep_file_name)), | 55 self.failUnlessEqual("resource.h", dep_output_file) |
56 "depfile should refer to itself as the depended upon file") | |
57 self.failUnlessEqual(1, len(deps)) | 56 self.failUnlessEqual(1, len(deps)) |
58 self.failUnlessEqual(deps[0], | 57 self.failUnlessEqual(deps[0], |
59 util.PathFromRoot('grit/testdata/substitute.xmb')) | 58 util.PathFromRoot('grit/testdata/substitute.xmb')) |
60 | 59 |
| 60 def testAssertOutputs(self): |
| 61 output_dir = tempfile.mkdtemp() |
| 62 class DummyOpts(object): |
| 63 def __init__(self): |
| 64 self.input = util.PathFromRoot('grit/testdata/substitute.grd') |
| 65 self.verbose = False |
| 66 self.extra_verbose = False |
| 67 |
| 68 # Incomplete output file list should fail. |
| 69 builder_fail = build.RcBuilder() |
| 70 self.failUnlessEqual(2, |
| 71 builder_fail.Run(DummyOpts(), [ |
| 72 '-o', output_dir, |
| 73 '-a', os.path.abspath( |
| 74 os.path.join(output_dir, 'en_generated_resources.rc'))])) |
| 75 |
| 76 # Complete output file list should succeed. |
| 77 builder_ok = build.RcBuilder() |
| 78 self.failUnlessEqual(0, |
| 79 builder_ok.Run(DummyOpts(), [ |
| 80 '-o', output_dir, |
| 81 '-a', os.path.abspath( |
| 82 os.path.join(output_dir, 'en_generated_resources.rc')), |
| 83 '-a', os.path.abspath( |
| 84 os.path.join(output_dir, 'sv_generated_resources.rc')), |
| 85 '-a', os.path.abspath( |
| 86 os.path.join(output_dir, 'resource.h'))])) |
61 | 87 |
62 if __name__ == '__main__': | 88 if __name__ == '__main__': |
63 unittest.main() | 89 unittest.main() |
OLD | NEW |