I'm trying to create a test suite that I can run programmatically. (The documentation does mention that one can tease an IDE into doing the test running, but it seems to me a more regular approach to set up the test suite as a standard Ceylon module that has its own runnable unit. Also, the documentation doesn't say anything about how to actually do it the IDE way).
So, I'm creating a TestRunner using the createTestRunner function. Said function takes a Sequential of TestSources ('TestSource[]
') as its first argument. TestSource
is an alias for this type:
Module|Package|ClassDeclaration|FunctionDeclaration|Class<Anything,Nothing>|FunctionModel<Anything,Nothing>|String
Which promts the question: How do I want to feed my tests to the test runner?
For starters it seems easiest to put them in local functions and then let the test runner access these functions somehow (not further specified).
As the long list of types that are included in the TestSource
alias doesn't seem to include actual Functions, I tried to go for the nearest candidate that looked like the right thing: FunctionDeclaration.
In order to make such a function declaration, I first had to ponder how my test wrapper functions might actually look like. Perhaps something like this?
Anything myTests1 () {
// assert something!
return null;
}
void myTests2 () {
// assert some more things!
}
(these functions are typewise equivalent, by the way)
After a lot of Ceylon Herd scrutiny, I figured that a FunctionDeclaration
for such functions could be spelled out like this:
// 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
);
So now, all I had to do was to feed this to the createTestRunner
function. I just had to put myFunctionDeclaration
into a TestSource[]
:
TestSource myTestSource = myFunctionDeclaration;
TestSource[] mySourceList = [myTestSource];
TestRunner myTestRunner = createTestRunner(mySourceList);
But that first line doesn't work. myFunctionDeclaration
of type 'FunctionDeclaration' simply doesn't pass as a TestSource
type. Why not? Is FunctionDeclaration
not a proper TestSource type? Looking at the alias definition for TestSource
, FunctionDeclaration
seems to be right there in the list of possible types:
Module|Package|ClassDeclaration|FunctionDeclaration|Class<Anything,Nothing>|FunctionModel<Anything,Nothing>|String
What am I missing here?