Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2015/08/19

I Need To Write This Up To Understand It, or The Epic Battle between Wat and Derp!

I've signed up for Neil Bowers' Pull Request Challenge, as I've blogged about before.

This month, I'm working with System::Command. It's neat, a step up from system calls, and as I understand it, integral to handling Git programmically, within Git::Repository. If I wasn't elbow-deep, I might try to use it as part of my Net::Globus project.

But the challenge isn't to use a module, it's to commit changes to a project. I wrote book, and he suggested writing a test to catch a bug that shows up in Windows. There's lots of "what even?" that's been going along with this, the great majority has a lot to do with the difference between coding for your self and your lab and coding for a community. I mean, I really do not get what's going on here, and you know that old joke? "Doctor, it hurts when I do this!" "Don't do that, then!" I keep thinking "If this is breaking your code, do something else!"

But, that sort of thinking doesn't get your code merged. So, I'm proceeding, my mind becoming the ring for an epic cage match between Wat and Derp.

One of the points of Derp (thanks #win32 on irc.perl.org) is that warnings are not exceptions. Since the error as given has a distressingly consistent ability to lock up Powershell session, I hadn't thought of that. It's lead me to think about cutting back to the least amount of code you can include to get a behavior you want to test for. In this case, it isn't just giving the wrong result, it's kicking up a lot of errors. Or, rather, warnings.

# test in windows for System::Command
use strict ;
use warnings ;
use System::Command ;
# We are going to overwride the WARN and DIE signal in order to figure out
# what is going on here.
# DIE and WARN are important, they tell us what's going on, so we're going to
# keep track of them.
my @deaths ;
my @warnings ;
# $^X is "Which perl executable is this?" and this should just give us the
# version
my @perlv = ( $^X, '-v' ) ;
# it would be hoped to get this to spit out output, but I have yet
# to make it do so. Figuring out where it's broken is more important
# right now.
my $cmd = System::Command->new( @perlv, 'default' ) ;
$cmd->close ;
exit ;
# BEGIN block makes sure this runs before anything real.
BEGIN {
# I learned to do this from Gabor Szabo and Perl Mavin.
# http://perlmaven.com/how-to-capture-and-save-warnings-in-perl
$SIG{ __WARN__ } = sub {
my $message = shift ;
chomp $message ;
push @warnings, $message ;
print qq{WARN - $message \n} ;
} ;
$SIG{ __DIE__ } = sub {
my $message = shift ;
chomp $message ;
push @deaths, $message ;
print qq{DIE - $message \n} ;
} ;
}
# this ensures we see what's going on at the end, by expanding the array
# of warnings and deaths we grab
END {
if ( scalar @warnings ) {
print qq{WARNINGS\n} ;
print scalar @warnings ;
print "\n" ;
print join "\n", map { '+ ' . $_ } @warnings ;
print "\n" ;
}
if ( scalar @deaths ) {
print qq{DEATHS\n} ;
print scalar @deaths ;
print "\n" ;
print join "\n", map { '* ' . $_ } @deaths ;
print "\n" ;
}
}
__DATA__
# OUTPUT ON LINUX
$ perl ./sig_around_this_problem.pl
jacoby@oz 72°F 00:46:32 0 steps ~/Dropbox
$
# OUTPUT ON WINDOWS
PS C:\Users\jacoby\Dropbox> perl -I ..\Documents\GitHub\System-Command\lib\ .\sig_around_this_
problem.pl
WARN - Warning: unable to close filehandle GEN11 properly: Bad file descriptor at .\sig_around_this_problem.pl line 28.
WARN - Warning: unable to close filehandle GEN7 properly: Bad file descriptor at .\sig_around_this_problem.pl line 28.
WARNINGS
2
+ Warning: unable to close filehandle GEN11 properly: Bad file descriptor at .\sig_around_this_problem.pl line 28.
+ Warning: unable to close filehandle GEN7 properly: Bad file descriptor at .\sig_around_this_problem.pl line 28.
PS C:\Users\jacoby\Dropbox>
# ADDITIONAL OUTPUT WHEN RUN WITH GIT BASH
jacoby@GORT ~/Dropbox
$ Invalid argument opening STDIN as Win32 handle 380 in pumper 5296 at c:/strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
Invalid argument opening STDIN as Win32 handle 112 in pumper 9668 at c:/strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.
Invalid argument opening STDIN as Win32 handle 408 in pumper 9136 at c:/strawberry/perl/vendor/lib/IPC/Run/Win32Pump.pm line 71.
Compilation failed in require.
BEGIN failed--compilation aborted.

Among the questions on the $64,000 Pyramid are:

  • "Why does Git Bash shell show the IPC::Run::Win32Pump errors, after the next prompt shows up, while Powershell doesn't?" 
  • "Is that significant?"
  • "What, then, is killing the great Powershells of my laptop?"
  • "How do you trap that?" 
  • "Isn't that more a test issue or a program issue?"
  • "How, then, do you turn this mess into a meaningful test?"
That last one is what I'll be sleeping on tonight. On the one hand, turn this into a .t file and any warning, any at all, would be enough to trigger the test, as it's demonstrated that no errors occur in Linux. On the other, a test that says "Yeah, this kicks up errors" seems less-than-helpful, so specifying the GEN7 and GEN11 seems like the kind of thing that could break on another system.

I suppose I could write both a general and specific error.

Any comments, either supportive ("Yeah, that's exactly the kind of test you need!"), inquisitive ("Can I use BEGIN blocks in my other work?") or dismissive ("_That_ is a stupid way to test this out!") will be read and learned from. 

Meanwhile, I wrote this after my bedtime, so good night.

No comments:

Post a Comment