File: _compare_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 (55 lines) | stat: -rw-r--r-- 1,886 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
use strict;
use warnings
  FATAL    => qw( all ),
  NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized );

use Test::Expander -tempdir => {};

my ( $args_valid, $diff, $info_valid );
my $mock_this = mock $CLASS => (
  override => [
    _compare_files          => sub { my ( $self ) = @_; $self->diag( $diff ); $self },
    _get_two_files_info     => sub { shift->diag( $info_valid ? [] : [ 'INFO ERROR' ] ) },
    _show_failure           => sub {},
    _show_result            => sub { !@{ shift->diag } },
    _validate_trailing_args => sub { shift->diag( $args_valid ? [] : [ 'ARGS ERROR' ] ) },
  ]
);

plan( 4 );

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

  my $self = $CLASS->_init;
  ( $args_valid, $diff, $info_valid ) = ( 0, [], 1 );
  ok( !$self->$METHOD( 'got_file', 'expected_file' ), 'failed' );
  is( $self->diag, [ 'ARGS ERROR' ],                  'failure reported' );
};

subtest 'file info cannot be gathered' => sub {
  plan( 2 );

  my $self = $CLASS->_init;
  ( $args_valid, $diff, $info_valid ) = ( 1, [], 0 );
  ok( !$self->$METHOD( 'got_file', 'expected_file' ), 'failed' );
  is( $self->diag, [ 'INFO ERROR' ],                  'failure reported' );
};

subtest 'expected file passed, differences detected' => sub {
  plan( 2 );

  my $self = $CLASS->_init;
  ( $args_valid, $diff, $info_valid ) = ( 1, [ 'DIFF' ],  1 );
  ok( !$self->$METHOD( 'got_file', 'expected_file' ), 'failed' );
  is( $self->diag, [ 'DIFF' ],                        'differences reported' );
};

subtest 'expected content passed, differences detected' => sub {
  plan( 2 );

  my $self = $CLASS->_init;
  ( $args_valid, $diff, $info_valid ) = ( 1, [ 'DIFF' ],  1 );
  ok( !$self->$METHOD( 'got_file', \'expected_file' ), 'failed' );
  is( $self->diag, [ 'DIFF' ],                         'differences reported' );
};