The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Parser - Base class for parsing log files from test runs, and displays in an XML syntax.

SYNOPSIS

 use Test::Parser::MyTest;

 my $parser = new Test::Parser::MyTest;
 $parser->parse($text) 
    or die $parser->error(), "\n";
 printf("Num Errors:    %8d\n", $parser->num_errors());
 printf("Num Warnings:  %8d\n", $parser->num_warnings());
 printf("Num Executed:  %8d\n", $parser->num_executed());
 printf("Num Passed:    %8d\n", $parser->num_passed());
 printf("Num Failed:    %8d\n", $parser->num_failed());
 printf("Num Skipped:   %8d\n", $parser->num_skipped());

 printf("\nErrors:\n");
 foreach my $err ($parser->errors()) {
     print $err;
 }

 printf("\nWarnings:\n");
 foreach my $warn ($parser->warnings()) {
     print $warn;
 }

 print $parser->to_xml();

DESCRIPTION

This module serves as a common base class for test log parsers. These tools are intended to be able to parse output from a wide variety of tests - including non-Perl tests.

The parsers also write the test data into the 'Test Result Publication Interface' (TRPI) XML schema, developed by SpikeSource. See http://www.spikesource.com/testresults/index.jsp?show=trpi-schema

FUNCTIONS

new()

Creates a new Test::Parser object.

name()

Gets/sets name parameter. user-customizable identification tag

testname()

Gets/sets testname parameter.

to_xml

Method to print test result data from the Test::Parser object in xml format following the trpi schema. Find the trpi schema here: http://developer.osdl.org/~jdaiker/trpi_extended_proposal.xsd

add_column

A method that adds test column information into the data structure of the Test::Parser object appropriately. This is a helper method to be used from the parse_line method.

add_data

A method that adds data values corresponding to a given column

inc_datum

A method that increments the num-datum variable

to_dump()

Function to output all data, good for debuging

set_debug($debug)

Turns on debug level. Set to 0 or undef to turn off.

type()

Gets or sets the testsuite type. Valid values include the following: unit, regression, load, integration, boundary, negative, stress, demo, standards

get_key

    Purpose: To find individual key values parsed from test results
    Input: The search key, the 'datum' the key is stored in
    Output: Data stored under the search key, or the search key if not found

parse($input, [$name[, $path]])

Call this routine to perform the parsing process. $input can be any of the following:

    * A text string
    * A filename of an external log file to parse
    * An open file handle (e.g. \*STDIN)

If you are dealing with a very large file, then using the filename approach will be more memory efficient. If you wish to use this program in a pipe context, then the file handle style will be more suitable.

This routine simply iterates over each newline-separated line of text, calling _parse_line. Note that the default _parse_line() routine does nothing particularly interesting, so you will probably wish to subclass Test::Parser and provide your own implementation of parse_line() to do what you need.

The 'name' argument allows you to specify the log filename or other indication of the source of the parsed data. 'path' allows specification of the location of this file within the test run directory. By default, if $input is a filename, 'name' and 'path' will be taken from that, else they'll be left blank.

If the filename contains multiple test records, parse() simply parses the first one it finds, and then returns the constant Test::Parser::END_OF_RECORD. If your input file contains multiple records, you probably want to call parse in the GLOB fashion. E.g.,

    my @logs;
    open (FILE, 'my.log') or die "Couldn't open: $!\n";
    while (FILE) {
        my $parser = new Test::Parser;
        $parser->parse(\*FILE);
        push @logs, $parser;
    }
    close (FILE) or die "Couldn't close: $!\n";

parse_line($text)

Virtual function for parsing a line of test result data. The base class' implementation of this routine does nothing interesting.

You will need to override this routine to customize it to your application. The parse() routine will call this iteratively for each line of text in the test output file.

Returns undef on error. The error message can be retrieved via error().

num_warnings()

The number of warnings found

warnings()

Returns a reference to an array of the warnings encountered.

num_errors()

The number of errors found

errors()

Returns a reference to an array of the errors encountered.

AUTHOR

Bryce Harrington <bryce@osdl.org>

COPYRIGHT

Copyright (C) 2005 Bryce Harrington. All Rights Reserved.

This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO

perl, Test::Metadata