Skip to content

Commit

Permalink
Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
giterlizzi committed Mar 5, 2024
1 parent 0e5d964 commit c09d86a
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 148 deletions.
2 changes: 1 addition & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ lib/CSAF.pm
lib/CSAF/Base.pm
lib/CSAF/Builder.pm
lib/CSAF/Document.pm
lib/CSAF/List.pm
lib/CSAF/Parser.pm
lib/CSAF/Renderer.pm
lib/CSAF/Renderer/Base.pm
Expand Down Expand Up @@ -70,6 +69,7 @@ lib/CSAF/Type/Tracking.pm
lib/CSAF/Type/Vulnerabilities.pm
lib/CSAF/Type/Vulnerability.pm
lib/CSAF/Util.pm
lib/CSAF/Util/List.pm
lib/CSAF/Validator.pm
lib/CSAF/Validator/Base.pm
lib/CSAF/Validator/MandatoryTests.pm
Expand Down
4 changes: 2 additions & 2 deletions lib/CSAF/Type/List.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use warnings;
use Moo;
use Carp;

extends 'CSAF::List';
extends 'CSAF::Util::List';

has item_class => (is => 'ro', required => 1);

Expand Down Expand Up @@ -78,7 +78,7 @@ L<CSAF::Type::List> is a base collection class.
=head2 METHODS
L<CSAF::Type::List> inherits all methods from L<CSAF::List> and implements the following new ones.
L<CSAF::Type::List> inherits all methods from L<CSAF::Util::List> and implements the following new ones.
=over
Expand Down
5 changes: 2 additions & 3 deletions lib/CSAF/Type/Relationship.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ has product_reference => (is => 'rw', required => 1);
has relates_to_product_reference => (is => 'rw', required => 1);

has full_product_name => (
is => 'rw',
predicate => 1,
coerce => sub {
is => 'rw',
coerce => sub {
(ref($_[0]) !~ /FullProductName/) ? CSAF::Type::FullProductName->new(shift) : $_[0];
}
);
Expand Down
14 changes: 7 additions & 7 deletions lib/CSAF/List.pm → lib/CSAF/Util/List.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package CSAF::List;
package CSAF::Util::List;

use 5.010001;
use strict;
Expand Down Expand Up @@ -65,17 +65,17 @@ __END__
=head1 NAME
CSAF::List - Collection utility
CSAF::Util::List - Collection utility
=head1 SYNOPSIS
use CSAF::List;
my $collection = CSAF::List->new( qw[foo bar baz] );
use CSAF::Util::List;
my $collection = CSAF::Util::List->new( qw[foo bar baz] );
=head1 DESCRIPTION
L<CSAF::List> is a collection utility.
L<CSAF::Util::List> is a collection utility.
=head2 METHODS
Expand Down Expand Up @@ -140,13 +140,13 @@ Get the last element of collection.
Evalutate the callback and create a new collection.
CSAF::List->new(1,2,3)->map(sub { $_ * 2 });
CSAF::Util::List->new(1,2,3)->map(sub { $_ * 2 });
=item new
Create a new collection.
my $c = CSAF::List->new( [foo bar baz] );
my $c = CSAF::Util::List->new( [foo bar baz] );
=item size
Expand Down
17 changes: 7 additions & 10 deletions lib/CSAF/Validator/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ use List::Util qw(first);
use Moo;
extends 'CSAF::Base';

use constant DEBUG => $ENV{CSAF_DEBUG};

our %TESTS = ();

has messages => (is => 'rw', default => sub { [] });

has tests => (is => 'rw', default => sub { [] });
has messages => (is => 'ro', default => sub { [] });
has summary => (is => 'ro', default => sub { {} });
has tests => (is => 'rw', default => sub { [] });

sub validate { Carp::croak 'Method "validate" not implemented by subclass' }

Expand All @@ -32,7 +30,10 @@ sub add_message {
my ($self, $message) = @_;

$self->{messages} ||= [];
push @{$self->{messages}}, $message;
$self->{summary}->{$message->code} ||= [];

push @{$self->{messages}}, $message;
push @{$self->{summary}->{$message->code}}, $message;

}

Expand All @@ -44,12 +45,8 @@ sub exec_test {
$test_sub =~ tr/\./_/;

if (my $code_ref = $self->can($test_sub)) {

DEBUG and say STDERR sprintf '(I) %s - Execute test %s', ref($self), $test_id;

eval { $code_ref->($self) };
Carp::croak "Failed to execute test $test_id: $@" if ($@);

}

}
Expand Down
Loading

0 comments on commit c09d86a

Please sign in to comment.