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

[PATCH] Make UNIVERSAL::VERSION return $VERSION #11522

Closed
p5pRT opened this issue Jul 25, 2011 · 24 comments
Closed

[PATCH] Make UNIVERSAL::VERSION return $VERSION #11522

p5pRT opened this issue Jul 25, 2011 · 24 comments
Labels

Comments

@p5pRT
Copy link

p5pRT commented Jul 25, 2011

Migrated from rt.perl.org#95544 (status was 'resolved')

Searchable as RT95544$

@p5pRT
Copy link
Author

p5pRT commented Jul 25, 2011

From @cpansprout

See the discussion starting at http​://www.nntp.perl.org/group/perl.perl5.porters/2011/06/msg173710.html

With this patch​:
$ ./miniperl -le ' $VERSION = "3alpha"; print "main"->VERSION'
3alpha
$ ./miniperl -le ' $VERSION = "3alpha"; print "main"->VERSION(4)'
Invalid version format (non-numeric data) at -e line 1.


Flags​:
  category=core
  severity=low


Site configuration information for perl 5.15.0​:

Configured by sprout at Thu Jun 16 05​:42​:17 PDT 2011.

Summary of my perl5 (revision 5 version 15 subversion 0) configuration​:
Snapshot of​: 00b4043
Platform​:
  osname=darwin, osvers=10.5.0, archname=darwin-thread-multi-2level
  uname='darwin pint.local 10.5.0 darwin kernel version 10.5.0​: fri nov 5 23​:20​:39 pdt 2010; root​:xnu-1504.9.17~1release_i386 i386 '
  config_args='-de -Dusedevel -Duseithreads'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=define, usemultiplicity=define
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=undef, use64bitall=undef, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
Compiler​:
  cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include',
  optimize='-O3',
  cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.2.1 (Apple Inc. build 5664)', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
Linker and Libraries​:
  ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /usr/lib
  libs=-ldbm -ldl -lm -lutil -lc
  perllibs=-ldl -lm -lutil -lc
  libc=/usr/lib/libc.dylib, so=dylib, useshrplib=false, libperl=libperl.a
  gnulibc_version=''
Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -fstack-protector'

Locally applied patches​:


@​INC for perl 5.15.0​:
  /usr/local/lib/perl5/site_perl/5.15.0/darwin-thread-multi-2level
  /usr/local/lib/perl5/site_perl/5.15.0
  /usr/local/lib/perl5/5.15.0/darwin-thread-multi-2level
  /usr/local/lib/perl5/5.15.0
  /usr/local/lib/perl5/site_perl
  .


Environment for perl 5.15.0​:
  DYLD_LIBRARY_PATH (unset)
  HOME=/Users/sprout
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/bin​:/bin​:/usr/sbin​:/sbin​:/usr/local/bin​:/usr/X11/bin​:/usr/local/bin
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jul 25, 2011

From @cpansprout

