-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestlib.tcl
More file actions
54 lines (48 loc) · 1.13 KB
/
testlib.tcl
File metadata and controls
54 lines (48 loc) · 1.13 KB
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
set ::passcount 0
set ::assertcount 0
set ::current_test ""
proc assert { a op b args } {
incr ::assertcount
if "{$a} $op {$b}" {
incr ::passcount
puts -nonewline "."
} else {
set extra ""
if { [string length $args] != 0 } {
set extra " ($args)"
}
error "{$a} doesn't $op {$b}$extra"
}
}
proc expect { a op b args } {
incr ::assertcount
if "{$a} $op {$b}" {
incr ::passcount
puts -nonewline "."
} else {
set extra ""
if { [string length $args] != 0 } {
set extra " ($args)"
}
puts stderr "${::current_test}: {$a} doesn't $op {$b}$extra"
}
}
proc assert_noerr code {
set ev [catch [list uplevel $code] msg]
assert $ev == 0
}
proc assert_err code {
set ev [catch [list uplevel $code] msg]
assert $ev == 1 "expected error"
}
proc test {name body} {
set ::current_test $name
if [catch $body msg] {
puts stderr "${::current_test}: $msg"
}
set ::current_test ""
}
proc bench {code} {
set res [uplevel "time {$code} 8"]
puts "[string trim $code]: $res"
}