Esempio n. 1
0
from depend import Depend
from depend import DependReport

if __name__ == "__main__":
    import sys
    file = sys.argv[1]
    lines = open(file).readlines()
    depend = Depend()
    depend.feed(lines)
    reporter = DependReport()
    print reporter.report(depend.getTree())
Esempio n. 2
0
class TestAcceptance(unittest.TestCase):
    def setUp(self):
        self.depend = Depend()

    def feed(self, precomp):
        lines = precomp.splitlines()
        self.depend.feed(lines)

    def getStats(self, precomp):
        self.feed(precomp)
        return self.depend.getStats()

    def getTree(self, precomp):
        self.feed(precomp)
        return self.depend.getTree()

    def testNoNothing(self):
        tree = self.getTree("")
        assert (tree is None)

    def testNoNothingStats(self):
        stats = self.getStats("")
        self.assertEqual(len(stats.files()), 0)

    def testNoLineInfo(self):
        tree = self.getTree("/*nothing to see here*/")
        assert (tree is None)

    def testFirstNode(self):
        precomp = '''#line 1 "test.cpp"'''
        tree = self.getTree(precomp)
        self.assertEqual(tree.name(), "test.cpp")

    def testWonkyLine(self):
        precomp = '''   #line 1 "test.cpp"'''
        tree = self.getTree(precomp)
        self.assertEqual(tree.name(), "test.cpp")

    def testFirstNodeWithAnnoyingName(self):
        precomp = '''#line 1 "C:\\blahblah\\overhere\\overthere\\test.cpp"'''
        tree = self.getTree(precomp)
        self.assertEqual(tree.name(), "test.cpp")

    def testFirstNodeWithLines(self):
        tree = self.getTree(precompWithLines)
        self.assertEqual(tree.name(), "test.cpp")
        self.assertEqual(tree.lines(), 6)

    def testTwoRootLevelFiles(self):
        self.feed(precompWithLinesTemplate % "a.cpp")
        self.feed(precompWithLinesTemplate % "b.cpp")
        trees = self.depend.getTrees()
        self.assertEqual(len(trees), 2)
        self.assertEqual(trees[0].name(), "a.cpp")
        self.assertEqual(trees[0].lines(), 6)
        self.assertEqual(trees[0].totalLines(), 6)
        self.assertEqual(trees[1].name(), "b.cpp")
        self.assertEqual(trees[1].lines(), 6)
        self.assertEqual(trees[1].totalLines(), 6)

    def testOneInclude(self):
        tree = self.getTree(precompOneInclude)
        self.assertEqual(tree.name(), "test.cpp")
        self.assertEqual(tree.lines(), 5)
        self.assertEqual(len(tree.children()), 1)
        self.assertEqual(tree.children()[0].name(), "test.h")
        self.assertEqual(tree.children()[0].lines(), 1)
        self.assertEqual(len(tree.children()[0].children()), 0)

    def testNestedInclude(self):
        tree = self.getTree(precompNestedInclude)
        self.assertEqual(tree.name(), "test.cpp")
        self.assertEqual(tree.lines(), 5)
        self.assertEqual(len(tree.children()), 1)
        self.assertEqual(tree.children()[0].name(), "test2.h")
        self.assertEqual(tree.children()[0].lines(), 1)
        self.assertEqual(len(tree.children()[0].children()), 1)
        self.assertEqual(tree.children()[0].children()[0].name(), "test.h")

    def testNestedIncludeSameNames(self):
        tree = self.getTree(precompNestedIncludeSameName)
        self.assertEqual(tree.name(), "test.cpp")
        self.assertEqual(tree.lines(), 5)
        self.assertEqual(len(tree.children()), 1)
        self.assertEqual(tree.children()[0].name(), "test.h")
        self.assertEqual(tree.children()[0].lines(), 1)
        self.assertEqual(len(tree.children()[0].children()), 1)
        self.assertEqual(tree.children()[0].children()[0].name(), "test.h")

    def testTwoIncludes(self):
        tree = self.getTree(precompTwoIncludes)
        self.assertEqual(tree.name(), "test.cpp")
        self.assertEqual(tree.lines(), 5)
        self.assertEqual(len(tree.children()), 2)
        self.assertEqual(tree.children()[0].name(), "testa.h")
        self.assertEqual(tree.children()[1].name(), "testb.h")

    def testTotalLines(self):
        tree = self.getTree(precompWithLines)
        self.assertEqual(tree.totalLines(), 6)

    def testTotalLinesWithNestedChildren(self):
        tree = self.getTree(precompNestedInclude)
        self.assertEqual(tree.totalLines(), 7)

    def testTotalLinesWithChildren(self):
        tree = self.getTree(precompTwoIncludes)
        self.assertEqual(tree.totalLines(), 7)

    def testTwoGnuCppIncludes(self):
        tree = self.getTree(precompGnuCpp)
        self.assertEqual(tree.name(), "test.cpp")
        self.assertEqual(tree.lines(), 4)
        self.assertEqual(len(tree.children()), 2)
        self.assertEqual(tree.children()[0].name(), "testa.h")
        self.assertEqual(tree.children()[1].name(), "testb.h")
