unit testing - Creating a ceylon.test.TestRunner -


i'm trying create test suite can run programmatically. (the documentation mention 1 can tease ide doing test running, seems me more regular approach set test suite standard ceylon module has own runnable unit. also, documentation doesn't how ide way).

so, i'm creating testrunner using createtestrunner function. said function takes sequential of testsources ('testsource[]') first argument. testsource alias type:

module|package|classdeclaration|functiondeclaration|class<anything,nothing>|functionmodel<anything,nothing>|string 

which promts question: how want feed tests test runner?

for starters seems easiest put them in local functions , let test runner access these functions somehow (not further specified). long list of types included in testsource alias doesn't seem include actual functions, tried go nearest candidate looked right thing: functiondeclaration.

in order make such function declaration, first had ponder how test wrapper functions might like. perhaps this?

anything mytests1 () {     // assert something!     return null; }  void mytests2 () {     // assert more things! } 

(these functions typewise equivalent, way)

after lot of ceylon herd scrutiny, figured functiondeclaration such functions spelled out this:

// function name function declaration: lidentifier funname = lidentifier("myname");  // type of return value function declaration: uidentifier returntypename1 = uidentifier("anything"); typenamewithtypearguments returntypename2 = typenamewithtypearguments(returntypename1); basetype returntype = basetype( returntypename2 );  // type of parameters function declaration: sequential<parameter> parameters1 = [];  // our test wrapper functions takes no arguments parameters parameters2 = parameters( parameters1 ); sequence<parameters> parameterlists = [parameters2];  // actual function declaration: functiondeclaration myfunctiondeclaration = functiondeclaration(     funname,     returntype,     parameterlists ); 

so now, had feed createtestrunner function. had put myfunctiondeclaration testsource[]:

testsource mytestsource = myfunctiondeclaration; testsource[] mysourcelist = [mytestsource]; testrunner mytestrunner = createtestrunner(mysourcelist); 

but first line doesn't work. myfunctiondeclaration of type 'functiondeclaration' doesn't pass testsource type. why not? functiondeclaration not proper testsource type? looking @ alias definition testsource, functiondeclaration seems right there in list of possible types:

module|package|classdeclaration|functiondeclaration|class<anything,nothing>|functionmodel<anything,nothing>|string 

what missing here?

this functiondeclaration literal:

`function mytests1` 

(as opposed function, `mytests1` without keyword. first detyped model in ceylon.language.meta.declaration, second statically typed model in ceylon.language.meta.model. see tour, metamodel.)

so think you’re supposed test runners is:

value mytestrunner = createtestrunner([`function mytests1`, `function mytests2`]); 

(but i’ve never done myself.)

what found on herd ceylon.ast, unrelated set of modules lets describe ceylon source code. myfunctiondeclaration describes abstract syntax tree of function

anything myname(); 

but @ syntax level: function never compiled. don’t need ceylon.ast metamodel stuff. (note function declaration, not function definition. it’s syntactically valid, won’t accepted typechecker because it’s not annotated formal.)

as side note, ceylon.ast.create module offers more convenient ways instantiate ceylon.ast.core nodes (instead of using module directly, did):

value fun = functiondefinition {     name = "myname";     type = basetype("anything"); }; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -