我正在尝试创建一个可以通过编程方式运行的测试套件。 (The documentation确实mention可以取笑IDE进行测试运行,但在我看来,更常规的方法是将测试套件设置为标准的Ceylon模块,它具有自己的{{ 3}}。此外,文档没有说明如何以IDE的方式实现它。
所以,我正在使用runnable unit函数创建TestRunner。所述函数采用createTestRunner s(' TestSource[]
')的顺序作为其第一个参数。 TestSource
是此类型的别名:
Module|Package|ClassDeclaration|FunctionDeclaration|Class<Anything,Nothing>|FunctionModel<Anything,Nothing>|String
提出问题:我如何将测试提供给测试运行器?
对于初学者来说,最简单的方法是将它们放在本地函数中然后让测试运行器以某种方式访问这些函数(未进一步指定)。
由于TestSource
别名中包含的长类型列表似乎并不包含实际TestSource,因此我尝试寻找最接近的候选人,看起来是正确的:{{3 }}
为了进行这样的函数声明,我首先要思考我的测试包装函数实际上是什么样子。也许是这样的?
Anything myTests1 () {
// assert something!
return null;
}
void myTests2 () {
// assert some more things!
}
(顺便说一下,Functions)
在经过大量FunctionDeclaration后,我认为这些函数的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
类型&#39;功能声明&#39;根本就没有以TestSource
类型传递。为什么不? FunctionDeclaration
不是正确的TestSource类型吗?查看TestSource
的别名定义,FunctionDeclaration
似乎在可能的类型列表中就在那里:
Module|Package|ClassDeclaration|FunctionDeclaration|Class<Anything,Nothing>|FunctionModel<Anything,Nothing>|String
我在这里缺少什么?
答案 0 :(得分:2)
这是一个FunctionDeclaration
字面值:
`function myTests1`
(与Function
相对,`myTests1`
没有关键字。第一个是ceylon.language.meta.declaration
中的 detyped 模型,第二个是静态类型ceylon.language.meta.model
中的模型。请参阅Tour, The metamodel。)
所以我认为你应该为测试跑步者做的是:
value myTestRunner = createTestRunner([`function myTests1`, `function myTests2`]);
(但我自己从未这样做过。)
您在Herd上找到的是ceylon.ast
,这是一组完全不相关的模块,可让您描述 Ceylon源代码。您的myFunctionDeclaration
描述了函数的抽象语法树
Anything myName();
但仅限于语法级别:函数永远不会被编译。元模型的东西你不需要ceylon.ast
。 (另请注意,这是一个函数声明,而不是函数定义。它在语法上是有效的,但不会被typechecker接受,因为它没有注释{{1} }。)
作为旁注,formal
模块提供了更方便的实例化ceylon.ast.create
节点的方法(而不是像你一样直接使用该模块):
ceylon.ast.core