Esempio n. 3
0
from depend import Depend
from depend import DependReport


if __name__ == "__main__":
  import sys
  files = sys.argv[1:]
  depend = Depend()
  for file in files:
    lines = open(file).readlines()
    depend.feed(lines)
  reporter = DependReport()
  print reporter.reportStats(depend.getStats())
Esempio n. 4
0
class TestAcceptance(unittest.TestCase):
    def setUp(self):
        self.depend = Depend()

    def feed(self, precomp):
        lines = precomp.splitlines()
        self.depend.feed(lines)

    def getStats(self, precomp):
        self.feed(precomp)
        return self.depend.getStats()

    def getTree(self, precomp):
        self.feed(precomp)
        return self.depend.getTree()

    def testNoNothing(self):
        tree = self.getTree("")
        assert tree is None

    def testNoNothingStats(self):
        stats = self.getStats("")
        self.assertEqual(len(stats.files()), 0)

    def testNoLineInfo(self):
        tree = self.getTree("/*nothing to see here*/")
        assert tree is None

    def testFirstNode(self):
        precomp = '''#line 1 "test.cpp"'''
        tree = self.getTree(precomp)
        self.assertEqual(tree.name(), "test.cpp")

    def testWonkyLine(self):
        precomp = '''   #line 1 "test.cpp"'''
        tree = self.getTree(precomp)
        self.assertEqual(tree.name(), "test.cpp")

    def testFirstNodeWithAnnoyingName(self):
        precomp = '''#line 1 "C:\\blahblah\\overhere\\overthere\\test.cpp"'''
        tree = self.getTree(precomp)
        self.assertEqual(tree.name(), "test.cpp")

    def testFirstNodeWithLines(self):
        tree = self.getTree(precompWithLines)
        self.assertEqual(tree.name(), "test.cpp")
        self.assertEqual(tree.lines(), 6)

    def testTwoRootLevelFiles(self):
        self.feed(precompWithLinesTemplate % "a.cpp")
        self.feed(precompWithLinesTemplate % "b.cpp")
        trees = self.depend.getTrees()
        self.assertEqual(len(trees), 2)
        self.assertEqual(trees[0].name(), "a.cpp")
        self.assertEqual(trees[0].lines(), 6)
        self.assertEqual(trees[0].totalLines(), 6)
        self.assertEqual(trees[1].name(), "b.cpp")
        self.assertEqual(trees[1].lines(), 6)
        self.assertEqual(trees[1].totalLines(), 6)

    def testOneInclude(self):
        tree = self.getTree(precompOneInclude)
        self.assertEqual(tree.name(), "test.cpp")
        self.assertEqual(tree.lines(), 5)
        self.assertEqual(len(tree.children()), 1)
        self.assertEqual(tree.children()[0].name(), "test.h")
        self.assertEqual(tree.children()[0].lines(), 1)
        self.assertEqual(len(tree.children()[0].children()), 0)

    def testNestedInclude(self):
        tree = self.getTree(precompNestedInclude)
        self.assertEqual(tree.name(), "test.cpp")
        self.assertEqual(tree.lines(), 5)
        self.assertEqual(len(tree.children()), 1)
        self.assertEqual(tree.children()[0].name(), "test2.h")
        self.assertEqual(tree.children()[0].lines(), 1)
        self.assertEqual(len(tree.children()[0].children()), 1)
        self.assertEqual(tree.children()[0].children()[0].name(), "test.h")

    def testNestedIncludeSameNames(self):
        tree = self.getTree(precompNestedIncludeSameName)
        self.assertEqual(tree.name(), "test.cpp")
        self.assertEqual(tree.lines(), 5)
        self.assertEqual(len(tree.children()), 1)
        self.assertEqual(tree.children()[0].name(), "test.h")
        self.assertEqual(tree.children()[0].lines(), 1)
        self.assertEqual(len(tree.children()[0].children()), 1)
        self.assertEqual(tree.children()[0].children()[0].name(), "test.h")

    def testTwoIncludes(self):
        tree = self.getTree(precompTwoIncludes)
        self.assertEqual(tree.name(), "test.cpp")
        self.assertEqual(tree.lines(), 5)
        self.assertEqual(len(tree.children()), 2)
        self.assertEqual(tree.children()[0].name(), "testa.h")
        self.assertEqual(tree.children()[1].name(), "testb.h")

    def testTotalLines(self):
        tree = self.getTree(precompWithLines)
        self.assertEqual(tree.totalLines(), 6)

    def testTotalLinesWithNestedChildren(self):
        tree = self.getTree(precompNestedInclude)
        self.assertEqual(tree.totalLines(), 7)

    def testTotalLinesWithChildren(self):
        tree = self.getTree(precompTwoIncludes)
        self.assertEqual(tree.totalLines(), 7)

    def testTwoGnuCppIncludes(self):
        tree = self.getTree(precompGnuCpp)
        self.assertEqual(tree.name(), "test.cpp")
        self.assertEqual(tree.lines(), 4)
        self.assertEqual(len(tree.children()), 2)
        self.assertEqual(tree.children()[0].name(), "testa.h")
        self.assertEqual(tree.children()[1].name(), "testb.h")
