~ubuntu-branches/ubuntu/saucy/padre/saucy-proposed

« back to all changes in this revision

Viewing changes to t/04_config.t

  • Committer: Package Import Robot
  • Author(s): Dominique Dumont, gregor herrmann, Dominique Dumont
  • Date: 2012-01-04 12:04:20 UTC
  • mfrom: (1.3.3)
  • Revision ID: package-import@ubuntu.com-20120104120420-i5oybqwf91m1d3il
Tags: 0.92.ds1-1
[ gregor herrmann ]
* Remove debian/source/local-options; abort-on-upstream-changes
  and unapply-patches are default in dpkg-source since 1.16.1.
* Swap order of alternative (build) dependencies after the perl
  5.14 transition.

[ Dominique Dumont ]
* Imported Upstream version 0.92.ds1
* removed fix-spelling patch (applied upstream)
* lintian-override: use wildcard to avoid listing a gazillion files
* updated size of some 'not-real-man-page' entries
* rules: remove dekstop cruft (replaced by a file provided in debian
  directory)
* control: removed Breaks statement. Add /me to uploaders. Updated
  dependencies
* rules: make sure that non-DFSG file (i.e. the cute butterfly, sigh)
  is not distributed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
use strict;
 
4
use warnings;
 
5
use constant NUMBER_OF_CONFIG_OPTIONS => 145;
 
6
 
 
7
# Move of Debug to Run Menu
 
8
use Test::More tests => NUMBER_OF_CONFIG_OPTIONS * 2 + 28;
 
9
use Test::NoWarnings;
 
10
use File::Spec::Functions ':ALL';
 
11
use File::Temp ();
 
12
 
 
13
BEGIN {
 
14
        $ENV{PADRE_HOME} = File::Temp::tempdir( CLEANUP => 1 );
 
15
}
 
16
use Padre::Constant ();
 
17
use Padre::Config   ();
 
18
 
 
19
# Loading the configuration subsystem should NOT result in loading Wx
 
20
is( $Wx::VERSION, undef, 'Wx was not loaded during config load' );
 
21
 
 
22
# Create the empty config file
 
23
my $empty = Padre::Constant::CONFIG_HUMAN;
 
24
open( my $FILE, '>', $empty ) or die "Failed to open $empty";
 
25
print $FILE "--- {}\n";
 
26
close($FILE);
 
27
 
 
28
# Load the config
 
29
my $config = Padre::Config->read;
 
30
isa_ok( $config,        'Padre::Config' );
 
31
isa_ok( $config->host,  'Padre::Config::Host' );
 
32
isa_ok( $config->human, 'Padre::Config::Human' );
 
33
is( $config->project,        undef, '->project is undef' );
 
34
is( $config->host->version,  undef, '->host->version is undef' );
 
35
is( $config->human->version, undef, '->human->version is undef' );
 
36
 
 
37
# Loading the config file should not result in Wx loading
 
38
is( $Wx::VERSION, undef, 'Wx was not loaded during config read' );
 
39
 
 
40
# Check that the defaults work
 
41
my @names =
 
42
        sort { length($a) <=> length($b) or $a cmp $b } keys %Padre::Config::SETTING;
 
43
is( scalar(@names), NUMBER_OF_CONFIG_OPTIONS, 'Expected number of config options' );
 
44
foreach my $name (@names) {
 
45
        ok( defined( $config->$name() ), "->$name is defined" );
 
46
        is( $config->$name(),
 
47
                $Padre::Config::DEFAULT{$name},
 
48
                "->$name defaults ok",
 
49
        );
 
50
}
 
51
 
 
52
# The config version number is a requirement for every config and
 
53
# the only key which is allowed to live in an empty config.
 
54
my %test_config = ( Version => $Padre::Config::VERSION );
 
55
 
 
56
# ... and that they don't leave a permanent state.
 
57
is_deeply(
 
58
        +{ %{ $config->human } }, \%test_config,
 
59
        'Defaults do not leave permanent state (human)',
 
60
);
 
61
is_deeply(
 
62
        +{ %{ $config->host } }, \%test_config,
 
63
        'Defaults do not leave permanent state (host)',
 
64
);
 
65
 
 
66
# Store the config again
 
67
ok( $config->write, '->write ok' );
 
68
 
 
69
# Saving the config file should not result in Wx loading
 
70
is( $Wx::VERSION, undef, 'Wx was not loaded during config write' );
 
71
 
 
72
# Check that we have a version for the parts now
 
73
is( $config->host->version,  1, '->host->version is set' );
 
74
is( $config->human->version, 1, '->human->version is set' );
 
75
 
 
76
# Set values on both the human and host sides
 
77
ok( $config->set( main_lockinterface => 0 ),
 
78
        '->set(human) ok',
 
79
);
 
80
ok( $config->set( main_maximized => 1 ),
 
81
        '->set(host) ok',
 
82
);
 
83
 
 
84
# Save the config again
 
85
ok( $config->write, '->write ok' );
 
86
 
 
87
# Read in a fresh version of the config
 
88
my $config2 = Padre::Config->read;
 
89
 
 
90
# Confirm the config is round-trip safe
 
91
is_deeply( $config2, $config, 'Config round-trips ok' );
 
92
 
 
93
# No configuration operations require loading Wx
 
94
is( $Wx::VERSION, undef, 'Wx is never loaded during config operations' );
 
95
 
 
96
# Check clone support
 
97
my $copy = $config->clone;
 
98
is_deeply( $copy, $config, '->clone ok' );
 
99
 
 
100
 
 
101
 
 
102
 
 
103
######################################################################
 
104
# Check configuration values not in the relevant option list
 
105
 
 
106
SCOPE: {
 
107
        my $bad = Padre::Config->new(
 
108
                Padre::Config::Host->_new(
 
109
                        {
 
110
 
 
111
                                # Invalid option
 
112
                                lang_perl5_lexer => 'Bad::Class::Does::Not::Exist',
 
113
                        }
 
114
                ),
 
115
                bless {
 
116
                        revision => Padre::Config::Human->VERSION,
 
117
 
 
118
                        # Valid option
 
119
                        startup_files => 'new',
 
120
 
 
121
                        # Invalid key
 
122
                        nonexistant => 'nonexistant',
 
123
                },
 
124
                'Padre::Config::Human'
 
125
        );
 
126
        isa_ok( $bad,        'Padre::Config' );
 
127
        isa_ok( $bad->host,  'Padre::Config::Host' );
 
128
        isa_ok( $bad->human, 'Padre::Config::Human' );
 
129
        is( $bad->startup_files, 'new', '->startup_files ok' );
 
130
 
 
131
        # Configuration should ignore a value not in configuration and go
 
132
        # with the default instead.
 
133
        is( $bad->default('lang_perl5_lexer'), 'stc', 'Default Perl 5 lexer ok' );
 
134
        is( $bad->lang_perl5_lexer,            'stc', '->lang_perl5_lexer matches default' );
 
135
}