About Kent Cowgill
Articles filed under...
abs ab_ripper andylester arms back baggyshorts bestpractices biceps bike blog bugs bus calculator cardio catalyst cgi chart chest chinups code cpan datamodel dbi doctor documentation exercise exhaustion fitness flattire flat_tire google gps heart_rate helmet history houston html humor journal kate kenpo kenpo_x kettlebell knees lazy legs lisa lisanne maps math matthew michaelmckenna mom montreal motivation movie mysql oops orm P90X pain park patellar_tendonitis patrick perl phb photos physical_therapy plyometrics poor_gait presentation procrastination progress pullups pushups pyramid rabbits racecondition rant refactor rest ribs ride route running shoulders situps slides sore spike sql statistics syntax test testing textile timex training triceps ups versioncontrol video vim vimrc walk warren work workouts yapc yapcna2007 yoga youtube

A R C H I V E S

(2)
(7)
(15)
(16)
(25)
(3)
(4)
(2)
(4)
(11)
(1)
(1)
(3)
(2)
(2)
(10)
(5)
(2)
(3)
(4)
(9)
(21)
(3)
(3)
(1)
(6)
(4)
(1)
(4)
(3)
(2)
(1)

    Is Kent Cowgill Online?
    View Kent Cowgill's profile on LinkedIn
    Add to Technorati Favorites

    Recent Entries...

    Merry P90X-mas!

    So much to write, so little time. Having trouble remember...

    Still here, still working

    Yes, I'm still here. No, I haven't fallen off the face of...

    Catching up through week 7

    So it seems that nearly every time I write about what I plan...

    Motivation, or lack thereof

    Thursday, Friday, Saturday, Sunday - all a whole lot of noth...

    On track so far...

    The week is about half way over, and so far I haven't skippe...

    My pants are on fire!

    I lied. Friday evening I didn't do anything. Saturday ...

    Playing catch-up

    It's been a while since I've updated my P90X progress. A ...

    Re: Yoga kicks my butt

    You should try a different yoga mat. I highly recommend the...

    Yoga kicks my butt

    It's time for a confession. I haven't done an entire Yoga...

    Recovery week comes in the nick of time

    Since it's been a few days, and I know I've rearranged my in...

    weblog | `web·lôg -läg |
    noun
    Another term for BLOG
    ORIGIN 1990s: from web in the sense [World Wide Web] and log in the sense [regular record of incidents.]
    blog | bläg |
    noun
    A web site on which an individual or group of users produces an ongoing narrative.
    ORIGIN a shortening of WEBLOG.

    HTML Test Reporting

    Kent Cowgill

    I wrote a few days ago about writing my own Test::Harness parser since I had been unable to install the module that does that, and does it well.

    On my machine, Test::TAP::HTMLMatrix is beautifully installed - however where this module could do me the most good - as in having tests run all the time for me - I have historically had issues getting modules installed. At the very least, I need to identify all the various dependencies of every module and their dependencies in order for the SAs to search for .rpm files for ease in making the modules easily installable on every other production machine in the cluster. Which makes a certain amount of sense. As long as you don't remember that this test reporting module has no business on production anyhow.

    But a brief perusal of the source for HTMLMatrix, and I'm starting to get the impression that having the SAs install it, plus all it's dependencies, plus all their dependencies, might be more hassle and take longer than I'd like.

    Since I got my html harness pretty much working before trying to install HTML Matrix again, I might as well start using that at work to keep at-a-glace test results at a handy web page. Without all those dependencies.

    So I did. And I copied all the tests over to our dev server. And I tweaked the hell out of them to make them actually run. More on that later.

    The above picture is just a snippet of it to be able to fit into my blog, but you can see a fuller version here.

    The code to create this is pretty simple. Here are the important bits of it:

    
    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use Test::Harness::Straps;
    
    my $strap = Test::Harness::Straps->new();
    
    my $graph_width    = 600;
    my $filename_width = 150;
    my $percent_width  =  75;
    
    print report_head();
    
    my $cnt = 1;
    my $tot = 0;
    my $ok  = 0;
    
    for my $file( @ARGV ){
      next unless -f $file;
      $cnt++;
      my $style = $cnt % 2 ? 'blue' : 'tan';
      my $result = $strap->analyze_file( $file );
      my( $this_tot, $this_ok )
        = ( $result->seen, $result->ok );
      $tot += $this_tot;
      $ok += $this_ok;
      my $graph
        = return_graph( $this_tot, $this_ok );
      my $percent
        = int( $this_ok / $this_tot * 100 );
      my $status = $percent < 100
          ? '<span style="color:red;">NOK</span>'
          : 'OK';
      my $perstyle = get_percent_style( $percent );
      printf <<END_REPORT, $style, $file,
        $file, $status, $graph, $perstyle, $percent;
      <tr class="row">
        <td class="%s">
          <a href="%s">%s</a>
        </td>
        <td class="status">%s</td>
        <td>
          <table class="graph">
            <tr>
    %s
           </tr>
         </table>
       </td>
       <td class="%s ctr">%d\%</td>
     </tr>
    END_REPORT
    }
    
    print report_end();
    
    sub return_graph {
      my( $cnt, $run ) = @_;
      my $width = int( $graph_width / $cnt );
      my $leftover = $cnt - $run;
      my $bad_cell
        = qq{<td class="nok" style="width: }
        . qq{${width}px"> </td>};
      my $good_cell
        = qq{<td class="ok" style="width: }
        . qq{${width}px"> </td>};
      my $cells = $good_cell x $run;
      $cells .= $bad_cell x $leftover;
      return $cells;
    }
    
    sub get_percent_style {
      my $pct = shift;
      return
             $pct == 100    ? 'hundred'
           : $pct >= 95     ? 'ninetyfive'
           : $pct >= 90     ? 'ninety'
           : $pct >= 80     ? 'eighty'
           : $pct >= 70     ? 'seventy'
           : $pct >= 60     ? 'sixty'
           : $pct >= 50     ? 'fifty'
           : $pct >= 40     ? 'forty'
           : $pct >= 30     ? 'thirty'
           : $pct >= 20     ? 'twenty'
           :                  'ten';
    }
    
    
    

    The missing report_header() and report_end() routines add the head, title, stylesheet, body tags, etc. to turn the meat of the output into a web page.

    Btw, if you have 1) unresponsive SAs or 2) too much bureaucracy to get modules installed, and 3) have an improper Scalar::Util installation, and 4) need to use Test::MockObject (or some other module that 'optionally' uses Scalar::Util::weaken - and some Enterprise Linux Distributions ship a broken version of Scalar::Util) you can use this sneaky workaround:

    
    BEGIN {
      # We're not using feature XYZ in
      # Obj::Using::Weaken, so don't
      # care about our improperly
      # installed Scalar::Util
      require Scalar::Util;  # load it into memory
      # we know this causes warnings
      no warnings 'redefine';
      # load our own versions that do nothing.
      *Scalar::Util::weaken = sub { return @_ };
      *Scalar::Util::export_fail = sub { return };
    }
    
    
    
    Related Photos: perl

    Trying to display pre tags inside a pre block

    Kent Cowgill

    I think I know why I can't show HTML pre tags inside a pre block, and it's not Kate's fault, and it's not Textile's fault.

    It's my fault.

    
      if( $text =~ m/<pre class="([^"]+)"/s ){
        $lang = $1;
        $text =~ s/<pre[^>]+>(.*)<\/pre>/$1/s;
      }
    
    
    

    See the problem?

    I'll probably have a few more posts about this until I figure it out.

    But it's not like you were doing anything better than reading this :)

    Related Photos: perl

    Main Page | Login

    Do you want to buy me ? Find more gift ideas at my wishlist