b2118764bd0c2a77750c769d57723a456fde02bd
[p5sagit/Config-Any.git] / t / 10-branches.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 10;
5
6 use_ok( 'Config::Any' );
7
8 {
9     my @warnings;
10     local $SIG{ __WARN__ } = sub { push @warnings, @_ };
11
12     Config::Any->load_files();
13     like(
14         shift @warnings,
15         qr/^No files specified!/,
16         "load_files expects args"
17     );
18
19     Config::Any->load_files( {} );
20     like(
21         shift @warnings,
22         qr/^No files specified!/,
23         "load_files expects files"
24     );
25
26     Config::Any->load_stems();
27     like(
28         shift @warnings,
29         qr/^No stems specified!/,
30         "load_stems expects args"
31     );
32
33     Config::Any->load_stems( {} );
34     like(
35         shift @warnings,
36         qr/^No stems specified!/,
37         "load_stems expects stems"
38     );
39 }
40
41 # grep out files we don't understand for these tests
42 my @files = grep { !m{\.(foo|unsupported)$} } glob( "t/conf/conf.*" );
43 my $filter = sub { return };
44 ok( Config::Any->load_files( { files => \@files, use_ext => 0 } ),
45     "use_ext 0 works" );
46 ok( Config::Any->load_files( { files => \@files, use_ext => 1 } ),
47     "use_ext 1 works" );
48
49 ok( Config::Any->load_files(
50         { files => \@files, use_ext => 1, filter => \&$filter }
51     ),
52     "filter works"
53 );
54 eval {
55     Config::Any->load_files(
56         {   files   => \@files,
57             use_ext => 1,
58             filter  => sub { die }
59         }
60     );
61 };
62 ok( $@, "filter breaks" );
63
64 my @stems = qw(t/conf/conf);
65 ok( Config::Any->load_stems( { stems => \@stems, use_ext => 1 } ),
66     "load_stems with stems works" );