Posted to tcl by apn at Tue Oct 08 06:28:49 GMT 2024view raw
- # Extremely simplistic to illustrate. Does not deal with namespaces, will not handle
- # mocking commands used within the redefinition (lindex, puts etc.)
- proc mock {cmd} {
- rename $cmd ${cmd}_original
- proc $cmd args {
- set me [lindex [info level 0] 0]
- incr ::counts($me)
- puts Trace:[info level 0]
- tailcall {*}${me}_original {*}$args
- }
- }
- % mock format
- % format %s%d foo 42
- Trace:format %s%d foo 42
- foo42
- % format %s%d foo 43
- Trace:format %s%d foo 43
- foo43
- % set counts(format)
- 2
- % format %s%d foo 44
- Trace:format %s%d foo 44
- foo44
- % set counts(format)
- 3