blob: 20c3b138979036d2d96b6601bd3ef48c099e710f [file] [log] [blame]
wychen037f6e9e2017-01-10 17:14:561#!/usr/bin/env python
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
4# found in the LICENSE file.
5
6import logging
7import json
wychen037f6e9e2017-01-10 17:14:568import unittest
9import check_gn_headers
10
11
12ninja_input = r'''
13obj/a.o: #deps 1, deps mtime 123 (VALID)
14 ../../a.cc
15 ../../dir/path/b.h
16 ../../c.hh
17
18obj/b.o: #deps 1, deps mtime 123 (STALE)
19 ../../b.cc
20 ../../dir2/path/b.h
21 ../../c2.hh
22
23obj/c.o: #deps 1, deps mtime 123 (VALID)
24 ../../c.cc
25 ../../build/a.h
26 gen/b.h
wychen0735fd762017-06-03 07:53:2627 ../../out/Release/gen/no.h
wychen037f6e9e2017-01-10 17:14:5628 ../../dir3/path/b.h
29 ../../c3.hh
30'''
wychen037f6e9e2017-01-10 17:14:5631
32
33gn_input = json.loads(r'''
34{
35 "others": [],
36 "targets": {
37 "//:All": {
38 },
39 "//:base": {
wychen55235782017-04-28 01:59:1540 "public": [ "//base/p.h" ],
wychen037f6e9e2017-01-10 17:14:5641 "sources": [ "//base/a.cc", "//base/a.h", "//base/b.hh" ],
42 "visibility": [ "*" ]
wychen55235782017-04-28 01:59:1543 },
44 "//:star_public": {
45 "public": "*",
wychen03629112017-05-25 20:37:1846 "sources": [ "//base/c.h", "//tmp/gen/a.h" ],
wychen55235782017-04-28 01:59:1547 "visibility": [ "*" ]
wychen037f6e9e2017-01-10 17:14:5648 }
49 }
50}
51''')
52
53
54whitelist = r'''
55 white-front.c
56a/b/c/white-end.c # comment
57 dir/white-both.c #more comment
58
59# empty line above
60a/b/c
61'''
62
63
64class CheckGnHeadersTest(unittest.TestCase):
65 def testNinja(self):
wychen0735fd762017-06-03 07:53:2666 headers = check_gn_headers.ParseNinjaDepsOutput(
wychen8cc31232017-06-13 10:21:2367 ninja_input.split('\n'), 'out/Release', False)
68 expected = {
69 'dir/path/b.h': ['obj/a.o'],
70 'c.hh': ['obj/a.o'],
71 'dir3/path/b.h': ['obj/c.o'],
72 'c3.hh': ['obj/c.o'],
73 }
wychen037f6e9e2017-01-10 17:14:5674 self.assertEquals(headers, expected)
75
wychen037f6e9e2017-01-10 17:14:5676 def testGn(self):
wychen03629112017-05-25 20:37:1877 headers = check_gn_headers.ParseGNProjectJSON(gn_input,
78 'out/Release', 'tmp')
wychen037f6e9e2017-01-10 17:14:5679 expected = set([
80 'base/a.h',
81 'base/b.hh',
wychen55235782017-04-28 01:59:1582 'base/c.h',
83 'base/p.h',
wychen03629112017-05-25 20:37:1884 'out/Release/gen/a.h',
wychen037f6e9e2017-01-10 17:14:5685 ])
86 self.assertEquals(headers, expected)
87
88 def testWhitelist(self):
89 output = check_gn_headers.ParseWhiteList(whitelist)
90 expected = set([
91 'white-front.c',
92 'a/b/c/white-end.c',
93 'dir/white-both.c',
94 'a/b/c',
95 ])
96 self.assertEquals(output, expected)
97
98
99if __name__ == '__main__':
100 logging.getLogger().setLevel(logging.DEBUG)
101 unittest.main(verbosity=2)