Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CCM::TextRender instead of CAF::TextRender in RegexpTest #53

Merged
merged 7 commits into from
May 5, 2015
Merged
61 changes: 58 additions & 3 deletions build-scripts/src/main/perl/Test/Quattor/Object.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ use File::Path qw(mkpath);

use Readonly;

# The target pan directory used by maven to stage the
# to-be-distributed pan templates
# The target pan directory used by maven to stage the
# to-be-distributed pan templates
Readonly our $TARGET_PAN_RELPATH => 'target/pan';

our @EXPORT = qw($TARGET_PAN_RELPATH);

# Keep track of all logged messages
my $loghist = {};

sub new
{
my $that = shift;
Expand All @@ -46,6 +49,53 @@ sub _initialize

=pod

=head2 add_loghist

Add a log C<message> for C<type> to the log history.

=cut

sub loghist_add
{
my ($self, $type, $message) = @_;

$self->{LOGCOUNT}->{$type}++;
$self->{LOGLATEST}->{$type} = $message;
push(@{$loghist->{$type}}, $message);
}

=pod

=head2 reset_loghist

Reset the log history.

=cut

sub loghist_reset
{
my ($self) = @_;
$self->{LOGCOUNT} = {};
$self->{LOGLATEST} = {};
$loghist = {};
}

=pod

=head2 loghist_get

Return the array of log messages for C<type>.

=cut

sub loghist_get
{
my($self, $type) = @_;
return defined($loghist->{$type}) ? @{$loghist->{$type}} : undef;
}

=pod

=head2 info

info-type logger, calls diag.
Expand All @@ -57,6 +107,7 @@ sub info
{
my ($self, @args) = @_;
my $msg = join('', @args);
$self->loghist_add('INFO', $msg);
diag("INFO $msg");
return $msg;
}
Expand All @@ -74,6 +125,7 @@ sub verbose
{
my ($self, @args) = @_;
my $msg = join('', @args);
$self->loghist_add('VERBOSE', $msg);
note("VERBOSE $msg");
return $msg;
}
Expand All @@ -95,6 +147,7 @@ sub debug
ok(0, "debug logging with unsupported level $level message $msg");
}

$self->loghist_add('DEBUG', "$level $msg");
note("DEBUG: $level $msg");
return $msg;
}
Expand All @@ -113,6 +166,7 @@ sub warn
{
my ($self, @args) = @_;
my $msg = join('', @args);
$self->loghist_add('WARN', $msg);
diag("WARN: $msg");
return $msg;
}
Expand All @@ -130,6 +184,7 @@ sub error
{
my ($self, @args) = @_;
my $msg = join('', @args);
$self->loghist_add('ERROR', $msg);
diag("ERROR: $msg");
return $msg;
}
Expand Down Expand Up @@ -299,7 +354,7 @@ sub get_template_library_core

=head2 make_target_pan_path

Create if needed the "target/pan" path in the current directory, and returns the
Create if needed the "target/pan" path in the current directory, and returns the
absolute pathname.

=cut
Expand Down
36 changes: 35 additions & 1 deletion build-scripts/src/main/perl/Test/Quattor/ProfileCache.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use EDG::WP4::CCM::Configuration;
use EDG::WP4::CCM::CacheManager;
use EDG::WP4::CCM::Fetch;
use EDG::WP4::CCM::Element qw(escape unescape);
use EDG::WP4::CCM::CCfg;

use Readonly;

Expand All @@ -45,7 +46,9 @@ EOF

our @EXPORT = qw(get_config_for_profile prepare_profile_cache
set_profile_cache_options
prepare_profile_cache_panc_includedirs);
prepare_profile_cache_panc_includedirs
set_json_typed get_json_typed
);


# A Test::Quattor::Object instance, can be used as logger.
Expand Down Expand Up @@ -257,4 +260,35 @@ sub get_config_for_profile
return $configs{profile_cache_name($profile)};
}

=pod

=head2 C<set_json_typed>

Set the json_typed config attribute to C<value>.
If value is undefined, C<json_typed> is set to true.

Returns the value set.

=cut

sub set_json_typed
{
my $value = shift;
$value = 1 if(! defined($value));
return EDG::WP4::CCM::CCfg::_setCfgValue('json_typed', $value ? 1 : 0);
}

=pod

=head2 C<get_json_typed>

Return the C<json_typed> value.

=cut

sub get_json_typed
{
return EDG::WP4::CCM::CCfg::getCfgValue('json_typed')
};

1;
48 changes: 33 additions & 15 deletions build-scripts/src/main/perl/Test/Quattor/RegexpTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ Following flags are supported

=over

=item multiline
=item multiline

(no)multiline / multiline=1/0

=item singleline

singleline / singleline=1/0
singleline / singleline=1/0

(This flag can coexist with multiline)

Expand All @@ -179,13 +179,13 @@ case(in)sensistive / casesensitive = 0/1

(un)ordered / ordered=0/1

=back
=back

=item negate

negate / negate = 0/1

Negate all regexps, none of the regexps can match
Negate all regexps, none of the regexps can match
(is an alias for C<COUNT 0> on every regtest;
overwritten when COUNT is set for individual regexp)

Expand All @@ -194,7 +194,7 @@ Negate all regexps, none of the regexps can match
quote / quote = 0/1

Whole tests block is 1 regular expression. With C<quote> flag set,
C<multiline> flag is logged and ignored; C<ordered> flag is
C<multiline> flag is logged and ignored; C<ordered> flag is
meaningless (and silently ignored).

=item location of module and contents settings:
Expand All @@ -209,6 +209,20 @@ Also any flag starting with C</> is interpreted as C<metaconfigservice>

