engine-story Pub Share

Testing built-in messages and executors

overwriting the diesel.env

diesel.env will be overwritten in the current context

msg ctx.echo  (e)

expect::  (e not empty)

TODO this is not working anymore - goes through parmsource

send::  msg ctx.set  (diesel.env="testing")

send::  msg testdiesel.setlocal  (env="testing")

send::  msg diesel.catch 

msg ctx.echo  (e)

expect::  (e == "local")
TODO would be nice if this worked

$val ctx["diesel.env"] = "local"

send::  msg testdiesel.setlocal  (env="local")

0 $mock:: testdiesel.setlocal (env)
   . (ctx[="diesel"][="env"]=env)

Context echo

msg ctx.echo  (ha="haha")

expect::  (ha == "haha")

send::  msg ctx.echo  (x:Number=1)

Testing constants

// $when diesel.before // => ctx.set(DONE_BEFORE="diesel.before yeah") // $send ctx.echo(msg = DONE_BEFORE) // $expect (DONE_BEFORE contains "diesel.before yeah")

Testing generation rules in context

send::  msg ctx.set  (c="oops")

send::  msg dieseltest.rule1  (a:Number=79, b="b")

expect::  (rule1ab is "79b")
expect::  (rule1abc is undefined)
expect::  (rule1abd is undefined)

send::  msg dieseltest.rule1  (a:Number=85, b="b", c="cc")

expect::  (rule1ab is "85b")
expect::  (rule1abc is "85bcc")
expect::  (rule1abd is undefined)
expect::  (c is "oops")

Matching messages

send::  msg aha.haha.sendtest 

expect::  (rule12 is true)

send::  msg dieseltestsendtest.aha 

expect::  (rule16 is true)

send::  msg dieseltest.send.multiple.aha 

expect::  (rule18 is true)
expect::  (rule18a not defined)

send::  msg dieseltestMM.send.multiple.aha 

expect::  (rule19a is true)

send::  msg dieseltestJhaha.sendtest18 

expect::  (rule19 not defined)

send::  msg dieseltestJ.haha.sendtest18 

expect::  (rule19 is true)

send::  msg dieseltest.opt1  (b="2")

expect::  (rule61 is "2")

send::  msg dieseltest.opt2  (b="2")

expect::  (rule64 is "12")

Comments

send::  msg dieseltest.comment1 

expect::  (rule22 is 22)

Specific diesel attributes

send::  msg dieseltest.engmsg25 

expect::  (rule25 is "dieseltestengmsg25dieseltest.engmsg25")

send::  msg dieseltest.engmsg27 

expect::  (rule27 is "dieseltestengmsg27dieseltest.engmsg27")

Exclusive mock

send::  msg ctx.set  (rule69:Number=0)

send::  msg dieseltest.nonexcl1 

expect::  (rule69 is 1)

send::  msg dieseltest.nonexcl1  (a:Number=1, b:Number=1)

expect::  (rule69 is 4)

Start again, for excl:

send::  msg ctx.set  (rule69:Number=0)

send::  msg dieseltest.excl1 

expect::  (rule69 is 1)

send::  msg dieseltest.excl1  (a:Number=1, b:Number=1)

expect::  (rule69 is 3)

Exclusive rules

send::  msg ctx.set  (rule69:Number=0)

send::  msg dieseltest.rnonexcl1 

expect::  (rule69 is 1)

send::  msg dieseltest.rnonexcl1  (a:Number=1, b:Number=1)

expect::  (rule69 is 4)

Start again, for excl:

send::  msg ctx.set  (rule69:Number=0)

send::  msg dieseltest.rexcl1 

expect::  (rule69 is 1)

send::  msg dieseltest.rexcl1  (a:Number=1, b:Number=1)

expect::  (rule69 is 3)

If/else

send::  msg dieseltest.ifelse  (a:Number=2, b:Number=1)

expect::  (rule67 is 1)
// $send dieseltest.ifelse (a=2, b=3) // $expect (rule67 is 2)

Comments

val TESTVAL1:Number=1=1

send::  msg ctx.echo  (m)

// $send ctx.echo(m=TESTVAL1) LEAVE THIS COMMENTED ITS A TEST

expect::  (TESTVAL1 is 1)

Exceptions, try/catch

This is during a story - define a try-catch block

send::  msg diesel.try 

send::  msg dieseltest.failplease 

expect::  (payload is exception)
send::  msg ctx.set  (oops:Number)

