File: run.tcl

package info (click to toggle)
gocode 0~git20140530-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 760 kB
  • ctags: 492
  • sloc: lisp: 212; tcl: 60; python: 55; sh: 50; ruby: 46; makefile: 9
file content (78 lines) | stat: -rwxr-xr-x 1,441 bytes parent folder | download | duplicates (2)
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
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env tclsh

set red "\033\[0;31m"
set grn "\033\[0;32m"
set nc  "\033\[0m"

set pass "${grn}PASS!${nc}"
set fail "${red}FAIL!${nc}"

set stats.total 0
set stats.ok 0
set stats.fail 0

proc print_fail_report {t out expected} {
	global fail

	set hr [join [lrepeat 65 "-"] ""]
	puts "${t}: ${fail}"
	puts $hr
	puts "Got:\n${out}"
	puts $hr
	puts "Expected:\n${expected}"
	puts $hr
}

proc print_pass_report {t} {
	global pass

	puts "${t}: ${pass}"
}

proc print_stats {} {
	global red grn nc stats.total stats.ok stats.fail

	set hr [join [lrepeat 72 "█"] ""]
	set hrcol [expr {${stats.fail} ? $red : $grn}]
	puts "\nSummary (total: ${stats.total})"
	puts "${grn}  PASS${nc}: ${stats.ok}"
	puts "${red}  FAIL${nc}: ${stats.fail}"
	puts "${hrcol}${hr}${nc}"
}

proc read_file {filename} {
	set f [open $filename r]
	set data [read $f]
	close $f
	return $data
}

proc run_test {t} {
	global stats.total stats.ok stats.fail

	incr stats.total
	set cursorpos [string range [file extension [glob "${t}/cursor.*"]] 1 end]
	set expected [read_file "${t}/out.expected"]
	set filename "${t}/test.go.in"

	set out [read_file "| gocode -in ${filename} autocomplete ${filename} ${cursorpos}"]
	if {$out eq $expected} {
		print_pass_report $t
		incr stats.ok
	} else {
		print_fail_report $t $out $expected
		incr stats.fail
	}
}

if {$argc == 1} {
	run_test $argv
} else {
	foreach t [lsort [glob test.*]] {
		run_test $t
	}
}

print_stats