Index: build/check_gn_headers_unittest.py |
diff --git a/build/check_gn_headers_unittest.py b/build/check_gn_headers_unittest.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..fa1650fafcf6d5ac84e761e4bdf59f853ad3e797 |
--- /dev/null |
+++ b/build/check_gn_headers_unittest.py |
@@ -0,0 +1,86 @@ |
+#!/usr/bin/env python |
+# Copyright 2016 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import logging |
+import json |
+import os |
+import unittest |
+import check_gn_headers |
+ |
+ |
+ninja_input = r''' |
+obj/a.o: #deps 1, deps mtime 123 (VALID) |
+ ../../a.cc |
+ ../../dir/path/b.h |
+ ../../c.hh |
+ |
+obj/b.o: #deps 1, deps mtime 123 (STALE) |
+ ../../b.cc |
+ ../../dir2/path/b.h |
+ ../../c2.hh |
+ |
+obj/c.o: #deps 1, deps mtime 123 (VALID) |
+ ../../c.cc |
+ ../../build/a.h |
+ gen/b.h |
+ ../../dir3/path/b.h |
+ ../../c3.hh |
+''' |
+ninja_input_win = ninja_input.replace('/', '\\') |
+ |
+ |
+gn_input = json.loads(r''' |
+{ |
+ "others": [], |
+ "targets": { |
+ "//:All": { |
+ }, |
+ "//:base": { |
+ "sources": [ "//base/a.cc", "//base/a.h", "//base/b.hh" ], |
+ "visibility": [ "*" ] |
+ } |
+ } |
+} |
+''') |
+ |
+ |
+class CheckGnHeadersTest(unittest.TestCase): |
+ def testNinja(self): |
+ headers = check_gn_headers.extract_d_headers(ninja_input) |
+ expected = set([ |
+ 'dir/path/b.h', |
+ 'c.hh', |
+ 'dir3/path/b.h', |
+ 'c3.hh', |
+ ]) |
+ self.assertEquals(headers, expected) |
+ |
+ def testNinjaWin(self): |
+ old_sep = os.sep |
+ os.sep = '\\' |
+ |
+ headers = check_gn_headers.extract_d_headers(ninja_input_win) |
+ expected = set([ |
+ 'dir\\path\\b.h', |
+ 'c.hh', |
+ 'dir3\\path\\b.h', |
+ 'c3.hh', |
+ ]) |
+ self.assertEquals(headers, expected) |
+ |
+ os.sep = old_sep |
+ |
+ def testGn(self): |
+ headers = check_gn_headers.extract_gn_headers(gn_input) |
+ expected = set([ |
+ 'base/a.h', |
+ 'base/b.hh', |
+ ]) |
+ self.assertEquals(headers, expected) |
+ |
+ |
+if __name__ == '__main__': |
+ logging.getLogger().setLevel(logging.DEBUG) |
+ unittest.main(verbosity=2) |