Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
EnTerr
Roku Guru

doctest for BrightScript? Plus improve console

It occured to me it would be quite useful if we can write a small library that functions akin to Python's doctest. That is, one can do unit tests without even writing unit tests - it parses comments that document the behavior and checks if the shown examples work. Say we have this:

function min(x, y)
 ' returns the smaller of two arguments
 ' >>> min(7, 4)
 ' 4
 ' >>> min("99", "a")
 ' "99"
 '
 if x < y then
   return x
 else
   return y
 end if
end function

and then when somewhere in main() i call say doctest(), it would go over the source files, try the examples from the comments and complain if the results don't match. Such utility library is easy to write and even easier to use - see, we did not even realize we had written couple of unit tests for min(). Or we had documented the function by example. Plus it's a case of literate programming

There is a hindrance, however - this documentation-and-test-by-example is easy and enjoyable to do in other languages because the command line there prints the result of evaluating the line w/o explicit PRINT. For example:
enterr ~ $ python
Python 2.7.10 (default, Jul 14 2015, 19:46:27)
>>> 1+2
3
>>> ^D
enterr ~ $ irb
irb(main):001:0> 1+2
=> 3
irb(main):002:0> ^D
enterr ~ $ node
> 1+2
3
> ^D
enterr ~ $ lua
Lua 5.2.4  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> = 1+2
3
>

In BrightScript though... not so much:
Brightscript Debugger> 1+2
Syntax Error. (compile error &h02) in $LIVECOMPILE(256)

So my proposal for Roku is, can we have the console amended so that it will implicitly output the result of the last statement?
This will be everyday convenience, plus will allow to copy&paste directly this as docotest-by-example
Brightscript Debugger> min("99", "a")
"99"
0 Kudos