我正在尝试创建一个可以以编程方式运行的测试套件。(文献资料做了提及,你可以戏弄一个IDE来运行测试,但在我看来,这是一种更常规的方法,可以将测试套件设置为一个标准的锡兰模块,它有自己的可运行单元。另外,文档中没有提到如何以IDE的方式实际实现)。
因此,我正在使用TestRunner函数创建一个createTestRunner。所述函数以TestSources ('TestSource[]')的顺序作为其第一个参数。TestSource是此类型的别名:
Module|Package|ClassDeclaration|FunctionDeclaration|Class<Anything,Nothing>|FunctionModel<Anything,Nothing>|String这就提出了一个问题:我要如何向测试运行者提供测试信息?
首先,似乎最容易将它们放在本地函数中,然后让测试运行程序以某种方式访问这些函数(没有进一步指定)。由于TestSource别名中包含的类型的长列表似乎不包括实际的函数,所以我尝试寻找看起来最接近的候选对象:FunctionDeclaration。
为了做出这样的函数声明,我首先必须考虑一下我的测试包装器函数的实际外观。也许是这样的?
Anything myTests1 () {
// assert something!
return null;
}
void myTests2 () {
// assert some more things!
}(顺便说一句,这些函数在类型上等价。)
在经历了大量的锡兰畜群审查之后,我认为这样的函数的FunctionDeclaration可以如下所示:
// function name for function declaration:
LIdentifier funName = LIdentifier("myName");
// type of return value for function declaration:
UIdentifier returnTypeName1 = UIdentifier("Anything");
TypeNameWithTypeArguments returnTypeName2 = TypeNameWithTypeArguments(returnTypeName1);
BaseType returnType = BaseType( returnTypeName2 );
// type of parameters for function declaration:
Sequential<Parameter> parameters1 = []; // our test wrapper functions takes no arguments
Parameters parameters2 = Parameters( parameters1 );
Sequence<Parameters> parameterLists = [parameters2];
// the actual function declaration:
FunctionDeclaration myFunctionDeclaration = FunctionDeclaration(
funName,
returnType,
parameterLists
);所以现在,我所要做的就是把这个输入到createTestRunner函数中。我只需要把myFunctionDeclaration放进TestSource[]
TestSource myTestSource = myFunctionDeclaration;
TestSource[] mySourceList = [myTestSource];
TestRunner myTestRunner = createTestRunner(mySourceList);但第一行不起作用。类型为“myFunctionDeclaration”的FunctionDeclaration根本不作为TestSource类型传递。为什么不行?FunctionDeclaration不是一个合适的TestSource类型吗?查看TestSource的别名定义,FunctionDeclaration似乎就在可能的类型列表中:
Module|Package|ClassDeclaration|FunctionDeclaration|Class<Anything,Nothing>|FunctionModel<Anything,Nothing>|String我在这里错过了什么?
发布于 2017-09-10 20:43:29
这是一个FunctionDeclaration文本:
`function myTests1`(与没有关键字的Function相反,它是`myTests1`。第一个是ceylon.language.meta.declaration中的去类型模型,第二个是ceylon.language.meta.model中的静态类型模型。见巡演,元模型.)
所以我认为你应该为测试者做的是:
value myTestRunner = createTestRunner([`function myTests1`, `function myTests2`]);(但我自己从来没有这么做过。)
您在Herd上找到的是ceylon.ast,这是一组完全不相关的模块,可以用来描述锡兰的源代码。您的myFunctionDeclaration描述了函数的抽象语法树
Anything myName();但只在语法级别:函数从未编译过。元模型不需要ceylon.ast。(还请注意,这是一个函数声明,而不是函数定义。它在语法上是有效的,但不会被打字机接受,因为它没有注释formal)。
另外,ceylon.ast.create模块提供了更方便的方法来实例化ceylon.ast.core节点(而不是像您那样直接使用该模块):
value fun = functionDefinition {
name = "myName";
type = baseType("Anything");
};https://stackoverflow.com/questions/46145157
复制相似问题