testing - 如何从一个文件位置获取数据并使用 tcl 代码运行

标签 testing tcl automated-tests

在 tcl 中如何从一个文件位置获取数据并使用 TCL 代码运行该数据。 例如 在文件夹 1 中有配置文件,我想获取配置文件的信息,我想执行存在或不存在的信息,

最佳答案

如果配置文件包含Tcl代码,它只是:

# Put the filename in quotes if you want, or in a variable, or ...
source /the/path/to/the/file.tcl

如果文件包含 Tcl 代码但您不信任它,您可以使用“安全解释器”上下文。这会禁用许多命令,提供一组更受限制的功能,然后您可以向这些功能添加特定的异常(exception)(使用 interp 别名):

# Make the context
set i [interp create -safe]

# Set up a way for the context to let the master find out about what to
# really set
interp alias $i configure {} recordConfiguration
proc recordConfiguration args {
    puts "configured with $args"
}

# Evaluate the script (note that [source] is hidden by default) in the context
$i invokehidden source /the/path/to/the/file.tcl

# Dispose the context
interp delete $i

如果文件不是 Tcl 代码,您必须解析它。这是一个复杂得多的问题,复杂到我们需要知道文件的格式才能回答。

关于testing - 如何从一个文件位置获取数据并使用 tcl 代码运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21844843/

相关文章:

javascript - 类型错误 : Cannot read property 'createElement' of null

Delphi GUI 测试和模态表单

python - 如何在python中的时间序列之间有效地映射数据

java - 使用 ArrayList 私有(private)成员测试类

python - Tkinter:root.after(), root.after_cancel()

tcl - 如何将 tcl 字符串视为十六进制数并将其转换为二进制?

java - Selenium - 错误 : Caught exception [ERROR: Unsupported command [clickAt]

scala - 什么是 sbt 的 "testQuick"的 gradle 等价物

tcl - TCL中upvar 0和upvar 1的区别

silverlight - Silverlight 应用程序的自动化测试 : MS Test Manager vs Selenium