Esempio n. 5
0
class TestDepend(MockTestCase):
    def setUp(self):
        self.depend = Depend()
        self.builder = self.mock()
        self.depend.builder = self.builder

    def expects(self):
        return self.builder.expects(once())

    def expectEnd(self):
        self.expects().end()

    def expectNode(self, file, name):
        return self.expects().node(eq(file), eq(name))

    def expectLine(self):
        return self.expects().line()

    def feed(self, text):
        self.depend.feed([text])

    def testOneNode(self):
        self.expectNode("test.cpp", "test.cpp")
        self.expectEnd()
        self.feed('#line 1 "test.cpp"')

    def testTwoFeeds(self):
        self.expectNode("a.cpp", "a.cpp")
        self.expectEnd()
        self.expectNode("b.cpp", "b.cpp")
        self.expectEnd()
        self.feed('#line 1 "a.cpp"')
        self.feed('#line 1 "b.cpp"')

    def testWindowsFilenameWithPath(self):
        self.expectNode("C:\\doodaa\\day\\test.cpp", "test.cpp")
        self.expectEnd()
        self.feed('#line 2 "C:\\doodaa\\day\\test.cpp"')

    def testUnixFilenameWithPath(self):
        self.expectNode("/home.chris/src/test.cpp", "test.cpp")
        self.expectEnd()
        self.feed('#line 2 "/home.chris/src/test.cpp"')

    def testGnuCppNode(self):
        self.expectNode("test.cpp", "test.cpp")
        self.expectEnd()
        self.feed('# 1 "test.cpp"')

    def testGnuCppNodeType2(self):
        self.expectEnd()
        self.feed('# 1 "<built-in>"')

    def testGnuCppNodeType3(self):
        self.expectNode("testa.h", "testa.h")
        self.expectEnd()
        self.feed('# 1 "testa.h" 1')

    def testOneLine(self):
        self.expectLine()
        self.expectEnd()
        self.feed("struct a;")

    def testEmptyLine(self):
        self.expectLine()
        self.expectEnd()
        self.feed("")

    def testGetTree(self):
        self.expects().getTree()
        self.depend.getTree()
Esempio n. 6
0
class TestDepend(MockTestCase):
  def setUp(self):
    self.depend = Depend()
    self.builder = self.mock()
    self.depend.builder = self.builder

  def expects(self):
    return self.builder.expects(once())

  def expectEnd(self):
    self.expects().end()

  def expectNode(self, file, name):
    return self.expects().node(eq(file), eq(name))

  def expectLine(self):
    return self.expects().line()

  def feed(self, text):
    self.depend.feed([text])
    
  def testOneNode(self):
    self.expectNode("test.cpp", "test.cpp")
    self.expectEnd()
    self.feed('#line 1 "test.cpp"')

  def testTwoFeeds(self):
    self.expectNode("a.cpp", "a.cpp")
    self.expectEnd()
    self.expectNode("b.cpp", "b.cpp")
    self.expectEnd()
    self.feed('#line 1 "a.cpp"')
    self.feed('#line 1 "b.cpp"')

  def testWindowsFilenameWithPath(self):
    self.expectNode("C:\\doodaa\\day\\test.cpp", "test.cpp")
    self.expectEnd()
    self.feed('#line 2 "C:\\doodaa\\day\\test.cpp"')

  def testUnixFilenameWithPath(self):
    self.expectNode("/home.chris/src/test.cpp", "test.cpp")
    self.expectEnd()
    self.feed('#line 2 "/home.chris/src/test.cpp"')

  def testGnuCppNode(self):
    self.expectNode("test.cpp", "test.cpp")
    self.expectEnd()
    self.feed('# 1 "test.cpp"')

  def testGnuCppNodeType2(self):
    self.expectEnd()
    self.feed('# 1 "<built-in>"')

  def testGnuCppNodeType3(self):
    self.expectNode("testa.h", "testa.h")
    self.expectEnd()
    self.feed('# 1 "testa.h" 1')

  def testOneLine(self):
    self.expectLine()
    self.expectEnd()
    self.feed("struct a;")

  def testEmptyLine(self):
    self.expectLine()
    self.expectEnd()
    self.feed("")

  def testGetTree(self):
    self.expects().getTree()
    self.depend.getTree()