如何从TCL中的测试文件中获取测试文件名

如何从TCL中的测试文件中获取测试文件名,tcl,tk,Tcl,Tk,如何获取测试中正在运行的测试文件的名称?在查看谷歌后,我似乎找不到这个问题的答案。澄清: test mytest-1.1 { my test tests ... } -body { # Command to get name of file we're currently in. } -result 0 我去获取注释所在的.test文件的名称 注意:这不是一个重复的问题,因为我不想知道测试的名称,而是测试文件的名称。这是对已经介绍的内容的一个轻微扩展。研究并注意源类型帧的文件记

如何获取测试中正在运行的测试文件的名称?在查看谷歌后,我似乎找不到这个问题的答案。澄清:

test mytest-1.1 {
   my test tests ... 
} -body {
    # Command to get name of file we're currently in.
} -result 0
我去获取注释所在的.test文件的名称


注意:这不是一个重复的问题,因为我不想知道测试的名称,而是测试文件的名称。

这是对已经介绍的内容的一个轻微扩展。研究并注意源类型帧的
文件
记录:

[dict get $frameInfo file]
扩展示例:

package req tcltest

proc example {} {
    for {set i 1} {$i<=[info frame]} {incr i} {
    set frameInfo [info frame $i]
    set frameType [dict get $frameInfo type]
    set cmd [dict get $frameInfo cmd]

    if {$frameType eq "source" && [lindex $cmd 0] eq "tcltest::test"} {
        puts $frameInfo
        puts "Called from [lindex $cmd 1] defined in '[dict get $frameInfo file]'"
        return ok
    }
    }

    return notok

}

tcltest::test foo-1.1 {testing the foo} {
    example
} ok

可能重复的请参阅我的编辑,它不是重复的。一旦您阅读了文档,它是大量冗余的;)但是,严格来说,不是重复的,同意。所以我需要创建一个完整的过程并逐步通过一个循环来获取名称,还是有一行命令(如果我错了,请纠正我,但如果我只是使用“set frameInfo[info frame$I]”后跟“[dict get$frameInfo file]”谢谢您的编辑mrcalvin,尽管我想指出,info脚本给出了文件的完整路径,info帧0行给出了以下错误:字典中的键“file”未知。因此,如果你能提供一些关于这个问题的信息,我会选择这个答案。如果有人知道答案,请告诉我,因为我真的搞不懂。@Ken
[info frame]
取决于调用(或激活)上下文,类似于:显式
源代码
与隐式源代码(通过
tclsh
)<代码>信息脚本
对此不可知,因为正在评估的脚本直接向当前解释器注册。。。。因此,只需在测试主体内使用
[info script]
,或者在使用专用的自省命令(如
示例
)时使用
[dict get$frameInfo file]
。。。但不是两者都有,以避免误解。
tcltest::test foo-1.1 {testing the foo} {
    puts [info script]
    # puts [dict get [info frame 0] file]; # context dependent
} ok