send::  msg diesel.catch 

This is a sample rule that has a try-catch block:

send::  msg dieseltest.testcatchNoerr 

expect::  (x97 is "oops")

send::  msg dieseltest.testcatchWithErr 

expect::  (x97 is "haha")
// $send dieseltest.testcatchWithThrow // $expect (x97 is "haha")

send::  msg dieseltest.testcatchnothrow 

expect::  (x99 is "oops")

parm values are evaluated once:

send::  msg dieseltest.evalonce.a1 

expect::  (res77 is "dieseltest.evalonce.a1")

send::  msg dieseltest.indetedLambda 

expect::  (embedded91)

if-else

There is an $else construct

send::  msg testdiesel.else  (branch:Boolean)

expect::  testdiesel.else.if

send::  msg testdiesel.else  (branch:Boolean)

expect::  testdiesel.else.else

send::  msg testdiesel.else1  (branch:Boolean)

expect::  (res131 is "if")
expect::  testdiesel.else.if

send::  msg testdiesel.else1  (branch:Boolean)

expect::  (res131 is "else")
expect::  testdiesel.else.else

send::  msg testdiesel.expand1 

expect::  (res147 is "ok")

send::  msg testdiesel.expand4 

expect::  (res152 is "ok")

Fallback rules

send::  msg testdiesel.fback1  (r156:Number=1)

expect::  (r156 is 2)

send::  msg testdiesel.fback1  (r156:Number=3)

expect::  (r156 is 5)

Contexts and variable overwriting

Single exported variables act as most would expect

val r193:Number=1=1 send::  msg testdiesel.inc  (r193)

expect::  (r193 is 3)
// most people would expect it to be 3 - but for that, you have to export it between runs, with dieselScope.

This version is not exported, but it works because the same rule shares the same context:

send::  msg testdiesel.incLOCAL  (r202:Number=1)

expect::  (r202 is 3)
// most people would expect it to be 2 but the two rules with the same name // share the same local context

This one, being set only in the common context, it is shared between the rules. Careful when using parallel rules, you will have the same issues common with multi-threading access to common variables. Use channels or streams-story for parallel rules.

send::  msg ctx.set  (r196:Number=1)

send::  msg testdiesel.incInContext 

expect::  (r196 is 4)
// most people would expect it to be 3, but since it's in context to begin with, all 3 rules are decomposed

overwrite vars in local context

send::  msg testdiesel.bug.overwriteLocalVar  (v183="183")

expect::  (payload is "184")

Auto exporting return vlues

send::  msg testdiesel.expr.autoexport 

expect::  (a189 is 189)

Fork join

TODO this section needs review - is it obsolete?

send::  msg diesel.stream.new  (stream="dtest247")

0 $mock:: dtest.l249
   dtest.l251 (stream="dtest247"="dtest247")

0 $mock:: dtest.l251
   . (g253=253)
   diesel.stream.put (stream="dtest247"="dtest247")
   diesel.stream.done (stream="dtest247"="dtest247")

send::  msg dtest.l249 

send::  msg diesel.stream.consume  (stream="dtest247")

//$expect a.b

Fork join

0 $mock:: dtest.l267
   dtest.l270 (stream="x"="x")

send::  msg dtest.l267 

expect::  (payload is 245)

Before and after

send::  msg snakk.text  (url ="/diesel/rest/dieseltest/resour"...)

expect::  (payload is "before-r1-read-after")

send::  msg snakk.text  (url ="/diesel/rest/dieseltest/resour"...)

expect::  (payload is "before-r1-update-after")

erasing payload

send:: msg  (payload=4)
send::  msg testdiesel.erasepayload 

send::  msg ctx.set  (x)

expect::  (payload not defined)
expect::  (x not defined)

run a script api

send::  msg snakk.text  (url ="/diesel/engine/script"..., verb="POST", body ="$msg testdiesel.api.public()"..., X-Api-Key)

expect::  (payload is "yeah")

send::  msg snakk.text  (url ="/diesel/engine/script"..., verb="POST", body ="$msg testdiesel.api.private()"..., X-Api-Key)

send::  msg diesel.catch 

expect::  (payload not defined)


Was this useful?    

By: Razie | 2017-04-03 .. 2024-07-06 | Tags: story , dsl , engine , sanity


Viewed 928 times ( | History | Print ) this page.

You need to log in to post a comment!

© Copyright DieselApps, 2012-2024, all rights reserved.