File: _validate_options.t

package info (click to toggle)
libtest-files-perl 0.26-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 352 kB
  • sloc: perl: 406; makefile: 7
file content (75 lines) | stat: -rw-r--r-- 2,597 bytes parent folder | download
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
use strict;
use warnings
  FATAL    => qw( all ),
  NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized );

use Test::Expander;

use Test::Files::Constants qw(
  $DIRECTORY_OPTIONS $FMT_FILTER_ISNT_CODEREF $FILE_OPTIONS $FMT_INVALID_NAME_PATTER $FMT_INVALID_OPTIONS $FILE_OPTIONS
);

my ( $expected, $self );

plan( 2 );

subtest failure => sub {
  plan( 3 );

  const my $DEFAULT => $DIRECTORY_OPTIONS;

  subtest 'invalid option' => sub {
    plan( 2 );

    isa_ok( $self = $CLASS->_init->options( { X => 0 } )->$METHOD( $DEFAULT ), [ $CLASS ],    'executed' );

    $expected = sprintf( $FMT_INVALID_OPTIONS, 'X' );
    is( $self->diag,                                                           [ $expected ], 'detected' );
  };

  subtest 'filter is not a code reference' => sub {
    plan( 2 );

    isa_ok( $self = $CLASS->_init->options( { FILTER => 0 } )->$METHOD( $DEFAULT ), [ $CLASS ],        'executed' );

    $expected = sprintf( $FMT_FILTER_ISNT_CODEREF, '.+' ) =~ s/([()])/\\$1/gr;
    like( $self->diag,                                                              [ qr/$expected/ ], 'detected' );
  };

  subtest 'invalid name pattern' => sub {
    plan( 2 );

    isa_ok( $self = $CLASS->_init->options( { NAME_PATTERN => '[' } )->$METHOD( $DEFAULT ), [ $CLASS ],        'executed' );

    $expected = sprintf( $FMT_INVALID_NAME_PATTER, '\[', '.+', '.+' );
    like( $self->diag,                                                                      [ qr/$expected/ ], 'detected' );
  };
};

subtest success => sub {
  plan( 2 );

  subtest 'both filter and name pattern supplied' => sub {
    plan( 3 );

    const my $DEFAULT => $DIRECTORY_OPTIONS;

    my $filter = sub {};
    isa_ok(
      $self = $CLASS->_init->options( { FILTER => $filter, NAME_PATTERN => '..' } )->$METHOD( $DEFAULT ),
                        [ $CLASS ],                                             'executed'
    );
    is( $self->diag,    [],                                                     'no errors' );
    is( $self->options, { %$DEFAULT, FILTER => $filter, NAME_PATTERN => '..' }, 'arguments determined' );
  };

  subtest 'both filter and name pattern omitted' => sub {
    plan( 3 );

    const my $DEFAULT => $FILE_OPTIONS;

    isa_ok( $self = $CLASS->_init->options( {} )->$METHOD( $DEFAULT ), [ $CLASS ], 'executed' );
    is( $self->diag,                                                   [],         'no errors' );
    is( $self->options,                                                $DEFAULT,   'arguments determined' );
  };
};