Inline Patch
diff --git a/universal.c b/universal.c
index 3295fc5..1caab9d 100644
--- a/universal.c
+++ b/universal.c
@@ -327,21 +327,20 @@ XS(XS_UNIVERSAL_VERSION)
     gvp = pkg ? (GV**)hv_fetchs(pkg, "VERSION", FALSE) : NULL;
 
     if (gvp && isGV(gv = *gvp) && (sv = GvSV(gv)) && SvOK(sv)) {
-        SV * const nsv = sv_newmortal();
-        sv_setsv(nsv, sv);
-        sv = nsv;
-	if ( !sv_derived_from(sv, "version"))
-	    upg_version(sv, FALSE);
+        ST(0) = sv_newmortal();
+        sv_setsv(ST(0), sv);
         undef = NULL;
     }
     else {
-        sv = &PL_sv_undef;
+        sv = ST(0) = &PL_sv_undef;
         undef = "(undef)";
     }
 
     if (items > 1) {
 	SV *req = ST(1);
 
+	if ( !sv_derived_from(sv, "version"))
+	    upg_version(sv, FALSE);
 	if (undef) {
 	    if (pkg) {
 		const char * const name = HvNAME_get(pkg);
@@ -376,12 +375,6 @@ XS(XS_UNIVERSAL_VERSION)
 
     }
 
-    if ( SvOK(sv) && sv_derived_from(sv, "version") ) {
-	ST(0) = sv_2mortal(vstringify(sv));
-    } else {
-	ST(0) = sv;
-    }
-
     XSRETURN(1);
 }
 

@p5pRT
Copy link
Author

p5pRT commented Jul 26, 2011

From @JohnPeacock

On 07/24/2011 07​:55 PM, Father Chrysostomos (via RT) wrote​:

See the discussion starting at http​://www.nntp.perl.org/group/perl.perl5.porters/2011/06/msg173710.html

With this patch​:
$ ./miniperl -le ' $VERSION = "3alpha"; print "main"->VERSION'
3alpha
$ ./miniperl -le ' $VERSION = "3alpha"; print "main"->VERSION(4)'
Invalid version format (non-numeric data) at -e line 1.

Close, but if you run lib/version.t, you will see that you are throwing
errors for the case where a module file does not declare $VERSION at all.

...
not ok 1029 - Replacement handles modules without package or VERSION

# Failed test 'Replacement handles modules without package or VERSION'
# at lib/version.t line 440.
# 'Modification of a read-only value attempted at
(eval 635) line 1, <DATA> line 72.
# BEGIN failed--compilation aborted at (eval 635) line 1, <DATA> line 72.
# '
# doesn't match '(?^​:defines neither package nor VERSION)'
...

The attached replacement patch fixes that (just need to delay upgrading sv).

I'm including this change in the next version.pm on CPAN (hopefully
sometime today).

John

@p5pRT
Copy link
Author

p5pRT commented Jul 26, 2011

From @JohnPeacock

VERSION2.diff
diff --git a/universal.c b/universal.c
index 3295fc5..896b3db 100644
--- a/universal.c
+++ b/universal.c
@@ -327,15 +327,12 @@ XS(XS_UNIVERSAL_VERSION)
     gvp = pkg ? (GV**)hv_fetchs(pkg, "VERSION", FALSE) : NULL;
 
     if (gvp && isGV(gv = *gvp) && (sv = GvSV(gv)) && SvOK(sv)) {
-        SV * const nsv = sv_newmortal();
-        sv_setsv(nsv, sv);
-        sv = nsv;
-	if ( !sv_derived_from(sv, "version"))
-	    upg_version(sv, FALSE);
+        ST(0) = sv_newmortal();
+        sv_setsv(ST(0), sv);
         undef = NULL;
     }
     else {
-        sv = &PL_sv_undef;
+        sv = ST(0) = &PL_sv_undef;
         undef = "(undef)";
     }
 
@@ -355,6 +352,9 @@ XS(XS_UNIVERSAL_VERSION)
 	     }
 	}
 
+	if ( !sv_derived_from(sv, "version"))
+	    upg_version(sv, FALSE);
+
 	if ( !sv_derived_from(req, "version")) {
 	    /* req may very well be R/O, so create a new object */
 	    req = sv_2mortal( new_version(req) );
@@ -376,12 +376,6 @@ XS(XS_UNIVERSAL_VERSION)
 
     }
 
-    if ( SvOK(sv) && sv_derived_from(sv, "version") ) {
-	ST(0) = sv_2mortal(vstringify(sv));
-    } else {
-	ST(0) = sv;
-    }
-
     XSRETURN(1);
 }
 

@p5pRT
Copy link
Author

p5pRT commented Jul 26, 2011

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From @JohnPeacock

On 07/26/2011 11​:25 AM, John Peacock wrote​:

The attached replacement patch fixes that (just need to delay
upgrading sv).

I'm including this change in the next version.pm on CPAN (hopefully
sometime today).

And attached is an even better patch that includes the test I added to
the CPAN release...

John

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From @JohnPeacock

