You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using "binmode" with ":encoding()" if the line of code is run then this line will show up as if it was a "use" statement and once as a normal statement line in the structure file. If it is not run then it does not show up as if it was a "use" statement. It does not matter what the file handle is or the encoding type. If "encoding" is not used then this does not happen, i.e. "binmode STDOUT, ':utf8';".
The main issue is that this will cause merge conflicts if one test does not run this line of code and the second test does. Then when merging the structures do not match. This can be seen with the code below:
sub foo {
print "foo\n";
binmode STDOUT, ':encoding(UTF-8)';
}
foo();
The structure then acts as if the "binmode" line was both a "use" statement and a normal line so the statement structure is [5, 3, 3, 3, 2, 3]. If we remove the call to foo() then the "binmode" line show up as a single statement line [2, 3].
I also noticed if "binmode" with "encoding" is used twice then only the first call will show up as a "use" statement plus a normal statement line. The second will then only show up as a normal statement line. For example if the file contained:
This file would give the following structure:
{"subroutine":[[1,"BEGIN"]],"start":{"1":{"BEGIN":[{"time":null,"statement":2,"branch":null,"pod":null,"subroutine":null,"condition":null}]},"-1":{"__COVER__":[{"subroutine":1,"condition":null,"time":null,"statement":5,"branch":null,"pod":null}]}},"file":"f2.pl","statement":[1,2,1,1,1],"digest":"8374f104aa1d19561eeea886e144a687"}
The structure would also be the same if both "binmode" lines were identical:
Found a workaround for this issue. If including a use statement for "encoding()" then when "binmode" using "encoding()" is called for the first time it does not show up like a use statement:
use open ':encoding(UTF-8)';
binmode STDIN, ':encoding(utf8)';
binmode STDIN, ':encoding(utf8)';
This does not show a use statement for the first call of "binmode", statement structure [2,3,1,1,1].
I think what is happening here is when "binmode" or "open" are used with "encoding()" for the first time there is a use statement being used to include "encoding()", Devel::Cover then only sees the use statement and writes it to the structure file if the line that uses "encoding()" is called.
When using "binmode" with ":encoding()" if the line of code is run then this line will show up as if it was a "use" statement and once as a normal statement line in the structure file. If it is not run then it does not show up as if it was a "use" statement. It does not matter what the file handle is or the encoding type. If "encoding" is not used then this does not happen, i.e. "binmode STDOUT, ':utf8';".
The main issue is that this will cause merge conflicts if one test does not run this line of code and the second test does. Then when merging the structures do not match. This can be seen with the code below:
The structure then acts as if the "binmode" line was both a "use" statement and a normal line so the statement structure is [5, 3, 3, 3, 2, 3]. If we remove the call to foo() then the "binmode" line show up as a single statement line [2, 3].
I also noticed if "binmode" with "encoding" is used twice then only the first call will show up as a "use" statement plus a normal statement line. The second will then only show up as a normal statement line. For example if the file contained:
This file would give the following structure:
{"subroutine":[[1,"BEGIN"]],"start":{"1":{"BEGIN":[{"time":null,"statement":2,"branch":null,"pod":null,"subroutine":null,"condition":null}]},"-1":{"__COVER__":[{"subroutine":1,"condition":null,"time":null,"statement":5,"branch":null,"pod":null}]}},"file":"f2.pl","statement":[1,2,1,1,1],"digest":"8374f104aa1d19561eeea886e144a687"}
The structure would also be the same if both "binmode" lines were identical:
I did noticed that if running this using the perl debugger the first call to "binmode" is run four times:
The text was updated successfully, but these errors were encountered: