develooper Front page | perl.perl5.porters | Postings from August 2016

[perl #129048] lib/perlbug.t: avoid spurious failure when testinglong PATH line

Thread Next
From:
James E Keenan
Date:
August 22, 2016 13:29
Subject:
[perl #129048] lib/perlbug.t: avoid spurious failure when testinglong PATH line
Message ID:
rt-4.0.24-5083-1471872539-1080.129048-75-0@perl.org
# New Ticket Created by  James E Keenan 
# Please include the string:  [perl #129048]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=129048 >


Please see perl5-porters discussion beginning here:

http://www.nntp.perl.org/group/perl.perl5.porters/2016/08/msg239185.html

lib/perlbug.t holds tests which sanity-check the operation of the 'perlbug' utility by creating bug reports without actually sending them.  Earlier this year we added tests (c04bead) provided by Niko Tyni with respect to this rationale:

#####
Mail transport agents limit the length of message lines at SMTP time. One observed limit is 1000 characters per line. ... [perlbug] needs to limit the length of its lines manually to make sure bug reports get delivered.
#####

Whether this objective is met is tested by this code:

#####
my $B = 'B'x9;
...
my $maxlen1 = 0; # body
my $maxlen2 = 0; # attachment
for (split(/\n/, $contents)) {
        my $len = length;
        $maxlen1 = $len if $len > $maxlen1 and !/$B/;
        $maxlen2 = $len if $len > $maxlen2 and  /$B/;
}
ok($maxlen1 < 1000, "[perl #128020] long body lines are wrapped: maxlen $maxlen1");
ok($maxlen2 > 1000, "long attachment lines are not wrapped: maxlen $maxlen2");
#####

In this case, $B is used simply to generate dummy copy for an attachment.  So, in the first of the two unit tests shown, we're testing to make sure that no bug report line other than in an attachment exceeds 1000 characters.

There is however, one line in a perlbug report which can quite plausibly exceed 1000 *unbroken* characters:  the line dumping the PATH environmental variable.  No (unescaped) wordspaces are permitted in a PATH, so the line does not wrap.  A PATH line greater than 1000 characters in length can occur in at least two plausible circumstances:  (1) For business reasons, the user has many directories in her path; or (2) The PATH (a) is shorter than 1000 characters; (b) terminates with ':$PATH'; and (c) is incremented in a particular shell -- a shell in which 'lib/perlbug.t' is subsequently run -- by use of commands like 'source ~/.bashrc' which the user is invoking to modify a .*rc or .profile file.

This can cause the kind of entirely spurious test failure reported in the p5p thread cited above:

#####
ok 20 - attachment included in fake bug report
not ok 21 - [perl \#128020] long body lines are wrapped: maxlen 1133
ok 22 - long attachment lines are not wrapped: maxlen 1200
# Failed test 21 - [perl \#128020] long body lines are wrapped: maxlen 
1133 at ../lib/perlbug.t line 154
Failed 1/22 subtests
#####

The patch attached excludes the 'PATH' line from test #21 in lib/perlbug.t and thereby reduces the possibility of spurious failures.  Here is how I tested this in a fresh shell.

#####
[perl] 13 $ echo -n $PATH | wc -m
432
[perl] 14 $ source ~/.bashrc
[perl] 15 $ source ~/.bashrc
[perl] 16 $ source ~/.bashrc
[perl] 17 $ echo -n $PATH | wc -m
1128
# configure and build perl in branch to which patch has been applied

$ cd t;./perl harness -v ../lib/perlbug.t; cd -

ok 1 - config information dumped with -d
[snip]
ok 20 - attachment included in fake bug report
ok 21 - [perl \#128020] long body lines are wrapped: maxlen 899
ok 22 - long attachment lines are not wrapped: maxlen 1200
ok
All tests successful.
Files=1, Tests=22,  1 wallclock secs ( 0.01 usr  0.00 sys +  0.58 cusr  0.03 csys =  0.62 CPU)
Result: PASS
#####

Please review.

Thank you very much.
-- 
James E Keenan (jkeenan@cpan.org)
Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About