aboutsummaryrefslogtreecommitdiff
path: root/examples/jcov
blob: d993784bfaaa367da62bd3b3de555379fc75b49d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env jimsh
# vim:se syntax=tcl:

# Experimental code coverage for Jim Tcl

set auto_path [linsert $auto_path 0 [file dirname $argv0]/jimlib]

set opt_all 0
if {[lindex $argv 0] eq "-all"} {
	incr opt_all
	set argv [lrange $argv 1 end]
}

set argv [lassign $argv argv0]

set coverage($argv0) {}

proc xcov {type file line result name arglist} {
	upvar ::coverage($file) info
	incr info($line)
}

xtrace xcov

# Catch exit but not error
set rc [catch -noerror -exit {source $argv0} msg opts]

xtrace {}

proc show-coverage {filename} {
	set info $::coverage($filename)

	puts "=== $filename ==="
	set f [open $filename]
	set n 0
	while {[$f gets buf] >= 0} {
		incr n
		if {[info exists info($n)]} {
			set prefix [format "%4d: " $info($n)]
		} else {
			set b [string trimleft $buf]
			if {$b eq "" || [string match "#*" $b] || [string match "\}*" $b]} {
				set prefix "   -: "
			} else {
				set prefix "####: "
			}
		}
		puts "$prefix$buf"
	}
	$f close
}

puts [dict keys $coverage]
if {$opt_all} {
	foreach filename [lsort [dict keys $coverage]] {
		if {$filename in {"" jcov}} {
			continue
		}
		show-coverage $filename
		puts ""
	}
} else {
	show-coverage $argv0
}

#parray coverage