Quellcode durchsuchen

added first draft of adding line-by-line coverage within ViM using Go

bmallred vor 10 Jahren
Ursprung
Commit
75d6cb7c2c
4 geänderte Dateien mit 94 neuen und 0 gelöschten Zeilen
  1. 18 0
      size.go
  2. 22 0
      size_test.go
  3. 2 0
      umbrella
  4. 52 0
      umbrella.py

+ 18 - 0
size.go

@ -0,0 +1,18 @@
1
package size
2
3
func Size(a int) string {
4
    switch {
5
    case a < 0:
6
        return "negative"
7
    case a == 0:
8
        return "zero"
9
    case a < 10:
10
        return "small"
11
    case a < 100:
12
        return "big"
13
    case a < 1000:
14
        return "huge"
15
    }
16
17
    return "enormous"
18
}

+ 22 - 0
size_test.go

@ -0,0 +1,22 @@
1
package size
2
3
import "testing"
4
5
type Test struct {
6
    in int
7
    out string
8
}
9
10
var tests = []Test {
11
    { -1, "negative" },
12
    { 5, "small" },
13
}
14
15
func TestSize(t *testing.T) {
16
    for i, test := range tests {
17
        size := Size(test.in)
18
        if size != test.out {
19
            t.Errorf("#%d: Size(%d)=%s; want %s", i, test.in, size, test.out)
20
        }
21
    }
22
}

+ 2 - 0
umbrella

@ -0,0 +1,2 @@
1
go test -coverprofile=coverage.out &> /dev/null
2
python umbrella.py &> /dev/null

+ 52 - 0
umbrella.py

@ -0,0 +1,52 @@
1
#!/usr/bin/python
2
3
import os
4
5
d = {}
6
output = ""
7
8
fileName = "coverage.out"
9
if os.path.isfile(fileName):
10
    # Read the Go coverage details
11
    f = open("coverage.out", "r")
12
13
    for line in f:
14
        target = line.split(":")[0].split("/")[-1]
15
      
16
        if target == "mode":
17
            continue
18
19
        if not target in d:
20
            d[target] = [[], [], []]
21
22
        l = int(line.split(":")[1].split(" ")[-1])
23
        l2 = line.split(":")[1].split(" ")[0].split(",")
24
25
        if l > 0:
26
            for ll in l2:
27
                i = ll.split(".")[0]
28
                if not i in d[target][0]:
29
                    d[target][0].append(i)
30
        else:
31
            for ll in l2:
32
                i = ll.split(".")[0]
33
                if not i in d[target][2]:
34
                    d[target][2].append(i)
35
36
    for key in d.keys():
37
        output += "{0};{1};{2};{3};\n".format(
38
            key,
39
            ",".join(str(x) for x in d[key][0]),
40
            ",".join(str(x) for x in d[key][1]),
41
            ",".join(str(x) for x in d[key][2]))
42
43
    f.close()
44
45
    # Time to write our output file.
46
    fileName = ".umbrella-coverage"
47
    if os.path.isfile(fileName):
48
        os.remove(fileName)
49
50
    f = open(fileName, "w")
51
    f.write(output)
52
    f.close()