关于tcl测试的问题
我有一个关于 Tcl 的问题,我们正在使用 Tcl 为 C 和 C++ 应用程序编写一些测试用例。我看到一些 Tcl 测试用例是:
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
这些代码如何工作? #START: 和 #END: 意味着什么?以及为什么他们有索引,例如:
HELLO1 HELLO2 HELLO3
任何人都可以帮助我吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于 Tcl 术语来说,这些测试看起来非常奇怪。如果他们读成这样(带有额外的分号):
那么他们只会被屏蔽掉什么都不做的代码(字面意思是;Tcl 不会尝试为其生成代码,就像 C 或 C++ 编译器不太可能为
if(0){...}
做很多事情),但您得到的版本只是一个语法错误。大括号后面不应跟空格以外的任何内容(除非它是特殊的{*}
语法,它会扩展替换)。也就是说,我希望测试代码看起来更像这样:
doATest
可能会根据某些逻辑忽略测试,但整个脚本会被忽略。 (Tcl 自己的内置测试工具 -tcltest
包 - 遵循此模式,并带有一些额外的参数来控制诸如运行测试的条件和预期结果之类的事情。)Those are very odd looking tests by Tcl terms. If they'd read like this (with the extra semicolon):
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:
The
doATest
might ignore the test based on some logic, but the overall script would be oblivious. (Tcl's own built-in test harness — thetcltest
package — follows this pattern with some extra parameters for controlling things like the conditions under which to run the test and the expected result.)哈希开始注释,但要小心。
http://wiki.tcl.tk/1669
Hashes begin comments, but be careful.
http://wiki.tcl.tk/1669
那是一些非常奇怪的 Tcl 代码。它看起来像专有(?)测试工具的语法。您能给我们关于测试工具名称的任何其他提示吗?
一般来说,
#
会启动一条注释(尽管比这稍微复杂一些),而if {0}
会有效地阻止下面的代码块运行。也许您的测试工具提取 START 和 END 之间的代码并在测试模式下运行它,否则代码将被忽略?不过,}#
(即:两者之间没有空格)通常应该抛出语法错误。您确定您向我们展示了测试代码的具体内容吗?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) andif {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?