| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. | 2 # Copyright 2017 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 import logging | 6 import logging |
| 7 import json | 7 import json |
| 8 import os | 8 import os |
| 9 import unittest | 9 import unittest |
| 10 import check_gn_headers | 10 import check_gn_headers |
| 11 | 11 |
| 12 | 12 |
| 13 ninja_input = r''' | 13 ninja_input = r''' |
| 14 obj/a.o: #deps 1, deps mtime 123 (VALID) | 14 obj/a.o: #deps 1, deps mtime 123 (VALID) |
| 15 ../../a.cc | 15 ../../a.cc |
| 16 ../../dir/path/b.h | 16 ../../dir/path/b.h |
| 17 ../../c.hh | 17 ../../c.hh |
| 18 | 18 |
| 19 obj/b.o: #deps 1, deps mtime 123 (STALE) | 19 obj/b.o: #deps 1, deps mtime 123 (STALE) |
| 20 ../../b.cc | 20 ../../b.cc |
| 21 ../../dir2/path/b.h | 21 ../../dir2/path/b.h |
| 22 ../../c2.hh | 22 ../../c2.hh |
| 23 | 23 |
| 24 obj/c.o: #deps 1, deps mtime 123 (VALID) | 24 obj/c.o: #deps 1, deps mtime 123 (VALID) |
| 25 ../../c.cc | 25 ../../c.cc |
| 26 ../../build/a.h | 26 ../../build/a.h |
| 27 gen/b.h | 27 gen/b.h |
| 28 ../../out/Release/gen/no.h |
| 28 ../../dir3/path/b.h | 29 ../../dir3/path/b.h |
| 29 ../../c3.hh | 30 ../../c3.hh |
| 30 ''' | 31 ''' |
| 31 ninja_input_win = ninja_input.replace('/', '\\') | 32 ninja_input_win = ninja_input.replace('/', '\\') |
| 32 | 33 |
| 33 | 34 |
| 34 gn_input = json.loads(r''' | 35 gn_input = json.loads(r''' |
| 35 { | 36 { |
| 36 "others": [], | 37 "others": [], |
| 37 "targets": { | 38 "targets": { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 57 a/b/c/white-end.c # comment | 58 a/b/c/white-end.c # comment |
| 58 dir/white-both.c #more comment | 59 dir/white-both.c #more comment |
| 59 | 60 |
| 60 # empty line above | 61 # empty line above |
| 61 a/b/c | 62 a/b/c |
| 62 ''' | 63 ''' |
| 63 | 64 |
| 64 | 65 |
| 65 class CheckGnHeadersTest(unittest.TestCase): | 66 class CheckGnHeadersTest(unittest.TestCase): |
| 66 def testNinja(self): | 67 def testNinja(self): |
| 67 headers = check_gn_headers.ParseNinjaDepsOutput(ninja_input.split('\n')) | 68 headers = check_gn_headers.ParseNinjaDepsOutput( |
| 69 ninja_input.split('\n'), 'out/Release') |
| 68 expected = set([ | 70 expected = set([ |
| 69 'dir/path/b.h', | 71 'dir/path/b.h', |
| 70 'c.hh', | 72 'c.hh', |
| 71 'dir3/path/b.h', | 73 'dir3/path/b.h', |
| 72 'c3.hh', | 74 'c3.hh', |
| 73 ]) | 75 ]) |
| 74 self.assertEquals(headers, expected) | 76 self.assertEquals(headers, expected) |
| 75 | 77 |
| 76 def testNinjaWin(self): | 78 def testNinjaWin(self): |
| 77 old_sep = os.sep | 79 old_sep = os.sep |
| 78 os.sep = '\\' | 80 os.sep = '\\' |
| 79 | 81 |
| 80 headers = check_gn_headers.ParseNinjaDepsOutput( | 82 headers = check_gn_headers.ParseNinjaDepsOutput( |
| 81 ninja_input_win.split('\n')) | 83 ninja_input_win.split('\n'), 'out\\Release') |
| 82 expected = set([ | 84 expected = set([ |
| 83 'dir\\path\\b.h', | 85 'dir\\path\\b.h', |
| 84 'c.hh', | 86 'c.hh', |
| 85 'dir3\\path\\b.h', | 87 'dir3\\path\\b.h', |
| 86 'c3.hh', | 88 'c3.hh', |
| 87 ]) | 89 ]) |
| 88 self.assertEquals(headers, expected) | 90 self.assertEquals(headers, expected) |
| 89 | 91 |
| 90 os.sep = old_sep | 92 os.sep = old_sep |
| 91 | 93 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 108 'a/b/c/white-end.c', | 110 'a/b/c/white-end.c', |
| 109 'dir/white-both.c', | 111 'dir/white-both.c', |
| 110 'a/b/c', | 112 'a/b/c', |
| 111 ]) | 113 ]) |
| 112 self.assertEquals(output, expected) | 114 self.assertEquals(output, expected) |
| 113 | 115 |
| 114 | 116 |
| 115 if __name__ == '__main__': | 117 if __name__ == '__main__': |
| 116 logging.getLogger().setLevel(logging.DEBUG) | 118 logging.getLogger().setLevel(logging.DEBUG) |
| 117 unittest.main(verbosity=2) | 119 unittest.main(verbosity=2) |
| OLD | NEW |