VERSION2.diff
diff --git a/lib/version.t b/lib/version.t
index bee9078..ac6a5dd 100644
--- a/lib/version.t
+++ b/lib/version.t
@@ -474,6 +474,20 @@ SKIP: {
 	    'Replacement handles modules without VERSION'); 
 	unlink $filename;
     }
+SKIP:    { # https://rt.perl.org/rt3/Ticket/Display.html?id=95544
+	skip "version require'd instead of use'd, cannot test UNIVERSAL::VERSION", 2
+	    unless defined $qv_declare;
+	my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1);
+	(my $package = basename($filename)) =~ s/\.pm$//;
+	print $fh "package $package;\n\$VERSION = '3alpha';\n1;\n";
+	close $fh;
+	eval "use lib '.'; use $package;";
+	unlike ($@, qr/Invalid version format (non-numeric data)/,
+	    'Do not warn about bad $VERSION unless asked');
+	eval "use lib '.'; use $package; warn $package->VERSION";
+	ok ($warning =~ /3alpha/, 'Even a bad $VERSION is returned:
+	    '.$warning);
+    }
 
 SKIP: 	{
 	skip 'Cannot test bare v-strings with Perl < 5.6.0', 4
@@ -624,7 +638,6 @@ SKIP: {
 	my $warning;
 	local $SIG{__WARN__} = sub { $warning = $_[0] };
 
-$DB::single = 1;
 	my $v = eval { $CLASS->$method('1,7') };
 #	is( $@, "", 'Directly test comma as decimal compliance');
 
diff --git a/universal.c b/universal.c
index 3295fc5..896b3db 100644
--- a/universal.c
+++ b/universal.c
@@ -327,15 +327,12 @@ XS(XS_UNIVERSAL_VERSION)
     gvp = pkg ? (GV**)hv_fetchs(pkg, "VERSION", FALSE) : NULL;
 
     if (gvp && isGV(gv = *gvp) && (sv = GvSV(gv)) && SvOK(sv)) {
-        SV * const nsv = sv_newmortal();
-        sv_setsv(nsv, sv);
-        sv = nsv;
-	if ( !sv_derived_from(sv, "version"))
-	    upg_version(sv, FALSE);
+        ST(0) = sv_newmortal();
+        sv_setsv(ST(0), sv);
         undef = NULL;
     }
     else {
-        sv = &PL_sv_undef;
+        sv = ST(0) = &PL_sv_undef;
         undef = "(undef)";
     }
 
@@ -355,6 +352,9 @@ XS(XS_UNIVERSAL_VERSION)
 	     }
 	}
 
+	if ( !sv_derived_from(sv, "version"))
+	    upg_version(sv, FALSE);
+
 	if ( !sv_derived_from(req, "version")) {
 	    /* req may very well be R/O, so create a new object */
 	    req = sv_2mortal( new_version(req) );
@@ -376,12 +376,6 @@ XS(XS_UNIVERSAL_VERSION)
 
     }
 
-    if ( SvOK(sv) && sv_derived_from(sv, "version") ) {
-	ST(0) = sv_2mortal(vstringify(sv));
-    } else {
-	ST(0) = sv;
-    }
-
     XSRETURN(1);
 }
 

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From @cpansprout

On Tue Jul 26 11​:25​:57 2011, john.peacock@​havurah-software.org wrote​:

On 07/24/2011 07​:55 PM, Father Chrysostomos (via RT) wrote​:

See the discussion starting at
http​://www.nntp.perl.org/group/perl.perl5.porters/2011/06/msg173710.html

With this patch​:
$ ./miniperl -le ' $VERSION = "3alpha"; print "main"->VERSION'
3alpha
$ ./miniperl -le ' $VERSION = "3alpha"; print "main"->VERSION(4)'
Invalid version format (non-numeric data) at -e line 1.

Close, but if you run lib/version.t, you will see that you are
throwing
errors for the case where a module file does not declare $VERSION at
all.

