5
use constant NUMBER_OF_CONFIG_OPTIONS => 135;
7
# Move of Debug to Run Menu
8
use Test::More tests => NUMBER_OF_CONFIG_OPTIONS * 2 + 28;
10
use File::Spec::Functions ':ALL';
14
$ENV{PADRE_HOME} = File::Temp::tempdir( CLEANUP => 1 );
16
use Padre::Constant ();
19
# Loading the configuration subsystem should NOT result in loading Wx
20
is( $Wx::VERSION, undef, 'Wx was not loaded during config load' );
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";
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' );
37
# Loading the config file should not result in Wx loading
38
is( $Wx::VERSION, undef, 'Wx was not loaded during config read' );
40
# Check that the defaults work
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" );
47
$Padre::Config::DEFAULT{$name},
48
"->$name defaults ok",
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 );
56
# ... and that they don't leave a permanent state.
58
+{ %{ $config->human } }, \%test_config,
59
'Defaults do not leave permanent state (human)',
62
+{ %{ $config->host } }, \%test_config,
63
'Defaults do not leave permanent state (host)',
66
# Store the config again
67
ok( $config->write, '->write ok' );
69
# Saving the config file should not result in Wx loading
70
is( $Wx::VERSION, undef, 'Wx was not loaded during config write' );
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' );
76
# Set values on both the human and host sides
77
ok( $config->set( main_lockinterface => 0 ),
80
ok( $config->set( main_maximized => 1 ),
84
# Save the config again
85
ok( $config->write, '->write ok' );
87
# Read in a fresh version of the config
88
my $config2 = Padre::Config->read;
90
# Confirm the config is round-trip safe
91
is_deeply( $config2, $config, 'Config round-trips ok' );
93
# No configuration operations require loading Wx
94
is( $Wx::VERSION, undef, 'Wx is never loaded during config operations' );
97
my $copy = $config->clone;
98
is_deeply( $copy, $config, '->clone ok' );
103
######################################################################
104
# Check configuration values not in the relevant option list
107
my $bad = Padre::Config->new(
108
Padre::Config::Host->_new(
112
lang_perl5_lexer => 'Bad::Class::Does::Not::Exist',
116
revision => Padre::Config::Human->VERSION,
119
startup_files => 'new',
122
nonexistant => 'nonexistant',
124
'Padre::Config::Human'
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' );
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' );