-
Notifications
You must be signed in to change notification settings - Fork 11
/
config.t
84 lines (62 loc) · 3.1 KB
/
config.t
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
#!/usr/bin/env perl
use strict;
use lib qw(../lib lib ../t t);
use TestUtil;
use Test::More tests => 50;
use Test::Exception;
my ($parser);
#testing load
require_ok( 'Workflow::Config' );
#testing bad config language,SCAML it is a disgrace to mark-up
dies_ok { Workflow::Config->new( 'SCAML' ) };
#testing good config language XML
ok($parser = Workflow::Config->new( 'xml' ));
ok(my @validtypes = $parser->get_valid_config_types());
is( $validtypes[0], 'action', 'Got array with valid types and action is first.');
isa_ok($parser, 'Workflow::Config');
my %config_xml = (
'workflow' => ['workflow.xml', 'workflow_type.xml'],
'action' => ['workflow_action.xml', 'workflow_action_type.xml'],
'condition' => ['workflow_condition.xml', 'workflow_condition_type.xml'],
'validator' => ['workflow_validator.xml'],
'persister' => ['workflow_persister.xml'],
);
for my $type ( sort keys %config_xml ){
for my $source ( @{$config_xml{$type}} ){
my @config = $parser->parse( $type, $source );
ok( $config[0], "Parsed a config from $source for $type.");
is( (ref $config[0]), 'HASH', 'Got a hashref.');
}
}
$parser = Workflow::Config->new( 'xml' );
ok($parser->parse( 'workflow', 'workflow.xml', 'workflow_type.xml', 'workflow_action.xml', 'workflow_action_type.xml', 'workflow_condition.xml', 'workflow_condition_type.xml', 'workflow_validator.xml' ));
#testing good config language Perl
ok($parser = Workflow::Config->new( 'perl' ));
isa_ok($parser, 'Workflow::Config');
dies_ok { $parser->parse( 'workflow', 'workflow_errorprone.perl' ) };
dies_ok { $parser->parse( 'workflow', 'no_such_file.perl' ) };
dies_ok { $parser->parse( '123_NOSUCHTYPE', 'workflow_errorprone.perl' ) };
dies_ok { Workflow::Config->parse() };
my @config = $parser->parse( 'workflow' );
is(scalar(@config), 0, 'forgotten file, asserting length of array returned');
my %config_perl = (
'workflow' => ['workflow.perl', 'workflow_type.perl', 'workflow_type_alternate_initial.perl'],
'action' => ['workflow_action.perl'],
'condition' => ['workflow_condition.perl', 'workflow_condition_type.perl'],
'validator' => ['workflow_validator.perl'],
'persister' => ['workflow_persister.perl'],
);
for my $type ( sort keys %config_perl ){
for my $source ( @{$config_perl{$type}} ){
my @config = $parser->parse( $type, $source );
ok( $config[0], "Parsed a config from $source for $type.");
is( (ref $config[0]), 'HASH', 'Got a hashref.');
}
}
$parser = Workflow::Config->new( 'perl' );
ok($parser->parse( 'workflow', 'workflow.perl', 'workflow_action.perl', 'workflow_condition.perl', 'workflow_validator.perl' ));
#testing class method parse_all_files
my @array = Workflow::Config->parse_all_files();
is(scalar @array, 0, 'asserting return value');
dies_ok { Workflow::Config->parse_all_files( '123_NOSUCHTYPE', 'workflow_condition.prl' ) };
ok(Workflow::Config->parse_all_files( 'workflow', 'workflow_condition.perl', 'workflow_validator.perl' ));