6add3b6787ba7f5687aad0e583de4441c25c9554
[webpac2] / t / 2-parse.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use Test::More tests => 19;
5 use Test::Exception;
6 use blib;
7
8 use Data::Dump qw/dump/;
9 use Cwd qw/abs_path/;
10 use YAML qw/LoadFile/;
11
12 BEGIN {
13 use_ok( 'WebPAC::Parser' );
14 use_ok( 'WebPAC::Config' );
15 }
16
17 my $debug = shift @ARGV;
18
19 ok(my $abs_path = abs_path($0), "abs_path");
20 $abs_path =~ s#/[^/]*$#/#;
21
22 my $config_path = "$abs_path/conf/test.yml";
23
24 ok(-e $config_path, "$config_path exists");
25
26 throws_ok { new WebPAC::Parser( no_log => 1 ) } qr/WebPAC::Config/, "new without config";
27
28 ok(
29         my $parser = new WebPAC::Parser(
30                 config => new WebPAC::Config( path => $config_path ),
31                 base_path => $abs_path,
32                 debug => $debug,
33 ), "new");
34
35 my $inputs = {
36         foo => [ qw/foo-input1 foo-input2/ ],
37         bar => [ qw/bar-input/ ],
38         baz => [ qw/baz-input/ ],
39 };
40
41 foreach my $db (qw/foo bar baz/) {
42         ok($parser->valid_database($db), "database $db");
43         ok($inputs->{$db}, "has known inputs");
44         diag "valid inputs = ", dump($inputs->{$db});
45         foreach my $i (@{ $inputs->{$db} }) {
46                 ok($parser->valid_database_input($db,$i), "input $i");
47         }
48 }
49 ok(! $parser->valid_database('non-existant'), "no database");
50
51 ok($parser->{source}, "source exist");
52
53 ok($parser->parse, 'parse');