...
not ok 1029 - Replacement handles modules without package or VERSION

# Failed test 'Replacement handles modules without package or
VERSION'
# at lib/version.t line 440.
# 'Modification of a read-only value attempted at
(eval 635) line 1, <DATA> line 72.
# BEGIN failed--compilation aborted at (eval 635) line 1, <DATA> line
72.
# '
# doesn't match '(?^​:defines neither package nor VERSION)'
...

The attached replacement patch fixes that (just need to delay
upgrading sv).

I'm including this change in the next version.pm on CPAN (hopefully
sometime today).

I forgot to mention that the patch was intended mainly for discussion. I
hadn’t fully tested it yet (obviously).

Thank you for finding the bug. Before you make the release (I hope I’m
not too late!), there is another bug, involving this piece of code​:

  Perl_croak(aTHX_
  "%s defines neither package nor VERSION--version check failed",
  SvPVx_nolen_const(ST(0)) );

We can’t get rid of the scalar it’s using. Attached is a better patch.

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From @cpansprout

Inline Patch
diff --git a/universal.c b/universal.c
index 3295fc5..c891b54 100644
--- a/universal.c
+++ b/universal.c
@@ -311,6 +311,7 @@ XS(XS_UNIVERSAL_VERSION)
     GV **gvp;
     GV *gv;
     SV *sv;
+    SV *ret;
     const char *undef;
     PERL_UNUSED_ARG(cv);
 
@@ -327,15 +328,12 @@ XS(XS_UNIVERSAL_VERSION)
     gvp = pkg ? (GV**)hv_fetchs(pkg, "VERSION", FALSE) : NULL;
 
     if (gvp && isGV(gv = *gvp) && (sv = GvSV(gv)) && SvOK(sv)) {
-        SV * const nsv = sv_newmortal();
-        sv_setsv(nsv, sv);
-        sv = nsv;
-	if ( !sv_derived_from(sv, "version"))
-	    upg_version(sv, FALSE);
+        ret = sv_newmortal();
+        sv_setsv(ret, sv);
         undef = NULL;
     }
     else {
-        sv = &PL_sv_undef;
+        sv = ret = &PL_sv_undef;
         undef = "(undef)";
     }
 
@@ -355,6 +353,9 @@ XS(XS_UNIVERSAL_VERSION)
 	     }
 	}
 
+	if ( !sv_derived_from(sv, "version"))
+	    upg_version(sv, FALSE);
+
 	if ( !sv_derived_from(req, "version")) {
 	    /* req may very well be R/O, so create a new object */
 	    req = sv_2mortal( new_version(req) );
@@ -376,11 +377,7 @@ XS(XS_UNIVERSAL_VERSION)
 
     }
 
-    if ( SvOK(sv) && sv_derived_from(sv, "version") ) {
-	ST(0) = sv_2mortal(vstringify(sv));
-    } else {
-	ST(0) = sv;
-    }
+    ST(0) = ret;
 
     XSRETURN(1);
 }

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From [Unknown Contact. See original ticket]

On Tue Jul 26 11​:25​:57 2011, john.peacock@​havurah-software.org wrote​:

On 07/24/2011 07​:55 PM, Father Chrysostomos (via RT) wrote​:

See the discussion starting at
http​://www.nntp.perl.org/group/perl.perl5.porters/2011/06/msg173710.html

With this patch​:
$ ./miniperl -le ' $VERSION = "3alpha"; print "main"->VERSION'
3alpha
$ ./miniperl -le ' $VERSION = "3alpha"; print "main"->VERSION(4)'
Invalid version format (non-numeric data) at -e line 1.

Close, but if you run lib/version.t, you will see that you are
throwing
errors for the case where a module file does not declare $VERSION at
all.

...
not ok 1029 - Replacement handles modules without package or VERSION

# Failed test 'Replacement handles modules without package or
VERSION'
# at lib/version.t line 440.
# 'Modification of a read-only value attempted at
(eval 635) line 1, <DATA> line 72.
# BEGIN failed--compilation aborted at (eval 635) line 1, <DATA> line
72.
# '
# doesn't match '(?^​:defines neither package nor VERSION)'
...

