OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2016 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 import logging |
| 7 import json |
| 8 import os |
| 9 import unittest |
| 10 import check_gn_headers |
| 11 |
| 12 |
| 13 ninja_input = r''' |
| 14 obj/a.o: #deps 1, deps mtime 123 (VALID) |
| 15 ../../a.cc |
| 16 ../../dir/path/b.h |
| 17 ../../c.hh |
| 18 |
| 19 obj/b.o: #deps 1, deps mtime 123 (STALE) |
| 20 ../../b.cc |
| 21 ../../dir2/path/b.h |
| 22 ../../c2.hh |
| 23 |
| 24 obj/c.o: #deps 1, deps mtime 123 (VALID) |
| 25 ../../c.cc |
| 26 ../../build/a.h |
| 27 gen/b.h |
| 28 ../../dir3/path/b.h |
| 29 ../../c3.hh |
| 30 ''' |
| 31 ninja_input_win = ninja_input.replace('/', '\\') |
| 32 |
| 33 |
| 34 gn_input = json.loads(r''' |
| 35 { |
| 36 "others": [], |
| 37 "targets": { |
| 38 "//:All": { |
| 39 }, |
| 40 "//:base": { |
| 41 "sources": [ "//base/a.cc", "//base/a.h", "//base/b.hh" ], |
| 42 "visibility": [ "*" ] |
| 43 } |
| 44 } |
| 45 } |
| 46 ''') |
| 47 |
| 48 |
| 49 class CheckGnHeadersTest(unittest.TestCase): |
| 50 def testNinja(self): |
| 51 headers = check_gn_headers.extract_d_headers(ninja_input) |
| 52 expected = set([ |
| 53 'dir/path/b.h', |
| 54 'c.hh', |
| 55 'dir3/path/b.h', |
| 56 'c3.hh', |
| 57 ]) |
| 58 self.assertEquals(headers, expected) |
| 59 |
| 60 def testNinjaWin(self): |
| 61 old_sep = os.sep |
| 62 os.sep = '\\' |
| 63 |
| 64 headers = check_gn_headers.extract_d_headers(ninja_input_win) |
| 65 expected = set([ |
| 66 'dir\\path\\b.h', |
| 67 'c.hh', |
| 68 'dir3\\path\\b.h', |
| 69 'c3.hh', |
| 70 ]) |
| 71 self.assertEquals(headers, expected) |
| 72 |
| 73 os.sep = old_sep |
| 74 |
| 75 def testGn(self): |
| 76 headers = check_gn_headers.extract_gn_headers(gn_input) |
| 77 expected = set([ |
| 78 'base/a.h', |
| 79 'base/b.hh', |
| 80 ]) |
| 81 self.assertEquals(headers, expected) |
| 82 |
| 83 |
| 84 if __name__ == '__main__': |
| 85 logging.getLogger().setLevel(logging.DEBUG) |
| 86 unittest.main(verbosity=2) |
OLD | NEW |