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

tests #1

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ jobs:
- "5.24"
- "5.22"
- "5.20"
- "5.18"
- "5.16"
- "5.14"
- "5.12"
- "5.10"
- "5.8"

env:
CIP_TAG: ${{ matrix.cip_tag }}
Expand Down
3 changes: 2 additions & 1 deletion dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ version_plugin = PkgVersion::Block
[Author::Plicease::Upload]
cpan = 0


[Prereqs]
Class::Method::Modifiers = 0
5 changes: 3 additions & 2 deletions lib/Perl/Critic/Role/Cacheable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ The name of the file where the cache will be stored.
}

sub _cacheable_config_digest ($self) {
return $self->{_cacheable}->{rc_digest};
return $self->{_cacheable}->{config_digest};
}

sub _cacheable_digest_ok ($self) {
Expand Down Expand Up @@ -156,7 +156,8 @@ critiqued and had no violations will not be checked again.

around critique => sub ($orig, $self, $source_code) {

my $filename = !is_ref $source_code ? Path::Tiny->new($source_code)->absolute->stringify : undef;
$DB::single = 1;
my $filename = !Ref::Util::is_ref $source_code ? Path::Tiny->new($source_code)->absolute->stringify : undef;
if($filename) {
return () if $self->_cacheable_check_cache_ok($filename);
}
Expand Down
1 change: 1 addition & 0 deletions t/00_diag.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ my %modules;
my $post_diag;

$modules{$_} = $_ for qw(
Class::Method::Modifiers
Cpanel::JSON::XS
ExtUtils::MakeMaker
Path::Tiny
Expand Down
161 changes: 158 additions & 3 deletions t/perl_critic_role_cacheable.t
Original file line number Diff line number Diff line change
@@ -1,22 +1,177 @@
use Test2::V0 -no_srand => 1;
use experimental qw( signatures postderef );
use Perl::Critic::Role::Cacheable;
use Path::Tiny;

package Perl::Critic::Cacheable {
my @faux_violations;
my $call_count;

package MyCritic {
use parent 'Perl::Critic';
use Role::Tiny::With ();

Role::Tiny::With::with 'Perl::Critic::Role::Cacheable';

sub critique ($self, $source_code ) {
$call_count++;
my @old = @faux_violations;
@faux_violations = ();
return @old;
}

sub new ($self, @args) {
$call_count = 0;
return $self->SUPER::new(@args);
}
}

subtest 'very basic' => sub {

my $critic = Perl::Critic::Cacheable->new;
my $critic = MyCritic->new;
isa_ok $critic, 'Perl::Critic';
ok $critic->can('new'), 'has new method';
ok !$critic->can('around'), 'does not have around method';

};

done_testing;
subtest 'cache' => sub {
my $root = Path::Tiny->tempdir;

my @perl_source = (map { $root->child($_) } qw( source1.pl source2.pm));
$perl_source[0]->spew('foo');
$perl_source[1]->spew('bar');

my $profile = $root->child('profile');
$profile->spew('');

my $cache = $root->child('cache');

subtest 'first run (no cache)' => sub {
my $critic = MyCritic->new(
-profile => "$profile",
'-cacheable-filename' => "$cache"
);

is(
[$critic->critique("$perl_source[0]")],
[],
"call \$critic->critique(\"$perl_source[0]\") = []",
);

@faux_violations = ('a','b','x');

is(
[$critic->critique("$perl_source[1]")],
['a','b','x'],
"call \$critic->critique(\"$perl_source[1]\") = [a,b,x]",
);

is $call_count, 2, 'expected call count';
$critic->cacheable_save;

ok -r $cache, 'created cache file';
};

subtest 'second run (with cache)' => sub {
my $critic = MyCritic->new(
-profile => "$profile",
'-cacheable-filename' => "$cache"
);

is(
[$critic->critique("$perl_source[0]")],
[],
"call \$critic->critique(\"$perl_source[0]\") = []",
);

@faux_violations = ('a','b','x');

is(
[$critic->critique("$perl_source[1]")],
['a','b','x'],
"call \$critic->critique(\"$perl_source[1]\") = [a,b,x]",
);

is $call_count, 1, 'expected call count';
};

subtest 'third run with change to source file' => sub {
$perl_source[0]->spew('baz');

my $critic = MyCritic->new(
-profile => "$profile",
'-cacheable-filename' => "$cache"
);

is(
[$critic->critique("$perl_source[0]")],
[],
"call \$critic->critique(\"$perl_source[0]\") = []",
);

@faux_violations = ('a','b','x');

is(
[$critic->critique("$perl_source[1]")],
['a','b','x'],
"call \$critic->critique(\"$perl_source[1]\") = [a,b,x]",
);

is $call_count, 2, 'expected call count';
};

subtest 'forth run with change to profile' => sub {
$perl_source[0]->spew('foo');
$profile->spew('; just a comment');

my $critic = MyCritic->new(
-profile => "$profile",
'-cacheable-filename' => "$cache"
);

is(
[$critic->critique("$perl_source[0]")],
[],
"call \$critic->critique(\"$perl_source[0]\") = []",
);

@faux_violations = ('a','b','x');

is(
[$critic->critique("$perl_source[1]")],
['a','b','x'],
"call \$critic->critique(\"$perl_source[1]\") = [a,b,x]",
);

is $call_count, 2, 'expected call count';
};

subtest 'forth run with change to arguments' => sub {
my $profile = $root->child('profile2');
$profile->spew('');

my $critic = MyCritic->new(
-profile => "$profile",
'-cacheable-filename' => "$cache"
);

is(
[$critic->critique("$perl_source[0]")],
[],
"call \$critic->critique(\"$perl_source[0]\") = []",
);

@faux_violations = ('a','b','x');

is(
[$critic->critique("$perl_source[1]")],
['a','b','x'],
"call \$critic->critique(\"$perl_source[1]\") = [a,b,x]",
);

is $call_count, 2, 'expected call count';
};

};

done_testing;
Loading