File: compare_archives_ok.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 (84 lines) | stat: -rw-r--r-- 2,296 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
76
77
78
79
80
81
82
83
84
use strict;
use warnings
  FATAL    => qw( all ),
  NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized );

use Test::Expander;

plan( 2 );

subtest success => sub {
  plan( 3 );

  my $mock_this = mock $CLASS => (
    override => [
      _compare_dirs           => sub { pass( 'content compared' ) },
      _compare_metadata       => sub { pass( 'metadata compared' ); shift },
      _extract                => sub { shift },
      _validate_trailing_args => sub { my ( $self ) = @_; $self->options( { EXTRACT => sub {}, FILTER => qr/./ } ) },
    ]
  );

  ok( $METHOD_REF->( 'got_archive', 'reference_archive' ), 'executed' );
};

subtest failure => sub {
  plan( 4 );

  subtest 'invalid arguments' => sub {
    plan( 1 );

    my $mock_this = mock $CLASS => (
      override => [
        _show_failure           => sub {},
        _validate_trailing_args => sub { shift->diag( [ 'ERROR' ] ) },
      ]
    );

    ok( !$METHOD_REF->( 'got_archive', 'reference_archive' ), 'executed' );
  };

  subtest 'metadata differs or cannot be extracted' => sub {
    plan( 1 );

    my $mock_this = mock $CLASS => (
      override => [
        _compare_metadata       => sub { shift->diag( [ 'ERROR' ] ) },
        _show_failure           => sub {},
        _validate_trailing_args => sub { shift },
      ]
    );

    ok( !$METHOD_REF->( 'got_archive', 'reference_archive' ), 'executed' );
  };

  subtest 'content differs' => sub {
    plan( 1 );

    my $mock_this = mock $CLASS => (
      override => [
        _compare_metadata       => sub { shift },
        _extract                => sub { shift->diag( undef ) },
        _show_failure           => sub {},
        _validate_trailing_args => sub { shift },
      ]
    );

    ok( !$METHOD_REF->( 'got_archive', 'reference_archive' ), 'executed' );
  };

  subtest 'content cannot be extracted' => sub {
    plan( 1 );

    my $mock_this = mock $CLASS => (
      override => [
        _compare_metadata       => sub { shift },
        _extract                => sub { shift->diag( [ 'ERROR' ] ) },
        _show_failure           => sub {},
        _validate_trailing_args => sub { shift },
      ]
    );

    ok( !$METHOD_REF->( 'got_archive', 'reference_archive' ), 'executed' );
  };
};