forked from pmichaud/pmtcl
/
test_more.tcl
113 lines (94 loc) · 3.11 KB
/
test_more.tcl
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#
# Analog to perl's Test::More
#
# Originally developed because running tcltest.tcl is daunting. Still in use
# because it lets us generate TAP output to work with the perl-based
# tests also at this level.
proc skip_all {} {
puts 1..0
}
proc plan {number} {
if {$number eq "no_plan"} {
global very_bad_global_variable_test_num
puts 1..$very_bad_global_variable_test_num
} {
puts 1..$number
}
}
set very_bad_global_variable_test_num 0
# The special argument, if passed, should be a two element list, e.g.
# {TODO "message"}
proc is {value expected {description ""} {special {}}} {
global very_bad_global_variable_test_num
incr very_bad_global_variable_test_num
set num $very_bad_global_variable_test_num
set type ""
if {[llength $special] == 2} {
set type [string toupper [lindex $special 0]]
set special_reason [concat {*}[lindex $special 1]]
set description [regsub -all # $description {\#}]
set description " - $description # $type $special_reason"
} else {
if {$description ne ""} {
set description " - $description"
}
}
if {$value eq $expected} {
puts "ok $num$description"
return 1
} {
puts "not ok $num$description"
if {$type ne "TODO"} {
set formatted_value [join [split $value "\n"] "\n# "]
set formatted_expected [join [split $expected "\n"] "\n# "]
diag "\n# Failed test #$very_bad_global_variable_test_num\n# got : '$formatted_value'\n# expected : '$formatted_expected'"
}
return 0
}
}
proc eval_is {code expected {description ""} {special {}}} {
global very_bad_global_variable_test_num
# The one case where skip actually means "don't do that"
if {[llength $special] == 2} {
set boolean [string compare -nocase [lindex $special 0] skip]
if {! $boolean} {
global very_bad_global_variable_test_num
incr very_bad_global_variable_test_num
puts "ok $very_bad_global_variable_test_num # $special"
return 1
}
}
catch {uplevel #0 $code} actual
is $actual $expected $description $special
}
proc ok {value {description ""} {special {}}} {
is $value 1 $description $special
}
proc not_ok {value {description ""} {special {}}} {
set value [expr !$value]
ok $value $description $special
}
proc pass {{description ""} {special ""}} {
ok 1 $description $special
}
proc like {value regexp {description ""}} {
if {[regexp $regexp $value]} {
pass $description
} else {
is "STRING: $value" "REGEXP: $regexp" $description
}
}
proc isnt {code expected {description ""} {special {}}} {
set code "\"\[eval {$code}\]\""
set expected "\"$expected\""
cmp_ok $code ne $expected $description $special
}
proc cmp_ok {left op right {description ""} {special {}}} {
ok "expr {$left $op $right}" $description $special
}
proc fail {{description ""} {special ""}} {
is "something else: $description" {something} $description $special
}
proc diag {diagnostic} {
puts stderr "# $diagnostic"
}