Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: build/check_gn_headers_unittest.py

Issue 2510303002: Add check_gn_headers.py to find missing headers in GN (Closed)
Patch Set: address nits Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/check_gn_headers.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/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
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 whitelist = r'''
50 white-front.c
51 a/b/c/white-end.c # comment
52 dir/white-both.c #more comment
53
54 # empty line above
55 a/b/c
56 '''
57
58
59 class CheckGnHeadersTest(unittest.TestCase):
60 def testNinja(self):
61 headers = check_gn_headers.ParseNinjaDepsOutput(ninja_input)
62 expected = set([
63 'dir/path/b.h',
64 'c.hh',
65 'dir3/path/b.h',
66 'c3.hh',
67 ])
68 self.assertEquals(headers, expected)
69
70 def testNinjaWin(self):
71 old_sep = os.sep
72 os.sep = '\\'
73
74 headers = check_gn_headers.ParseNinjaDepsOutput(ninja_input_win)
75 expected = set([
76 'dir\\path\\b.h',
77 'c.hh',
78 'dir3\\path\\b.h',
79 'c3.hh',
80 ])
81 self.assertEquals(headers, expected)
82
83 os.sep = old_sep
84
85 def testGn(self):
86 headers = check_gn_headers.ParseGNProjectJSON(gn_input)
87 expected = set([
88 'base/a.h',
89 'base/b.hh',
90 ])
91 self.assertEquals(headers, expected)
92
93 def testWhitelist(self):
94 output = check_gn_headers.ParseWhiteList(whitelist)
95 expected = set([
96 'white-front.c',
97 'a/b/c/white-end.c',
98 'dir/white-both.c',
99 'a/b/c',
100 ])
101 self.assertEquals(output, expected)
102
103
104 if __name__ == '__main__':
105 logging.getLogger().setLevel(logging.DEBUG)
106 unittest.main(verbosity=2)
OLDNEW
« no previous file with comments | « build/check_gn_headers.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698