The attached replacement patch fixes that (just need to delay
upgrading sv).

I'm including this change in the next version.pm on CPAN (hopefully
sometime today).

I forgot to mention that the patch was intended mainly for discussion. I
hadn’t fully tested it yet (obviously).

Thank you for finding the bug. Before you make the release (I hope I’m
not too late!), there is another bug, involving this piece of code​:

  Perl_croak(aTHX_
  "%s defines neither package nor VERSION--version check failed",
  SvPVx_nolen_const(ST(0)) );

We can’t get rid of the scalar it’s using. Attached is a better patch.

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From @cpansprout

On Tue Jul 26 18​:38​:03 2011, john.peacock@​havurah-software.org wrote​:

On 07/26/2011 11​:25 AM, John Peacock wrote​:

The attached replacement patch fixes that (just need to delay
upgrading sv).

I'm including this change in the next version.pm on CPAN (hopefully
sometime today).

And attached is an even better patch that includes the test I added to
the CPAN release...

Argh!! I was too late, wasn’t I? (See my previous message.)

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From [Unknown Contact. See original ticket]

On Tue Jul 26 18​:38​:03 2011, john.peacock@​havurah-software.org wrote​:

On 07/26/2011 11​:25 AM, John Peacock wrote​:

The attached replacement patch fixes that (just need to delay
upgrading sv).

I'm including this change in the next version.pm on CPAN (hopefully
sometime today).

And attached is an even better patch that includes the test I added to
the CPAN release...

Argh!! I was too late, wasn’t I? (See my previous message.)

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From @cpansprout

On Tue Jul 26 18​:38​:03 2011, john.peacock@​havurah-software.org wrote​:

On 07/26/2011 11​:25 AM, John Peacock wrote​:

The attached replacement patch fixes that (just need to delay
upgrading sv).

I'm including this change in the next version.pm on CPAN (hopefully
sometime today).

And attached is an even better patch that includes the test I added to
the CPAN release...

John

+SKIP​: { # https://rt-archive.perl.org/perl5/Ticket/Display.html?id=95544
+ skip "version require'd instead of use'd, cannot test
UNIVERSAL​::VERSION", 2
+ unless defined $qv_declare;
+ my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK
=> 1);
+ (my $package = basename($filename)) =~ s/\.pm$//;
+ print $fh "package $package;\n\$VERSION = '3alpha';\n1;\n";
+ close $fh;
+ eval "use lib '.'; use $package;";
+ unlike ($@​, qr/Invalid version format (non-numeric data)/,
+ 'Do not warn about bad $VERSION unless asked');

Don’t you mean \( and \) in that regexp?

Shouldn’t it actually be is($@​, ''), so that a changing error message
won’t sabotage the test?

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From [Unknown Contact. See original ticket]

On Tue Jul 26 18​:38​:03 2011, john.peacock@​havurah-software.org wrote​:

On 07/26/2011 11​:25 AM, John Peacock wrote​:

The attached replacement patch fixes that (just need to delay
upgrading sv).

I'm including this change in the next version.pm on CPAN (hopefully
sometime today).

And attached is an even better patch that includes the test I added to
the CPAN release...

John

+SKIP​: { # https://rt-archive.perl.org/perl5/Ticket/Display.html?id=95544
+ skip "version require'd instead of use'd, cannot test
UNIVERSAL​::VERSION", 2
+ unless defined $qv_declare;
+ my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK
=> 1);
+ (my $package = basename($filename)) =~ s/\.pm$//;
+ print $fh "package $package;\n\$VERSION = '3alpha';\n1;\n";
+ close $fh;
+ eval "use lib '.'; use $package;";
+ unlike ($@​, qr/Invalid version format (non-numeric data)/,
+ 'Do not warn about bad $VERSION unless asked');

Don’t you mean \( and \) in that regexp?

