Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anonymous block shows first line not covered #324

Open
pryrt opened this issue May 13, 2023 · 2 comments
Open

Anonymous block shows first line not covered #324

pryrt opened this issue May 13, 2023 · 2 comments

Comments

@pryrt
Copy link

pryrt commented May 13, 2023

If I have an anonymous block (for encapsulation or other similar purposes), the first line usually shows up as uncovered, as I described here (running with Devel::Cover 1.40)

x.pl

#!perl
use 5.012; # strict, //
use warnings;

{
    my $i = 1;
    my $j = 2;
    sub get {
        $i + $j;
    }
}
get();

run:

perl -MDevel::Cover x.pl 
cover

output:

----- ------ ------ ------ ------ ------ ------ ------
File    stmt   bran   cond    sub    pod   time  total
----- ------ ------ ------ ------ ------ ------ ------
x.pl    90.9    n/a    n/a  100.0    n/a  100.0   92.8
Total   90.9    n/a    n/a  100.0    n/a  100.0   92.8
----- ------ ------ ------ ------ ------ ------ ------

The coverage report shows line 6 with two rows in the statement column, the second of which shows as uncovered.

If I change it to a do block instead, the do line shows up as uncovered, instead of the first my line.

#!perl
use 5.012; # strict, //
use warnings;

do {
    my $i = 1;
    my $j = 2;
    sub get {
        $i + $j;
    }
};
get();

and perlmonk haukex reduced it to an even simpler case { sub x {} } x(), which I have expanded slightly so you can see the line numbers for which statements show as uncovered.

{
    sub x {
        print 1;
    }
}
x();

All three of those simple scripts actually execute every statement at least once, so it really appears there's a bug in the statement coverage.

@pjcj
Copy link
Owner

pjcj commented May 22, 2023

Thanks very much for this report. It certainly does look like a bug. Could you please post the output of perl -V?

I suspect we'll need to look into what the optree looks like in these cases and perhaps craft something to recognise that and report correctly.

@pryrt
Copy link
Author

pryrt commented May 22, 2023

Summary of my perl5 (revision 5 version 32 subversion 1) configuration:

  Platform:
    osname=MSWin32
    osvers=10.0.19042.746
    archname=MSWin32-x64-multi-thread
    uname='Win32 strawberry-perl 5.32.1.1 #1 Sun Jan 24 15:00:15 2021 x64'
    config_args='undef'
    hint=recommended
    useposix=true
    d_sigaction=undef
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=undef
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='gcc'
    ccflags =' -DWIN32 -DWIN64 -D__USE_MINGW_ANSI_STDIO -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv -fno-strict-aliasing -mms-bitfields'
    optimize='-s -O2'
    cppflags='-DWIN32'
    ccversion=''
    gccversion='8.3.0'
    gccosandvers=''
    intsize=4
    longsize=4
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='long long'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='g++.exe'
    ldflags ='-s -L"C:\USR\LOCAL\APPS\STRAWBERRY\perl\lib\CORE" -L"C:\USR\LOCAL\APPS\STRAWBERRY\c\lib"'
    libpth=C:\USR\LOCAL\APPS\STRAWBERRY\c\lib C:\USR\LOCAL\APPS\STRAWBERRY\c\x86_64-w64-mingw32\lib C:\USR\LOCAL\APPS\STRAWBERRY\c\lib\gcc\x86_64-w64-mingw32\8.3.0
    libs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    perllibs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    libc=
    so=dll
    useshrplib=true
    libperl=libperl532.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs
    dlext=xs.dll
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags='-mdll -s -L"C:\USR\LOCAL\APPS\STRAWBERRY\perl\lib\CORE" -L"C:\USR\LOCAL\APPS\STRAWBERRY\c\lib"'


Characteristics of this binary (from libperl):
  Compile-time options:
    HAS_TIMES
    HAVE_INTERP_INTERN
    MULTIPLICITY
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_IMPLICIT_CONTEXT
    PERL_IMPLICIT_SYS
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    USE_64_BIT_INT
    USE_ITHREADS
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under MSWin32
  Compiled at Jan 24 2021 15:05:42
  @INC:
    C:/usr/local/apps/STRAWBERRY/perl/site/lib/MSWin32-x64-multi-thread
    C:/usr/local/apps/STRAWBERRY/perl/site/lib
    C:/usr/local/apps/STRAWBERRY/perl/vendor/lib
    C:/usr/local/apps/STRAWBERRY/perl/lib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants