1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#!/bin/env perl
use strict;
use warnings;
use lib 't/lib';
use Test::More;
use Test::Routine;
use Test::Routine::Util;
use namespace::autoclean;
{
package Test::Routine::Role::TestWithFlavor;
use Moose::Role;
has flavor => (
is => 'ro',
isa => 'Str',
default => sub { 'vanilla' },
);
around skip_reason => sub {
my ($orig, $self, $test_instance) = @_;
return unless $test_instance->can('only_flavor');
return unless $test_instance->only_flavor;
return if $test_instance->only_flavor eq $self->flavor;
return sprintf "only running %s tests, but test is %s flavor",
$test_instance->only_flavor,
$self->flavor;
return $self->$orig($test_instance);
};
no Moose::Role;
}
{
package Test::Routine::TestsHaveFlavor;
use Moose::Role;
sub test_routine_test_traits {
return 'Test::Routine::Role::TestWithFlavor';
}
no Moose::Role;
}
with 'Test::Routine::TestsHaveFlavor';
has only_flavor => (
is => 'ro',
isa => 'Str',
);
test "I like bananas" => sub {
my ($self) = @_;
ok(1);
};
test "Do you like bananas" => sub {
my ($self) = @_;
ok(1);
};
test "No, cucumbers are best" => { flavor => 'cuke' } => sub {
my ($self) = @_;
ok(1);
};
run_me;
run_me({ only_flavor => 'vanilla' });
run_me({ only_flavor => 'cuke' });
done_testing;
|