]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/coverage.py
Merge with master
[lilypond.git] / buildscripts / coverage.py
index a3b68dd58d074230c5fb5598c1978ce5f15e4da4..ed7d0eef255a59078d796e2a7341e25e518df054 100644 (file)
@@ -69,11 +69,30 @@ class Chunk:
                 cov = ''
             sys.stdout.write ('%8s:%8d:%s' % (cov, n, l))
             
+    def uncovered_score (self):
+        return self.length ()
+    
+class SchemeChunk (Chunk):
+    def uncovered_score (self):
+        text = self.text ()
+        if (text.startswith  ('(define ')
+            and not text.startswith ('(define (')):
+            return 0
+
+        if text.startswith  ('(use-modules '):
+            return 0
+
+        if (text.startswith  ('(define-public ')
+            and not text.startswith ('(define-public (')):
+            return 0
+
+        return len ([l for (c,n,l) in self.lines() if (c == 0)]) 
+
 def read_gcov (f):
     ls = []
 
     in_lines = [l for l in open (f).readlines ()]
-    (count_len, line_num_len) = tuple (map (len, in_lines[0].split':')[:2]))
+    (count_len, line_num_len) = tuple (map (len, in_lines[0].split (':')[:2]))
     
     for l in in_lines:
         c = l[:count_len].strip ()
@@ -120,28 +139,22 @@ def get_scm_chunks (ls, file):
     chunk = []
 
     def new_chunk ():
-        nums = [n-1 for (n, l) in chunk]
-        chunks.append (Chunk ((min (nums), max (nums)+1),
-                              last_c, ls, file))
-        chunk = []
+        if chunk:
+            nums = [n-1 for (n, l) in chunk]
+            chunks.append (SchemeChunk ((min (nums), max (nums)+1),
+                                        max (last_c, 0), ls, file))
+            chunk[:] = []
         
     last_c = -1
-    for (c, n, l) in ls:
-
-        if l.startswith ('(define'):
+    for (cov_count, line_number, line) in ls:
+        if line.startswith ('('):
             new_chunk ()
-            last_c =
-            continue
+            last_c = -1
         
-        if not (c == last_c or c < 0):
+        chunk.append ((line_number, line))
+        if cov_count >= 0:
+            last_c = cov_count
 
-            
-            if chunk and last_c >= 0:
-
-        chunk.append ((n,l))
-        if c >= 0:
-            last_c = c
-            
     return chunks
 
 def widen_chunk (ch, ls):
@@ -218,7 +231,7 @@ def main ():
 
         if options.uncovered:
             chunks = filter_uncovered (chunks)
-            chunks = [(c.length (), c) for c in chunks]
+            chunks = [(c.uncovered_score (), c) for c in chunks if c.uncovered_score() > 0]
         elif options.hotspots:
             chunks = [((c.coverage_count, -c.length()), c) for c in chunks]