On 2/27/06, anu p <[EMAIL PROTECTED]> wrote:
> Hi,
>
>   I have a script which runs a regression and
> generates a log of failed tests.
>
> Eg: Test:     dir1/test1.v failed
>
> My manager wants me to create a link to the file, so
> that if we click on the link the actual log pops up in
> a browser. I know the path to open the test in a
> browser, it's like
> file:////a/b/c/dir1/test1.v
>
> Till now I have only used Perl for mainly text
> processing and I have no idea how to start on this.
>
> It would be great if some one can suggest me where to
> start from.
>
> Thanks a lot,
> Anu.

This is still text processing.  It is just a different target: html. 
What you want is a file named log.html that contains the text:

<html>
<head>
<title>Log for X run on 2006-02-27 12:01:23</title>
</head>
<body>
Test: <a href="file:////a/b/c/dir1/test1.v">dir1/test1.v failed</a><br />
Test: <a href="file:////a/b/c/dir1/test2.v">dir1/test2.v failed</a><br />
Test: <a href="file:////a/b/c/dir1/test5.v">dir1/test5.v failed</a><br />
</body>
</html>

You can get this by either parsing your original log or by writting
the original log with this information.  Since I don't know what sort
of test harness you are using I will assume that I have a file with
the format:

Test:     {testfile} failed

with one line per test failure.  The (untested) code to generate the
html file would be

#!/usr/bin/perl

use strict;
use warnings;
use IO::File;

my $filename = shift;
my $in   = IO::File->new;
my $out = IO::File->new;
$in->open("<", $filename) or die "Could not open $filename for reading:$!";
$out->open(">", "$filename.html") or die "Could not open $filename for
writing:$!";

my $runtime = localtime(($in->stat)[9]);

$out->print("<html>\n<head>\n<title>Log for X run on
$runtime</title>\n</head>\n<body>");

while (my $line = <$in>) {
    next unless $line =~ /Test:\s+(.*)\s+failed/;
    my $test = $1;
    $out->print(qq(Test <a href="file:////a/b/c/$test">$test</a><br />\n));
}

$out->print("</body>\n</html>\n");

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to