File: main-module.t

package info (click to toggle)
libdist-zilla-perl 4.300020-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,144 kB
  • sloc: perl: 6,159; makefile: 9
file content (95 lines) | stat: -rw-r--r-- 3,116 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use strict;
use warnings;

use Test::More 0.88;

use lib 't/lib';

use Test::DZil;
use YAML::Tiny;

sub mkconfig {
  my $root = shift;
  my $t = Builder->from_config( { dist_root => $root }, { add_files => { 'source/dist.ini' => simple_ini(@_) } } );
  $t->build;
  return $t;
}

sub testeval(&&) {
  my ( $evaler, $testcode ) = @_;
  local $@;
  eval { $evaler->(); };
  my $lasterror = $@;
  $lasterror = undef if $lasterror eq "";
  $testcode->( defined $lasterror, $lasterror );
}

#
# no main_module + No Gatherdir + Legit Filesystem
#
testeval { mkconfig( 'corpus/dist/DZT', [ Prereqs => { 'Test::Simple' => 0.88 } ] )->main_module } sub {
  my ( $died, $error ) = @_;
  ok( $died, 'fails with no main_module' );
  like( $error, qr/didn't find any files in your dist/, 'tells users there are no files in dist' );
  like( $error, qr{tried to guess 'lib/DZT/Sample.pm'}, 'tells user what we expected to find' );
};

# no main_module + gatherdir + legit filesystem
#
testeval { mkconfig( 'corpus/dist/DZT', 'GatherDir', [ Prereqs => { 'Test::Simple' => 0.88 } ] )->main_module } sub {
  my ( $died, $error ) = @_;
  ok( !$died, 'should not fail with main_module' );
};

# no main_module + gatherdir + bogus filesystem
#
testeval { mkconfig( 'corpus/dist/DZT_NoPm', 'GatherDir', [ Prereqs => { 'Test::Simple' => 0.88 } ] )->main_module } sub {
  my ( $died, $error ) = @_;
  ok( $died, 'fails with no main_module' );
  like( $error, qr{tried to guess 'lib/DZT/Sample.pm'}, 'tells user what we expected to find' );
  like( $error, qr{We didn't find any \.pm files},      'tells the user there are no pm files' );
};

# bad main_module, no gatherdir, legit filesystem
#
testeval {
  mkconfig( 'corpus/dist/DZT', { main_module => 'lib/Bogus/Adventure.pm' }, [ Prereqs => { 'Test::Simple' => 0.88 } ] )
    ->main_module;
}
sub {
  my ( $died, $error ) = @_;
  ok( $died, 'should fail with missing main_module' );
  like( $error, qr/didn't find any files in your dist/, 'tells users there are no files in dist' );
  like( $error, qr{but the file 'lib/Bogus/Adventure.pm' is not to be found}, 'tells user their main_module was fubar' );
};

# bad main_module, gatherdir, legit filesystem
#
testeval {
  mkconfig( 'corpus/dist/DZT', { main_module => 'lib/Bogus/Adventure.pm' },
    'GatherDir', [ Prereqs => { 'Test::Simple' => 0.88 } ] )->main_module;
}
sub {
  my ( $died, $error ) = @_;
  ok( $died, 'should fail with missing main_module' );
  like( $error, qr{but the file 'lib/Bogus/Adventure.pm' is not to be found}, 'tells user their main_module was fubar' );
};

# bad main_module, gatherdir, bogus filesystem
#
testeval {
  mkconfig(
    'corpus/dist/DZT_NoPm', { main_module => 'lib/Bogus/Adventure.pm' },
    'GatherDir', [ Prereqs => { 'Test::Simple' => 0.88 } ]
  )->main_module;
}
sub {
  my ( $died, $error ) = @_;
  ok( $died, 'should fail with missing main_module' );
  like( $error, qr{but the file 'lib/Bogus/Adventure.pm' is not to be found}, 'tells user their main_module was fubar' );
  like( $error, qr{We didn't find any \.pm files}, 'tells the user there are no pm files' );

};

done_testing;