Also any flag starting with C<//> is interpreted as C<renderpath>

=item rendermodule

Specify the value of the module to use. (Precedes
metaconfigservice/renderpath value).

=item contentspath

Specify the path to use for contents. (Precedes
metaconfigservice/renderpath value).

=item element

Comma separated list of predefined element convert options for CCM::TextRender.

=back

=item Default settings
Expand Down Expand Up @@ -243,10 +257,14 @@ sub parse_flags
$self->{flags}->{"$1"} = 0;
} elsif ($line =~ m/^\s*(case)in(sensitive)\s*$/) {
$self->{flags}->{"$1$2"} = 0;
} elsif ($line =~ m/^\s*(metaconfigservice|renderpath)\s*=\s*(\S+)\s*$/) {
} elsif ($line =~ m/^\s*(metaconfigservice|renderpath|contentspath|rendermodule)\s*=\s*(\S+)\s*$/) {
$self->{flags}->{$1} = $2;
} elsif ($line =~ m/^\s*(\/)?(\/\S*)\s*$/) {
$self->{flags}->{defined($1) ? 'renderpath' : 'metaconfigservice'} = $2;
} elsif ($line =~ m/^\s*element=(\S+)\s*$/) {
foreach my $opt (split (',', $1)) {
$self->{flags}->{element}->{$opt} = 1;
}
} else {
$self->notok("Unallowed flag $line");
}
Expand Down Expand Up @@ -290,26 +308,26 @@ sub make_re_flags

Parse the tests block and set C<tests> attribute

If the C<quote> flag is set, the whole tests block is
seen as one big regular expression, and rendered text
If the C<quote> flag is set, the whole tests block is
seen as one big regular expression, and rendered text
has to be an exact match, incl EOF newline etc.

Without the C<quote> flag set, the tests are parsed line by line,
Without the C<quote> flag set, the tests are parsed line by line,
and seen as one regexp per line.

Lines starting with C<\s*#{3} > (trailing space!) are comments.

Lines ending with C<\s#{3}> are interpreted as having options set.
Supported options
Lines ending with C<\s#{3}> are interpreted as having options set.
Supported options

=over

=item COUNT

C<COUNT \d+> is the exact number of matches
C<COUNT \d+> is the exact number of matches
(use C<COUNT 0 >to make sure a line doesn't match).

This is a global count, e.g. in ordered mode the count
This is a global count, e.g. in ordered mode the count
itself is not number of matches since previous test match.

=back
Expand Down Expand Up @@ -357,7 +375,7 @@ sub parse_tests
# redefine line
$line = $1;
}

if ($line =~ m/\s+$/) {
# No auto-chomp, but help figuring out why something doesn't match
$self->verbose("Trailing whitespace found on line $line.");
Expand Down Expand Up @@ -393,7 +411,7 @@ sub match
$self->error("No text to match defined");
return;
}

foreach my $test (@{$self->{tests}}) {

# always make all matches for the whole text
Expand Down
42 changes: 34 additions & 8 deletions build-scripts/src/main/perl/Test/Quattor/TextRender/RegexpTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use Test::More;

use base qw(Test::Quattor::RegexpTest);

use CAF::TextRender;
use EDG::WP4::CCM::TextRender;

=pod

Expand Down Expand Up @@ -47,11 +47,11 @@ The configuration instance to retreive the values from.

=item ttincludepath

The includepath for CAF::TextRender.
The includepath for CCM::TextRender.

=item ttrelpath

The relpath for CAF::TextRender.
The relpath for CCM::TextRender.

=back

Expand All @@ -60,24 +60,50 @@ The relpath for CAF::TextRender.
=cut

# Render the text using config and flags-renderpath
# Store the CAF::TextRender instance and the get_text result in attributes
# Store the CCM::TextRender instance and the get_text result in attributes
sub render
{
my ($self) = @_;

my $srv = $self->{config}->getElement($self->{flags}->{renderpath})->getTree();
my $renderpath = $self->{flags}->{renderpath};
my ($module, $contentspath);

if ($self->{flags}->{rendermodule}) {
$module = $self->{flags}->{rendermodule};
} else {
my $modulepath = "$renderpath/module";
ok($self->{config}->elementExists($modulepath), "modulepath $modulepath elementExists");

$module = $self->{config}->getElement($modulepath)->getValue()
}
ok($module, "rendermodule specified". ($module || "<undef>"));

if ($self->{flags}->{contentspath}) {
$contentspath = $self->{flags}->{contentspath};
} else {
$contentspath = "$renderpath/contents";
}
ok($contentspath, "contentspath specified". ($contentspath || "<undef>"));
ok($self->{config}->elementExists($contentspath), "contentspath elementExists");

ok($self->{ttincludepath}, "ttincludepath specified " . ($self->{ttincludepath} || '<undef>'));
ok($self->{ttrelpath}, "ttrelpath specified " . ($self->{ttrelpath} || '<undef>'));

# TODO how to keep this in sync with what metaconfig does? esp the options
$self->{trd} = CAF::TextRender->new(
$srv->{module},
$srv->{contents},
my $opts = {
eol => 0,
relpath => $self->{ttrelpath},
includepath => $self->{ttincludepath},
log => $self,
};
if(defined($self->{flags}->{element})) {
$opts->{element} = $self->{flags}->{element};
}

$self->{trd} = EDG::WP4::CCM::TextRender->new(
$module,
$self->{config}->getElement($contentspath),
%$opts
);

$self->{text} = $self->{trd}->get_text;
Expand Down
Loading