Tom Tromey wrote:
"Jacob" == Jacob Bachmeyer <jcb62...@gmail.com> writes:
Jacob> API call: testcase group begin <name>
Jacob> API call: testcase group end <name>
Jacob> Begin or end test group <name> where <name> is either a string that
Jacob> may contain multiple /-delimited parts or a Tcl list that will be
Jacob> joined into such a string. Each call to "testcase group begin" must
Jacob> have a matching call to "testcase group end" with exactly the same
Jacob> name in both calls and both calls must be in the same file.
How about just having a single call which takes a block of code:
testcase group NAME {
# your code here
}
This is easy to do in Tcl and will avoid any bugs involving incorrect
pairing.
I had not thought of that.
Would passing a code block inhibit byte-compiliation? I think that Tcl
would be able to byte-compile a procedure containing calls to "testcase
group {begin|end}" including the code that runs the tests in between,
but passing code to a procedure as a parameter results in the code being
passed as a string and parsed/evaluated when run. I would be happy to
be mistaken here. (If I remember correctly, Tcl built-in control
structures avoid this problem by implementing "compilation handlers" or
something like that, but the API for that is only available in C.)
Part of the planned use for this feature is for lib/dg.exp in DejaGnu to
group tests from each input file. At a quick glance, the procedures in
that module should be byte-compilable, and the opportunistic bytecode
JIT is a major contributor to modern Tcl's acceptable performance
compared to other systems and older versions of Tcl.
With a slight change of putting the group name consistently immediately
after "testcase group", both forms could be easily supported, with code
blocks recognized because they will always contain whitespace, while
command keywords will not. This would allow modules to use the
begin|end pair inside compilable procedures, while test scripts
executing outside of any procedure can use the simpler "testcase group
<name> { test code here }" syntax.
Instead of moving the group name parameter, another option for passing a
block would be "testcase group eval <name> { test code here }" patterned
after Tcl's "namespace eval" command. Again, this provides an
"idiot-proof" option for simple scripts, while allowing modules to use
an alternate interface in compilable procedures.
-- Jacob