Open xenu opened 5 years ago
That is indeed confusing. Documentation (and the error message) should be corrected.
I will explain it here, but yeah docs and such also need to be updated.
Test2 has a lot of internal state that it delays setting until the last possible moment. These are things like "Are we using IPC", "What renderer is going to be used", "Do we need Test::Builder compatibility stuff in place", etc. Test2 is not considered fully loaded until these things all happen.
When does this normally happen? It usually happens when the very first event is generated (plan, assertion, note, diag, etc). When IPC is loaded there is an INIT block that forces it after BEGIN time as well to make threading/forking easier: https://github.com/Test-More/test-more/blob/master/lib/Test2/IPC.pm#L28
It might make sense to always have this init block, I am not sure.
The above script fails with
Test2 must be fully loaded before you start a new thread! at a.pl line 7 thread 1.
. It is not clear at all what "fully loaded" does mean, and this concept doesn't seem to exist in Test2 documentation.It stops crashing when I either add
use Test2::IPC;
or callok(1)
before creating a new thread. Perhaps the error message should recommend doing that?