qrazhan/perl5i — comment on commit 71ba4370f6a2417e87329035df9922879092417c
File: t/pick.t line 33
By schwern:

Similar issue with the diagnostics as with `pick_one`.

In addition, there's a subtle issue with writing your own test functions as wrappers around Test::More functions. Test::More reports where the test fails from by looking up the call stack a fixed number of times. It stores this in `$Test::Builder::Level`. If you wrap an extra layer of test functions around `ok` you have to increment this, but only do it in this localized context. To do this you use `local`. `local` temporarily assigns a new value to a global, and then restores the old one at the end of the block. Because of the way local works, you can't just increment. You have to `local $Test::Builder::Level = $Test::Builder::Level + 1;` before the `ok`. `pick_one` needs this treatment as well.

This allows failures to be reported at the point where `pick_one_ok` was called, and not at the `ok` inside `pick_one_ok`. This helps testers debug the failure by knowing which test failed.