-
Notifications
You must be signed in to change notification settings - Fork 1
/
oc_assert-1.0.tm
85 lines (68 loc) · 1.83 KB
/
oc_assert-1.0.tm
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
#===============================================================================
# oc_assert-1.0.tm
#
# Assert Utility.
#
# Copyright Sam O'Connor 2012
# Licenced for use under the same terms as Tcl 8.6. See:
# http://core.tcl.tk/tcl/artifact/537ba3f664b958496ab51849e23d7f564342014b
# http://github.com/tcltk/tcl/raw/core_8_6_1/license.terms
#===============================================================================
package provide oc_assert 1.0
proc assert {args} {
# usage: assert command args...
# or: assert {expression}
if {[llength $args] == 1} {
if {[uplevel expr $args]} {
return
}
set args [uplevel subst $args]
} else {
if {[uplevel $args]} {
return
}
}
return -code error \
-errorcode [list assert {*}$args] \
"Assertion Failed:\n $args"
}
proc forbid {args} {
# usage: forbid command args...
# or: forbid {expression}
if {[llength $args] == 1} {
if {![uplevel expr $args]} {
return
}
set args [uplevel subst $args]
} else {
if {![uplevel $args]} {
return
}
}
return -code error \
-errorcode [list assert {*}$args] \
"Forbidden:\n $args"
}
foreach {alias cmd} {
require assert
check assert
test assert
⊢ assert
✅ assert
✓ assert
🚫 forbid
❌ forbid
❎ forbid
✗ forbid
⏳ after
🔎 regexp
💀 throw
💥 throw
💣 throw
💬 puts
} {
interp alias {} $alias {} $cmd
}
#===============================================================================
# End of file.
#===============================================================================