OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 from link_dependencies import extract_inputs, library_deps |
| 7 import unittest |
| 8 |
| 9 |
| 10 class ExtractInputsTest(unittest.TestCase): |
| 11 def test_empty(self): |
| 12 self.assertListEqual([], extract_inputs('')) |
| 13 query_result = '\n'.join([ |
| 14 'header', |
| 15 ' input: link', |
| 16 ' outputs: nothing', |
| 17 'footer' |
| 18 ]) |
| 19 self.assertListEqual([], extract_inputs(query_result)) |
| 20 |
| 21 def test_one_input(self): |
| 22 query_result = '\n'.join([ |
| 23 'header', |
| 24 ' input: link', |
| 25 ' foo', |
| 26 ' outputs: link', |
| 27 ' quxx', |
| 28 'footer' |
| 29 ]) |
| 30 self.assertListEqual(['foo'], extract_inputs(query_result)) |
| 31 |
| 32 def test_many_inputs(self): |
| 33 query_result = '\n'.join([ |
| 34 'header', |
| 35 ' input: link', |
| 36 ' foo', |
| 37 ' bar', |
| 38 ' baz', |
| 39 ' outputs:', |
| 40 ' quxx', |
| 41 'footer' |
| 42 ]) |
| 43 self.assertListEqual(['foo', 'bar', 'baz'], extract_inputs(query_result)) |
| 44 |
| 45 def test_no_pipe_inputs(self): |
| 46 query_result = '\n'.join([ |
| 47 'header', |
| 48 ' input: link', |
| 49 ' |foo', |
| 50 ' bar', |
| 51 ' |baz', |
| 52 ' outputs:', |
| 53 ' quxx', |
| 54 'footer' |
| 55 ]) |
| 56 self.assertListEqual(['bar'], extract_inputs(query_result)) |
| 57 |
| 58 def test_prefix(self): |
| 59 query_result = '\n'.join([ |
| 60 'header', |
| 61 ' input: link', |
| 62 ' bar', |
| 63 ' outputs:', |
| 64 'footer' |
| 65 ]) |
| 66 self.assertListEqual(['foo/bar'], |
| 67 extract_inputs(query_result, 'foo/')) |
| 68 |
| 69 |
| 70 class LibraryDepsTest(unittest.TestCase): |
| 71 def mkquery(self, answers): |
| 72 """Creates a query function for library_deps. |
| 73 |
| 74 Creates a query function for library_deps that returns answers from the |
| 75 supplied map. |
| 76 """ |
| 77 return lambda target, unused_workdir, unused_prefix='': answers[target] |
| 78 |
| 79 def test_empty(self): |
| 80 self.assertEqual(set(), library_deps([], 'wd', self.mkquery({}))) |
| 81 |
| 82 def test_nonarch(self): |
| 83 deps = ['abc.a', 'def.o', 'abc.a'] |
| 84 self.assertEqual({'wd/abc.a', 'wd/def.o'}, |
| 85 library_deps(deps, 'wd', self.mkquery({}))) |
| 86 |
| 87 def test_arch(self): |
| 88 dep_map = {'abc': ['wd/def.a', 'wd/ghi.o']} |
| 89 deps = ['abc', 'jkl.o'] |
| 90 self.assertEqual({'wd/def.a', 'wd/ghi.o', 'wd/jkl.o'}, |
| 91 library_deps(deps, 'wd', self.mkquery(dep_map))) |
| 92 |
| 93 def test_arch_many(self): |
| 94 dep_map = {'abc': ['wd/def.o', 'wd/ghi.a'], |
| 95 'def': ['wd/def.o', 'wd/jkl.a']} |
| 96 deps = ['abc', 'def', 'def.o'] |
| 97 self.assertEqual({'wd/def.o', 'wd/ghi.a', 'wd/jkl.a'}, |
| 98 library_deps(deps, 'wd', self.mkquery(dep_map))) |
| 99 |
| 100 |
| 101 if __name__ == '__main__': |
| 102 unittest.main() |
OLD | NEW |