File: 20_trait.t

package info (click to toggle)
cipux 3.4.0.11-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 316 kB
  • ctags: 59
  • sloc: perl: 1,064; makefile: 13
file content (67 lines) | stat: -rw-r--r-- 1,647 bytes parent folder | download | duplicates (3)
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
use Test::More tests => 7;

BEGIN {
    use_ok('CipUX::Trait');

}
use base qw(CipUX);
use Module::Pluggable except => ['CipUX::Trait::DebianEdu'];

my $trait = CipUX::Trait->new;

my @methods = qw(init set_trait_name_register get_trait_name_register);
can_ok( $trait, @methods );
isa_ok( $trait, 'CipUX::Trait' );

# add module from the filesystem
ok( $trait->init );

# comare hash
my $class_hr = {
    'some-feature' => 'CipUX::Trait::SomeThing',
    'that-feature' => 'CipUX::Trait::ThatThing',
    'this-feature' => 'CipUX::Trait::ThisThing',
};

# add artificial traits
foreach my $c ( keys %{$class_hr} ) {
    ok(
        $trait->set_trait_name_register(
            { class => $class_hr->{$c}, name => $c }
        )
    );
}
my $trait_list_hr = {};
$trait_list_hr = $trait->get_trait_name_register;

# add offical traits here
if ( exists $trait_list_hr->{'debian-edu-configuration'} ) {
    $class_hr->{'debian-edu-configuration'} = 'CipUX::Trait::DebianEdu';
}
if ( exists $trait_list_hr->{'samba-support'} ) {
    $class_hr->{'samba-support'} = 'CipUX::Trait::Samba';
}

#use Data::Dumper;
#diag(Dumper($class_hr));
#diag(Dumper($trait_list_hr));

# postpone test untill clear how to add custom traits.
#is_deeply( $trait_list_hr, $class_hr, 'trait_name_register' );

#foreach my $trait ( sort keys %{$trait_list_hr} ) {
#    diag(" $trait: $trait_list_hr->{$trait}\n");
#}

#
my @trait = $trait->get_trait;
my $err   = 0;

foreach my $t (@trait) {
    if ( not( exists $class_hr->{$t} and defined $class_hr->{$t} ) ) {
        $err = 1;
    }
}

# postpone test untill clear how to add custom traits.
#is( $err, 0, 'get trait sub' );