tcl tcltest 未知选项 -运行

tcl tcltest unknown option -run

当我 运行 进行任何测试时,我都会收到相同的消息。这是一个示例测试:

package require tcltest
namespace import -force ::tcltest::*
test foo-1.1 {save 1 in variable name foo} {} {
    set foo 1
} {1}

我得到以下输出:

WARNING: unknown option -run: should be one of -asidefromdir, -constraints, -debug, -errfile, -file, -limitconstraints, -load, -loadfile, -match, -notfile, -outfile, -preservecore, -relateddir, -singleproc, -skip, -testdir, -tmpdir, or -verbose

我已经尝试了多次测试,但似乎没有任何效果。有谁知道如何让它工作?

更新#1:

以上错误是我的错,这是因为它在我的脚本中 运行。但是,如果我 运行 在命令行中输入以下内容,则没有输出:

[root@server1 ~]$ tcl
tcl>package require tcltest
2.3.3
tcl>namespace import -force ::tcltest::*
tcl>test foo-1.1 {save 1 in variable name foo} {expr 1+1} {2}
tcl>echo [test foo-1.1 {save 1 in variable name foo} {expr 1+1} {2}]

tcl>

如何让它输出通过或失败?

您不会从 test 命令本身获得任何输出(只要测试通过,如示例所示:如果失败,命令会打印 "contents of test case" / "actual result" / "expected result" 摘要;另请参阅下面的配置说明)。测试统计数据在内部保存:您可以使用 cleanupTests 命令打印 Total/Passed/Skipped/Failed 数字(该命令还会重置计数器并进行一些清理)。

(当你 运行 runAllTests, 它 运行s 测试子进程中的文件,拦截每个文件的 cleanupTests 的输出并将它们加起来总计。)

测试期间收集的内部统计信息可在 AFACT 未记录的命名空间变量中使用,例如 ::tcltest::numTests。如果您想自己使用统计数据,可以在 调用 cleanupTests 之前访问它们 ,例如

parray ::tcltest::numTests
array set myTestData [array get ::tcltest::numTests]
set passed $::tcltest::numTests(Passed)

查看库中 tcltest 的源代码,了解可用的变量。

test命令的输出量是可配置的,如果将p / pass添加到-verbose,即使测试通过也可以得到输出] 选项。这个选项还可以让你在失败时有更少的输出等

您还可以创建一个名为 ::tcltest::ReportToMaster 的命令,如果它存在,cleanupTests 将以相关数据作为参数调用该命令。这样做似乎抑制了统计信息的输出,至少抑制了大部分的重置和清理。 (我并没有深入研究那个方法。)请注意,搞砸这个更可能是制造麻烦而不是解决问题,但是如果你正在编写自己的基于 tcltest 的测试软件,你可能仍然想看看

哦,请对 test 命令使用更新的语法。它比较冗长,但如果您开始使用它,您稍后会感谢自己。

强制性但相当无用(在本例中)文档 link:tcltest