blob: 7272ea960640f8fb3d85f76eabbd5810ec2695f4 [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": {
41 "sources": [ "//base/a.cc", "//base/a.h", "//base/b.hh" ],
42 "visibility": [ "*" ]
43 }
44 }
45}
46''')
47
48
49whitelist = r'''
50 white-front.c
51a/b/c/white-end.c # comment
52 dir/white-both.c #more comment
53
54# empty line above
55a/b/c
56'''
57
58
59class 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
104if __name__ == '__main__':
105 logging.getLogger().setLevel(logging.DEBUG)
106 unittest.main(verbosity=2)