File: AnyOf.pm

package info (click to toggle)
libfile-libmagic-perl 1.02-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 524 kB
  • ctags: 849
  • sloc: perl: 1,616; pascal: 88; ansic: 54; makefile: 13
file content (41 lines) | stat: -rw-r--r-- 647 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
package Test::AnyOf;

use strict;
use warnings;

use Exporter;

use base 'Exporter';

our @EXPORT = qw( is_any_of );

use Test::More;

sub is_any_of ($$;$) {
    my $got    = shift;
    my $expect = shift;
    my $name   = shift;

    local $Test::Builder::Level = $Test::Builder::Level + 1;

    my $tb = Test::More->builder;

    my $match = ( grep { $got eq $_ } @{$expect} ) ? 1 : 0;

    $tb->ok( $match, $name );

    unless ($match) {
        my $diag = <<'EOF';
         got: $got
    expected: any one of ...
EOF
        $diag .= join "\n", map { "             $_"} @{$expect};

        $tb->diag($diag);
    }

    return $match;
}

1;