[Gambas-user] Merge request for gb.test

Tobias Boege taboege at gmail.com
Wed Sep 11 14:26:31 CEST 2019


On Wed, 11 Sep 2019, Christof Thalhofer wrote:
> To create a plan before testing ("1..X") – this is currently impossible
> in the way Perl does it – it would be necessary to count every
> occurrence of "Assert." in a test method.
> 

Perl doesn't (can't) do that either. It is either the programmer who
counts the assertions by hand and keeps the count updated in the test
source code [1] or they have the TAP printer count the number of
assertions as they happen, because every assertion has to call into
the TAP printer, and emits the plan line at the end, which is what
you do currently and what [2] uses. People tend to do the latter
for any number of reasons:

  - if they don't believe in keeping track of the number of tests
    manually,
  - if it's really hard to compute the number of tests because it
    depends on environment variables (subtests would alleviate this),
  - or it's simply too annoying.

Both result in perfectly valid TAP and in both cases the TAP parser
on the other end can detect a premature exit of the program: either
because not all tests in the plan line at the beginning were run,
or because the plan line at the end was not printed.

The only downside to not counting your tests manually is that you
cannot be sure that your test logic does not omit any important
tests by accident. It is a simple parity test *for your test*.
Most people seem to have at least that much confidence in their
programming thought and won't miss this :-)

Regards,
Tobi

[1] https://metacpan.org/source/MOB/Forks-Super-0.97/t/05-util.t
    using `tests => 30` parameter to the Test::More module
[2] https://metacpan.org/source/SRI/Mojolicious-8.23/t/mojo/dom.t
    using `done_testing` after the last assertion

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20190911/d94c8f63/attachment.sig>


More information about the User mailing list