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

Unified Diff: build/scan_sources_test.py

Issue 8037013: Create scanning script to determine header dependencies. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
« build/scan_sources.py ('K') | « build/scan_sources.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/scan_sources_test.py
===================================================================
--- build/scan_sources_test.py (revision 0)
+++ build/scan_sources_test.py (revision 0)
@@ -0,0 +1,92 @@
+#!/usr/bin/python
+# Copyright (c) 2011 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 os
+import scan_sources
+import unittest
+
+
+class MockSimplePath(object):
+ def exists(self, pathname):
+ return True
+
+ def getcwd(self):
+ return '.'
+
+ def isdir(self, pathname):
+ return True
+
+ def realpath(self, pathname):
+ return pathname
+
+
+class MockScanner(object):
+ def __init__(self, filelists):
+ self.filelists = filelists
+
+ def ScanFile(self, filename):
+ if not self.filelists:
+ return []
+ return self.filelists.pop()
+
+
+class MockResolver(object):
+ def FindFile(self, filename):
+ return filename
+
+
+class ScannerUnitTest(unittest.TestCase):
+
+ def testScanData(self):
+ scanner = scan_sources.Scanner()
+ test = """
+#This is not an include
+#include is <bogus>
+#include <x1>
+ #include "x2"
+#include <x3>
+#include "x4"
+# include <x5>
+# include "x6"
+# include "x7"
+Not
+"""
+ results = scanner.ScanData(test)
+ self.assertEqual(results, ['x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7'])
+
+ def testResolverAddDirectories(self):
+ resolver = scan_sources.Resolver(MockSimplePath())
+ resolver.AddDirectories(['Dir1 Dir2', 'Dir3', 'Dir4', 'Dir5'])
+ results = resolver.GetDirectories()
+ self.assertEqual(results, ['Dir1','Dir2','Dir3','Dir4','Dir5'])
+
+ def testResolverRelative(self):
+ resolver = scan_sources.Resolver()
+ tests = [
+ ('/foo/bar','/foo/bar/file1','file1'),
+ ('/foo/bar/extra', '/foo/bar/file2', '../file2'),
+ ('/foo/bar', '/foo/bar/extra/file3', 'extra/file3'),
+ ]
+ for (base, full, rel) in tests:
+ self.assertEqual(rel, resolver.RealToRelative(full, base))
+
+ def testWorkQ(self):
+ filelists = [['file1', 'file4', 'file2'], ['file3'], ['file5', 'file2']]
+ resolver = MockResolver()
+ scanner = MockScanner(filelists)
+ workq = scan_sources.WorkQueue(resolver, scanner)
+ workq.PushIfNew('file3')
+ result = workq.Run()
+
+ flat = set([item for item in [sublist for sublist in filelists]])
+ flat = [item for item in flat]
+
+ flat = sorted(flat)
+ result = sorted(flat)
+ self.assertEqual(flat, result)
+
+if __name__ == '__main__':
+ unittest.main()
+
Property changes on: build/scan_sources_test.py
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:eol-style
+ LF
« build/scan_sources.py ('K') | « build/scan_sources.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698