I'm running cover from Devel::Cover on a module and getting 50% of branch coverage in lines that use the conditional ternary operator i.e.
return @rgb ? map { hex $_ } @rgb : undef;
Is this OK? Do I have to change the code to use if/else blocks in order to gain the 100% of coverage?
I'm new to Devel::Cover so any insight that you could provide about this, will be really helpful.
Thanks
You are not getting coverage for the false branch of the ternary, because your tests do not cover a case where
@rgbis empty. In that case, themapwill never be called, but it will returnundef(or()like @ikegami suggested).The ternary is the same as this:
So there is a branch there that has not been covered by the test.
You have several options:
@rgbhas no elements# uncoverable branch falsecomment as described in https://metacpan.org/pod/Devel::Cover#UNCOVERABLE-CRITERIAwrite a test case where it expects
@rgbnot to have elements