[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC] Add assert statement to make unit testing easier for Poke code
From: |
Mohammad-Reza Nabipoor |
Subject: |
Re: [RFC] Add assert statement to make unit testing easier for Poke code |
Date: |
Wed, 18 Nov 2020 22:29:35 +0330 |
Hi, Jose.
On Wed, Nov 18, 2020 at 09:37:36AM +0100, Jose E. Marchesi wrote:
>
> I think this can be achieved without having to introduce a special form
> `assert'. Something like this:
>
> fun assert (int condition, string msg,
> int line, string file) = void:
> {
> if (!condition)
> raise Exception {
> code = EC_generic,
> msg = "Assertion failed at " + itos (line) + file + (msg'length ?
> ": " + msg : ""),
> exit_status = 1
> };
> }
>
> That you invoke like:
>
> assert ("foo"[n] == 102UB, "", __LINE__, __FILE);
>
Yes. But I don't like to put those `__LINE__` and `__FILE__` variables
everywhere.
And I think adding such a small syntactic sugar to achieve conciseness
is an affordable thing to do.
BTW do you know that `assert` is a keyword of Poke? (libpoke/pkl-tab.y:315)
> We don't have an `itos' (integer to string) function in the standard
> library yet though. You may want to write it :)
>
Sure!
> > ```poke
> > type TestFn = () void;
> > type Test = struct
> > {
> > string name;
> > TestFn func; /* Currently doesn't work! error: invalid type in struct
> > field */
>
> This will be possible soon.
>
Thanks!
Regards,
Mohammad-Reza