Shouldn’t it actually be is($@​, ''), so that a changing error message
won’t sabotage the test?

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From @JohnPeacock

On 07/26/2011 08​:27 PM, Father Chrysostomos via RT wrote​:

I forgot to mention that the patch was intended mainly for discussion. I
hadn’t fully tested it yet (obviously).

Thank you for finding the bug. Before you make the release (I hope I’m
not too late!), there is another bug, involving this piece of code​:

    Perl\_croak\(aTHX\_
             "%s defines neither package nor VERSION\-\-version check failed"\,
             SvPVx\_nolen\_const\(ST\(0\)\) \);

We can’t get rid of the scalar it’s using. Attached is a better patch.
I don't understand what scalar you are talking about here.

John

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From @JohnPeacock

On 07/26/2011 08​:34 PM, Father Chrysostomos via RT wrote​:

+ (my $package = basename($filename)) =~ s/\.pm$//;

+ print $fh "package $package;\n\$VERSION = '3alpha';\n1;\n";
+ close $fh;
+ eval "use lib '.'; use $package;";
+ unlike ($@​, qr/Invalid version format (non-numeric data)/,
+ 'Do not warn about bad $VERSION unless asked');
Don’t you mean \( and \) in that regexp?

Yes, actually I do. I'll make that change to the version.pm repo, but I
don't think it rises to the level of requiring a new release. Perhaps
if I understood the other bug you cited, then combined they would mean
I'd need 0.93...

Shouldn’t it actually be is($@​, ''), so that a changing error message
won’t sabotage the test?

No, I want to be sure that I match the exact error message that is
emitted, since there are multiple codepaths each with different errors.
If that error message gets changed, the test will fail (since it is now
a regression). Someone else could be relying on the error message too...

John

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From @cpansprout

On Wed Jul 27 07​:05​:48 2011, john.peacock@​havurah-software.org wrote​:

On 07/26/2011 08​:27 PM, Father Chrysostomos via RT wrote​:

I forgot to mention that the patch was intended mainly for discussion. I
hadn’t fully tested it yet (obviously).

Thank you for finding the bug. Before you make the release (I hope I’m
not too late!), there is another bug, involving this piece of code​:

    Perl\_croak\(aTHX\_
             "%s defines neither package nor VERSION\-\-version check failed"\,
             SvPVx\_nolen\_const\(ST\(0\)\) \);

We can’t get rid of the scalar it’s using. Attached is a better patch.
I don't understand what scalar you are talking about here.

ST(0), which contains the package name.

We can’t write to ST(0) until after that block, which is why my updated
patch creates a new C variable, named ret.

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From [Unknown Contact. See original ticket]

On Wed Jul 27 07​:05​:48 2011, john.peacock@​havurah-software.org wrote​:

On 07/26/2011 08​:27 PM, Father Chrysostomos via RT wrote​:

I forgot to mention that the patch was intended mainly for discussion. I
hadn’t fully tested it yet (obviously).

Thank you for finding the bug. Before you make the release (I hope I’m
not too late!), there is another bug, involving this piece of code​:

    Perl\_croak\(aTHX\_
             "%s defines neither package nor VERSION\-\-version check failed"\,
             SvPVx\_nolen\_const\(ST\(0\)\) \);

We can’t get rid of the scalar it’s using. Attached is a better patch.
I don't understand what scalar you are talking about here.

ST(0), which contains the package name.

We can’t write to ST(0) until after that block, which is why my updated
patch creates a new C variable, named ret.

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From @JohnPeacock

On 07/27/2011 08​:30 AM, Father Chrysostomos via RT wrote​:

ST(0), which contains the package name.
We can’t write to ST(0) until after that block, which is why my updated
patch creates a new C variable, named ret.
Yeah, I figured that after I had some breakfast. I'll release another
iteration to version.pm to CPAN this afternoon...

John

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From @JohnPeacock

On 07/26/2011 08​:34 PM, Father Chrysostomos via RT wrote​:

