[Gambas-devel] Suggestion : Gambas Unit Testing
Tobias Boege
taboege at ...176...
Tue Dec 9 22:20:13 CET 2014
On Tue, 09 Dec 2014, Adrien Prokopowicz wrote:
> Le Tue, 09 Dec 2014 16:09:23 +0100, Tobias Boege <taboege at ...176...> wrote:
>
> > On Tue, 09 Dec 2014, Adrien Prokopowicz wrote:
> >> [...]
> >
> > I know some people who waited for this. Thank you!
> >
> > An extra "gbt3" would be the way I prefer, and maybe *somehow* the
> > ability
> > to specify tests in plain text, i.e. not Gambas code. But that point can
> > safely be left for the future.
> >
>
> I would still like to know precisely what you have in mind, though. :)
>
Suppose your class LagrangeInterp.class can interpolate polynomials from
given data sets using Lagrange's method. Its interface is
Public Sub _call(X As Float[], Y As Float[]) As Polynomial
I would like to be able to write into a text file, say lagrange.unit,
...
LagrangeInterp([1,2,3], [1,4,9]) = "x^2"
LagrangeInterp([], []) Error
...
and then call
$ gbt3 /path/to/my/project <lagrange.unit
to unit-test my project -- imagine that we want to do that from a cronjob,
after a new Gambas version was built.
Note that LagrangeInterp([1,2,3], [1,4,9]) and LagrangeInterp([], []) is
valid Gambas code which can be Eval()'d in a suitable environment. The first
line asserts that the Polynomial object returned from that call has a string
representation "x^2". Polynomials can safely be CStr()'d. That's what makes
it reasonable to discuss this level of comfort. The second call should raise
an error which is indicated by the "Error" keyword instead of some equality
assertion.
As I said, this is only about comfort -- comfort that can later be
implemented on top of the working unit tester and a level of comfort that is
still *feasible*. E.g. the first line would be converted by a parser into a
sequence like this:
Dim sLine As String
Dim vExpected, vResult As Variant
' Sample data
sLine = "LagrangeInterp([1,2,3], [1,4,9]) = \"x^2\""
' For equality assertions:
With Scan(sLine, "* = *")
vResult = Eval(.[0]) ' Requires that the LagrangeInterp class is loaded![*]
vExpect = Eval(.[1])
If TypeOf(vExpect) = gb.String Then ' [+]
If CStr(vResult) = vExpect Then Print "OK"
Endif
End With
[*] Maybe we can list all the used classes in the header of such a file and
load them explicitely using Class.Load()? I don't know if that would
work.
[+] I don't know off the top of my head if this If statement is necessary.
Maybe the code
If vResult = vExpect Then Print "OK"
would suffice as it may trigger an automatic conversion of vResult to
vExpect's type which is String in this example.
Just an idea.
Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the Devel
mailing list