File: 3-complete-errors.t

package info (click to toggle)
libfile-libmagic-perl 0.96-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 232 kB
  • sloc: perl: 290; pascal: 88; ansic: 54; makefile: 13
file content (63 lines) | stat: -rw-r--r-- 1,774 bytes parent folder | download | duplicates (2)
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
use strict;
use warnings;

use Test::More tests => 7;

use File::LibMagic qw( :complete );

# TODO can we simulate an out-of-memory error?

# try to use a missing magic file
{
    my $h = magic_open(MAGIC_NONE);
    
    {
        no warnings 'uninitialized';
        eval { magic_load(undef, 't/samples/magic') };
        like( $@, qr{magic_load requires a defined handle}, 'magic_load(undef)' );
    }
    eval { magic_load($h, 't/samples/missing') };
#    like( $@, qr{libmagic could not find any magic files}, 'missing magic file' );
    magic_close($h);
}

{
    my $h = magic_open(MAGIC_NONE);
    magic_load($h, 't/samples/magic');

    # try to get information about an undef buffer
    {
        no warnings 'uninitialized';
        eval { magic_buffer(undef, "Foo") };
        like( $@, qr{magic_buffer requires a defined handle}, 'magic_buffer(undef)' );
    }

    eval { magic_buffer($h, undef) };
    like( $@, qr{magic_buffer requires defined content}, 'magic_buffer no content' );


    # try to get information about a missing file
    {
        no warnings 'uninitialized';
        eval { magic_file(undef, 't/samples/foo.foo') };
        like( $@, qr{magic_file requires a defined handle}, 'magic_file(undef)' );
    }

    eval { magic_file($h, undef) };
    like( $@, qr{magic_file requires a filename}, 'magic_file no file' );

    TODO: {
        local $TODO = 'check libmagic version';
        eval { magic_file($h, 't/samples/missing') };
        like( $@, qr{libmagic cannot open .+ at }, 'missing file' );
        magic_close($h)
    };
}

# try calling magic_close with undef handle
{
    no warnings 'uninitialized';
    my $h = magic_open(MAGIC_NONE);
    eval { magic_close(undef) };
    like($@, qr{magic_close requires a defined handle});
}