[PROPOSED PATCH MANIFEST lib/Net/Netrc.t] Add Tests for Net::Netrc
[not yet sent to p5p; comments welcome] Is this valuable for anyone? I could probably turn something like this into an article for perl.com or the Perl Journal or even use.perl, if anyone could sweet-talk an editor or thinks gonzo testing ought to be promoted. Schwern thinks it's clever, so it can't be all bad. -- c --- ~MANIFEST Sun Oct 21 14:36:07 2001 +++ MANIFESTSun Oct 21 14:36:23 2001 @@ -1087,6 +1087,7 @@ lib/Net/netent.pm By-name interface to Perl's builtin getnet* lib/Net/netent.t See if Net::netent works lib/Net/Netrc.pm libnet +lib/Net/Netrc.tSee if Net::Netrc works lib/Net/NNTP.pmlibnet lib/Net/Ping.pmHello, anybody home? lib/Net/POP3.pmlibnet --- /dev/null Thu Aug 30 03:54:37 2001 +++ lib/Net/Netrc.t Sun Oct 21 14:35:50 2001 @@ -0,0 +1,130 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +use strict; +use Cwd; +use Test::More tests => 19; + +# for testing _readrc +$ENV{HOME} = Cwd::cwd(); + +local *CORE::GLOBAL::getpwuid = sub ($) { + ((undef) x 7, Cwd::cwd()); +}; + +# for testing _readrc +my @stat; +local *CORE::GLOBAL::stat = sub (*) { + return @stat; +}; + +# for testing _readrc +$INC{'FileHandle.pm'} = 1; + +# now that the tricks are out of the way... +use_ok( 'Net::Netrc' ); + +SKIP: { + skip('incompatible stat() handling for OS', 4) + if ($^O =~ /os2|win32|macos|cygwin/i); + + my $warn; + local $SIG{__WARN__} = sub { + $warn = shift; + }; + + # add write access for group/other + $stat[2] = 077; + is( Net::Netrc::_readrc(), undef, + '_readrc() should not read world-writable file' ); + like( $warn, qr/^Bad permissions/, '... and should warn about it' ); + + # the owner field should still not match + $stat[2] = 0; + is( Net::Netrc::_readrc(), undef, + '_readrc() should not read file owned by someone else' ); + like( $warn, qr/^Not owner/, '... and should warn about it' ); +} + +# this field must now match, to avoid the last-tested warning +$stat[4] = $<; + +# this curious mix of spaces and quotes tests a regex at line 79 (version 2.11) +FileHandle::set_lines(split(/\n/,{login}, 'nigol', + 'lookup() should find value by host name' ); + +# on 'foo' with login 'l2', the password is 'p2' +is( Net::Netrc->lookup('foo', 'l2')->{password}, 'p2', + 'lookup() should find value by hostname and login name' ); + +# the default password is 'p3', as later declarations have priority +is( Net::Netrc->lookup()->{password}, 'p3', + 'lookup() should find default value' ); + +# lookup() ignores the login parameter when using default data +is( Net::Netrc->lookup('default', 'baz')->{password}, 'p3', + 'lookup() should ignore passed login when searching default' ); + +# lookup() goes to default data if hostname cannot be found in config data +is( Net::Netrc->lookup('abadname')->{login}, 'baz', + 'lookup() should use default for unknown machine name' ); + +# now test these accessors +my $instance = bless({}, 'Net::Netrc'); +for my $accessor (qw( login account password )) { + is( $instance->$accessor(), undef, + "$accessor() should return undef if $accessor is not set" ); + $instance->{$accessor} = $accessor; + is( $instance->$accessor(), $accessor, + "$accessor() should return value when $accessor is set" ); +} + +# and the three-for-one accessor +is( scalar( () = $instance->lpa()), 3, + 'lpa() should return login, password, account'); +is( join(' ', $instance->lpa), 'login password account', + 'lpa() should return appropriate values for l, p, and a' ); + +package FileHandle; + +sub new { + tie *FH, 'FileHandle', @_; + return \*FH; +} + +sub TIEHANDLE { + my ($class, undef, $file, $mode) = @_; + bless({ file => $file, mode => $mode }, $class); +} + +my @lines; +sub set_lines { + @lines = @_; +} + +sub READLINE { + shift @lines; +} + +sub close { 1 }
Re: Preliminary test coverage analysis
-BEGIN PGP SIGNED MESSAGE- Moin, On 21-Oct-01 Paul Johnson tried to scribble about: > I keep getting hit by things that think I am running Micros~1 stuff :-( Those worms, again. *sigh* > Looks like you have it now, but let me know if that's not the case. Since I am constantly developing, I need to run the Coverage locally. But first I need to fix the remaining failures in my working copy. Anyway, thanx for your work! I can probably give you a lot of examples where the coverage is wrong (or mileading), but will do so when I get to run it locally,so that I can make small testcases. Cheers, - -- perl -MMath::String -e 'print \ Math::String->from_number("215960156869840440586892398248"),"\n"' http://bloodgate.com/thief/ Thief - The Dark Project http://bloodgate.com/perl My current Perl projects http://freedomforlinks.de Fight for your right to link. PGP key available on http://bloodgate.com/tels.asc or via email -BEGIN PGP SIGNATURE- Version: 2.6.3i Charset: latin1 iQEVAwUBO9MQCXcLPEOTuEwVAQEj2Qf8DmW7CSfjOpP+LN/q6oB/sGbup2U1EWAM /azWF70s5i/2GQySRUc/EDa7j5vQqGxCRRtpwEiwXUjSdLSluUaBAUZMNLB8M8wF 4moftJXEAk4LHBkArCU00Ia/jNBVCXe/V6WX5iKsvAeOmiHsq6zuPrTyMCwZALYb x94MpnJkm/K/idbWCpAupmN/McmskAani2i55t5vV6nu81NT/seUvDYRZVKmy+po acJo7R1zAsuTj62qvTa/tE8oCUJbH28BunnJ7grJqpEKr7VY12H9vgmHpgIGWm3/ 2ymVplSMmu0ZX968wNQOAWW3VgXyTQp+56F1CNhl3mi2cQTApQAkWA== =6VV1 -END PGP SIGNATURE-
Re: Preliminary test coverage analysis
On Sun, Oct 21, 2001 at 07:31:20PM +0200, Tels wrote: > On 21-Oct-01 Paul Johnson tried to scribble about: > > On Thu, Oct 18, 2001 at 10:42:33PM -0400, Michael G Schwern wrote: > >> On Thu, Oct 18, 2001 at 12:07:26AM -0600, chromatic wrote: > >> > > - Of those covered, a smidge less than half have < 75% statement > >> > > coverage. - " > >> > >" " , 20% have < 50% statement coverage. > > I ran this last night, and supply the results here without comment save: > > Good work! (I see my modules ;) > > Some hints, though: > > You could leave of *.t files. The test's own coverage is not very > interesting, since most testsuites probably are supposed to not be covered > 100%. F.i. bigintpm.t runs some tests different based on your system, and I > bet others do so, too. So you can't achieve 100% anyway. Certainly there is a lot that could do with cleaning up, but I wanted to throw out the first pass so people could get a feel for it. You're right that platform specific cod is going to skew the figures somewhat. [ I liked that typo so much I decided to keep it :-) ] > Of course, somebody might be interested in why some test files have poor > coverage ;) This can be useful on occasion. > I tried to view my modules, but your server is currently melting and can't > deliver the HUGE html documents :/ I keep getting hit by things that think I am running Micros~1 stuff :-( Looks like you have it now, but let me know if that's not the case. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net
Re: Preliminary test coverage analysis
-BEGIN PGP SIGNED MESSAGE- Moin, On 21-Oct-01 Paul Johnson tried to scribble about: > On Sun, Oct 21, 2001 at 07:40:11PM +0200, Tels wrote: > >> Thank you for your work! I looked at BigFloat.pm, noticed a untested >> line >> in facmp(), added tests and lo and behold, there was a bug! >> (bacmp(5,+inf) >> returned 1 but should return -1 ;) > > Hah! It was all worth it :-) Good news: Unearthed a few more bugs (and buglets) by looking for untested things. Very few remain, but every bug extracted is worth it ;) Cheers, - -- perl -MMath::String -e 'print \ Math::String->from_number("215960156869840440586892398248"),"\n"' http://bloodgate.com/thief/ Thief - The Dark Project http://bloodgate.com/perl My current Perl projects http://freedomforlinks.de Fight for your right to link. PGP key available on http://bloodgate.com/tels.asc or via email -BEGIN PGP SIGNATURE- Version: 2.6.3i Charset: latin1 iQEVAwUBO9MNKHcLPEOTuEwVAQFBUgf+MpO2klG4rsWclIWWuA+sGRDoFAvjfFR3 0Hq0GsueqXFDe9imW6kQKm3YZP2Ymq/fQIWMp6RA7RGGfeWuWPrz2n8o9shz94Ay lP+hBeZmymeAhDG9MT0H2cxtfXUx11t3L7ePv4BB7b1KMcU2q3mklJivFy4bQ3A3 eaU1REzME+tmpdbLrdP/XM4SWS1B70kYgonY+ULVdk5uuHr4J0+V2tUiPH/pmgGR mdcdlSxWqN5uT4qWCY7iQFmAH+6nt5gct6UMdjFqzkCk5OuoMKcLGQSzjKHuoJjg s9pg0een8xooicz9up4ncKQFktB9LqjrGTHgt2O+0UNr8J3x0qDYww== =mw0V -END PGP SIGNATURE-
Re: Preliminary test coverage analysis
On Sun, Oct 21, 2001 at 07:40:11PM +0200, Tels wrote: > Thank you for your work! I looked at BigFloat.pm, noticed a untested line > in facmp(), added tests and lo and behold, there was a bug! (bacmp(5,+inf) > returned 1 but should return -1 ;) Hah! It was all worth it :-) > Wow ;) Indeed. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net
Re: Preliminary test coverage analysis
-BEGIN PGP SIGNED MESSAGE- Moin, On 21-Oct-01 Paul Johnson tried to scribble about: > I ran this last night, and supply the results here without comment save: Thank you for your work! I looked at BigFloat.pm, noticed a untested line in facmp(), added tests and lo and behold, there was a bug! (bacmp(5,+inf) returned 1 but should return -1 ;) Wow ;) Cheers, - -- perl -MMath::String -e 'print \ Math::String->from_number("215960156869840440586892398248"),"\n"' http://bloodgate.com/thief/ Thief - The Dark Project http://bloodgate.com/perl My current Perl projects http://freedomforlinks.de Fight for your right to link. PGP key available on http://bloodgate.com/tels.asc or via email -BEGIN PGP SIGNATURE- Version: 2.6.3i Charset: latin1 iQEVAwUBO9MIbncLPEOTuEwVAQHJEgf8DgOMsP97bTVIrbG/8QengFNOg22nAg8+ N6u094A08fkJbsuX1ac/jAZgFnSyyKGGBSZNzO2NEQYCmMZhJUDThKAOap37O0Kn d9/VYcDaMHlVsro78Bk6B2r1zvt+DXzYZb0FDWXPHRIU2lP/EZFhnLH8uVUbtlwd W7W9jVeaqZv4RW7NtFOClTckfktU07LiQzH7gL6PIzbObq3ynl0DRRsuWinPNfc8 P0dlbun2up60vb6wRVmKA90lgr740ySPS7T8xjey0PeZOvHyLsqQkY9wesclwFis 6NmTyOtucIMsUCeMWxF8fo4xIN8Ced0Q1/JCGeGn2BhcCMdA8eg4dQ== =czTA -END PGP SIGNATURE-
Re: Preliminary test coverage analysis
-BEGIN PGP SIGNED MESSAGE- Moin, On 21-Oct-01 Paul Johnson tried to scribble about: > On Thu, Oct 18, 2001 at 10:42:33PM -0400, Michael G Schwern wrote: >> On Thu, Oct 18, 2001 at 12:07:26AM -0600, chromatic wrote: >> > > - Of those covered, a smidge less than half have < 75% statement >> > > coverage. - " >> > >" " , 20% have < 50% statement coverage. > I ran this last night, and supply the results here without comment save: Good work! (I see my modules ;) Some hints, though: You could leave of *.t files. The test's own coverage is not very interesting, since most testsuites probably are supposed to not be covered 100%. F.i. bigintpm.t runs some tests different based on your system, and I bet others do so, too. So you can't achieve 100% anyway. Of course, somebody might be interested in why some test files have poor coverage ;) I tried to view my modules, but your server is currently melting and can't deliver the HUGE html documents :/ Tels - -- perl -MMath::String -e 'print \ Math::String->from_number("215960156869840440586892398248"),"\n"' http://bloodgate.com/thief/ Thief - The Dark Project http://bloodgate.com/perl My current Perl projects http://freedomforlinks.de Fight for your right to link. PGP key available on http://bloodgate.com/tels.asc or via email -BEGIN PGP SIGNATURE- Version: 2.6.3i Charset: latin1 iQEVAwUBO9MGQncLPEOTuEwVAQFkTwf/QVXE9+YxXgItlpvZTs+vLXEG+LSqXyv8 ARLxaEJV3eiBkub2tZpWl3yfFVIpTusrdHSaPXUKi+UEbj6fl4houNWWmd2Iy796 OtIuHSZRxk5dpATZDFVoihDJQAjMOCDRoDQ7xQcH3blks3A8nIFN2djiAi+lTZFE 6BYS8yXgRMh9gry1EcLAdZ0ZIXGHgJY2EB873HEYD/hsVwpTE6EoqGFxFCXLwG0F LpJRhz9KfeuJsQedW49Fm8/zSqi8ck/GzvrXvPnTxNkAfmN3R4AzTcuQGS/WXh/b WHFzi2irLde8aC6g9T3gNBQlH1Q+dXmkFEMObFfVyR0ZNIAG8uXxag== =gJkg -END PGP SIGNATURE-
Re: Preliminary test coverage analysis
On Thu, Oct 18, 2001 at 10:42:33PM -0400, Michael G Schwern wrote: > On Thu, Oct 18, 2001 at 12:07:26AM -0600, chromatic wrote: > > > - Of those covered, a smidge less than half have < 75% statement coverage. - " > > >" " , 20% have < 50% statement coverage. > > > > Is it possible to get an update on this? Writing a new test from > > scratch is generally harder than adding to an existing test. (It's > > probably the blank page thing that plagues authors.) > > Unfortunately, no. Devel::Coverage is fundamentally broken and > Devel::Cover is gagging on the core test suite. I ran this last night, and supply the results here without comment save: - Devel::Cover is still alpha code and there are obviously bugs. - 11/316 tests failed, 2 are obviously due to bugs in Devel::Cover. - A few tests ended up in different directories and are not reported here. - The URL is to my home machine so apologies if it is down or slow. - I'll leave the data there for a while, but not for ever. - This gives me plenty to work on http://pjcj.sytes.net/cover.12493/cover_db/cover_db.html username: perl password: cover -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net