blob: 78c78776a15544cc11e4ebab88727e782926d850 [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
8import os
9import unittest
10import check_gn_headers
11
12
13ninja_input = r'''
14obj/a.o: #deps 1, deps mtime 123 (VALID)
15 ../../a.cc
16 ../../dir/path/b.h
17 ../../c.hh
18
19obj/b.o: #deps 1, deps mtime 123 (STALE)
20 ../../b.cc
21 ../../dir2/path/b.h
22 ../../c2.hh
23
24obj/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'''
31ninja_input_win = ninja_input.replace('/', '\\')
32
33
34gn_input = json.loads(r'''
35{
36 "others": [],
37 "targets": {
38 "//:All": {
39 },
40 "//:base": {
wychen55235782017-04-28 01:59:1541 "public": [ "//base/p.h" ],
wychen037f6e9e2017-01-10 17:14:5642 "sources": [ "//base/a.cc", "//base/a.h", "//base/b.hh" ],
43 "visibility": [ "*" ]
wychen55235782017-04-28 01:59:1544 },
45 "//:star_public": {
46 "public": "*",
wychen03629112017-05-25 20:37:1847 "sources": [ "//base/c.h", "//tmp/gen/a.h" ],
wychen55235782017-04-28 01:59:1548 "visibility": [ "*" ]
wychen037f6e9e2017-01-10 17:14:5649 }
50 }
51}
52''')
53
54
55whitelist = r'''
56 white-front.c
57a/b/c/white-end.c # comment
58 dir/white-both.c #more comment
59
60# empty line above
61a/b/c
62'''
63
64
65class CheckGnHeadersTest(unittest.TestCase):
66 def testNinja(self):
wychenef74ec992017-04-27 06:28:2567 headers = check_gn_headers.ParseNinjaDepsOutput(ninja_input.split('\n'))
wychen037f6e9e2017-01-10 17:14:5668 expected = set([
69 'dir/path/b.h',
70 'c.hh',
71 'dir3/path/b.h',
72 'c3.hh',
73 ])
74 self.assertEquals(headers, expected)
75
76 def testNinjaWin(self):
77 old_sep = os.sep
78 os.sep = '\\'
79
wychenef74ec992017-04-27 06:28:2580 headers = check_gn_headers.ParseNinjaDepsOutput(
81 ninja_input_win.split('\n'))
wychen037f6e9e2017-01-10 17:14:5682 expected = set([
83 'dir\\path\\b.h',
84 'c.hh',
85 'dir3\\path\\b.h',
86 'c3.hh',
87 ])
88 self.assertEquals(headers, expected)
89
90 os.sep = old_sep
91
92 def testGn(self):
wychen03629112017-05-25 20:37:1893 headers = check_gn_headers.ParseGNProjectJSON(gn_input,
94 'out/Release', 'tmp')
wychen037f6e9e2017-01-10 17:14:5695 expected = set([
96 'base/a.h',
97 'base/b.hh',
wychen55235782017-04-28 01:59:1598 'base/c.h',
99 'base/p.h',
wychen03629112017-05-25 20:37:18100 'out/Release/gen/a.h',
wychen037f6e9e2017-01-10 17:14:56101 ])
102 self.assertEquals(headers, expected)
103
104 def testWhitelist(self):
105 output = check_gn_headers.ParseWhiteList(whitelist)
106 expected = set([
107 'white-front.c',
108 'a/b/c/white-end.c',
109 'dir/white-both.c',
110 'a/b/c',
111 ])
112 self.assertEquals(output, expected)
113
114
115if __name__ == '__main__':
116 logging.getLogger().setLevel(logging.DEBUG)
117 unittest.main(verbosity=2)