user707549
user707549

Reputation:

a question about tcl testing

I have a question about Tcl, we are using Tcl to write some test cases for c and c++ application. I saw some Tcl test cases are:

if {0} { #START:HELLO1
//some code here
}#END:HELLO1

if {0} { #START:HELLO2
//some code here
}#END:HELLO2

if {0} { #START:HELLO3
//some code here
}#END:HELLO3

How does these code works? #START: and #END: means what? and why they have index such as:

HELLO1 HELLO2 HELLO3

can anyone help me on this?

Upvotes: 1

Views: 320

Answers (3)

Donal Fellows
Donal Fellows

Reputation: 137567

Those are very odd looking tests by Tcl terms. If they'd read like this (with the extra semicolon):

if {0} { #START:HELLO1
//some code here
};#END:HELLO1

Then they'd just be blocked out code that does nothing (literally; Tcl won't attempt to generate code for it, just as a C or C++ compiler is unlikely to do much for if(0){...}) but the version you've got is just a syntax error. Braces shouldn't be followed by anything other than whitespace (unless it is the special {*} syntax, which does expanding substitution).

That said, I'd expect testing code to look more like this:

doATest "the test name" {
    // Whatever makes the body of the test, in whatever language
}

The doATest might ignore the test based on some logic, but the overall script would be oblivious. (Tcl's own built-in test harness — the tcltest package — follows this pattern with some extra parameters for controlling things like the conditions under which to run the test and the expected result.)

Upvotes: 1

Bryan Oakley
Bryan Oakley

Reputation: 385970

That is some very strange Tcl code. It looks like the syntax to a proprietary (?) testing tool. Can you give us any other hints about the name of the testing tool?

In general, # starts a comment (though it's a little more complicated than that) and if {0} effectively prevents the following block of code from running. Maybe your testing tool extracts the code between START and END and runs it when in testing mode, and the code is ignored otherwise? Though, }# (ie: with no space between the two) should normally throw a syntax error. Are you sure you're showing us exactly what the testing code looks like?

Upvotes: 1

bitbucket
bitbucket

Reputation: 1171

Hashes begin comments, but be careful.

http://wiki.tcl.tk/1669

Upvotes: 1

Related Questions