Don’t you mean \( and \) in that regexp?
Shouldn’t it actually be is($@​, ''), so that a changing error message
won’t sabotage the test?
Attached is a replacement for the tests I proposed earlier; I escaped
the parens and included both a positive and negative test for that
exception string. I've just released version.pm 0.93 with your changes
to UNIVERSAL​::VERSION as well as my augmented tests.

John

@p5pRT
Copy link
Author

p5pRT commented Jul 27, 2011

From @JohnPeacock

VERSION3.diff
diff --git a/lib/version.t b/lib/version.t
index bee9078..dd47e87 100644
--- a/lib/version.t
+++ b/lib/version.t
@@ -474,6 +474,22 @@ SKIP: {
 	    'Replacement handles modules without VERSION'); 
 	unlink $filename;
     }
+SKIP:    { # https://rt.perl.org/rt3/Ticket/Display.html?id=95544
+	skip "version require'd instead of use'd, cannot test UNIVERSAL::VERSION", 2
+	    unless defined $qv_declare;
+	my ($fh, $filename) = tempfile('tXXXXXXX', SUFFIX => '.pm', UNLINK => 1);
+	(my $package = basename($filename)) =~ s/\.pm$//;
+	print $fh "package $package;\n\$VERSION = '3alpha';\n1;\n";
+	close $fh;
+	eval "use lib '.'; use $package; die $package->VERSION";
+	ok ($@ =~ /3alpha/, 'Even a bad $VERSION is returned');
+	eval "use lib '.'; use $package;";
+	unlike ($@, qr/Invalid version format \(non-numeric data\)/,
+	    'Do not warn about bad $VERSION unless asked');
+	eval "use lib '.'; use $package 1;";
+	like ($@, qr/Invalid version format \(non-numeric data\)/,
+	    'Warn about bad $VERSION when asked');
+    }
 
 SKIP: 	{
 	skip 'Cannot test bare v-strings with Perl < 5.6.0', 4
@@ -624,7 +640,6 @@ SKIP: {
 	my $warning;
 	local $SIG{__WARN__} = sub { $warning = $_[0] };
 
-$DB::single = 1;
 	my $v = eval { $CLASS->$method('1,7') };
 #	is( $@, "", 'Directly test comma as decimal compliance');
 

@p5pRT
Copy link
Author

p5pRT commented Jul 28, 2011

From @cpansprout

On Wed Jul 27 13​:01​:24 2011, john.peacock@​havurah-software.org wrote​:

On 07/26/2011 08​:34 PM, Father Chrysostomos via RT wrote​:

Don’t you mean \( and \) in that regexp?
Shouldn’t it actually be is($@​, ''), so that a changing error message
won’t sabotage the test?
Attached is a replacement for the tests I proposed earlier; I escaped
the parens and included both a positive and negative test for that
exception string. I've just released version.pm 0.93 with your changes
to UNIVERSAL​::VERSION as well as my augmented tests.

Thank you. I’ve just applied my patch as 9bf41c1 and yours as a0e8d7b.

@p5pRT
Copy link
Author

p5pRT commented Jul 28, 2011

From [Unknown Contact. See original ticket]

On Wed Jul 27 13​:01​:24 2011, john.peacock@​havurah-software.org wrote​:

On 07/26/2011 08​:34 PM, Father Chrysostomos via RT wrote​:

Don’t you mean \( and \) in that regexp?
Shouldn’t it actually be is($@​, ''), so that a changing error message
won’t sabotage the test?
Attached is a replacement for the tests I proposed earlier; I escaped
the parens and included both a positive and negative test for that
exception string. I've just released version.pm 0.93 with your changes
to UNIVERSAL​::VERSION as well as my augmented tests.

Thank you. I’ve just applied my patch as 9bf41c1 and yours as a0e8d7b.

@p5pRT
Copy link
Author

p5pRT commented Jul 28, 2011

@cpansprout - Status changed from 'open' to 'resolved'

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

No branches or pull requests

1 participant