如何在规范中包含外部源文件以指定措施?
我正在使用 Specs2 编写测量库的规范。为了验证计算出的测量值,我有大量源文件,涵盖标准情况以及许多极端情况。我确实手动分析了它们,以了解确切的测量结果,但为了记录所有内容并使其自动化,这应该是 Specs2 规范的一部分。
到目前为止,我将一些源文件复制到我的规范中,并将其作为字符串传递给验证方法。然而,这有一个缺点,即不再检查内联代码 - 外部文件由标准编译器验证,因此我确信它是有效的代码。仅传递文件名是没有问题的,但我的规范应该在生成的 HTML 报告中包含源代码,而不仅仅是指向必须手动挖掘和查看的文件。为了给您一些想法,我现在正在使用的代码
class CountVisitorSpec extends Specification { def is =
"Given the ${com/example/Test1.java} source, the visitor should deliver a count of ${16}" ! new GivenThen {
def extract(text: String) = {
val (filename, count) = extract2(text)
val file = classOf[CountVisitorSpec].getClassLoader.getResource(filename).getFile
val src = Path(file).slurpString
val visitor = new CountVisitor
AstAnalyzer.runWith(src, visitor)
visitor.count must_== count.toLong
}
}
}
有人知道如何指向外部文件,以便将它们作为初始输入包含在生成的 HTML 报告中吗?
I'm using Specs2 to write a specification for a measurement library. To verify the calculated measures I have numerous source files covering standard cases as well as a lot of corner cases. I did analyze them manually to I know the exact measures, but to document everything and automate it, this should be part of a Specs2 specification.
So far I copied some of the source files into my specification and passed it to the verifying methods as string. However, this has the downside, that the inlined code isn't checked anymore - the external files are verified by the standard compiler so I'm sure it is valid code. It's no problem to just pass the filename, but my specification should include the source code in the resulting HTML report and not only point to a file one has to dig out and look at manually. To give you some idea here is the code I'm using right now
class CountVisitorSpec extends Specification { def is =
"Given the ${com/example/Test1.java} source, the visitor should deliver a count of ${16}" ! new GivenThen {
def extract(text: String) = {
val (filename, count) = extract2(text)
val file = classOf[CountVisitorSpec].getClassLoader.getResource(filename).getFile
val src = Path(file).slurpString
val visitor = new CountVisitor
AstAnalyzer.runWith(src, visitor)
visitor.count must_== count.toLong
}
}
}
Does someone have an idea, how it is possible to point to the external files so that they are included as initial input in the resulting HTML report?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该只是封装你想要的内容的问题:
然后:
That should be just a matter of encapsulating what you want:
And then: