aboutsummaryrefslogtreecommitdiff
path: root/t/20-config.t
diff options
context:
space:
mode:
authorAndreas Guldstrand <andreas.guldstrand@gmail.com>2016-08-13 13:26:08 +0200
committerAndreas Guldstrand <andreas.guldstrand@gmail.com>2016-08-13 13:26:08 +0200
commit96ebe3dceeca539856a16968e4a8630ebc930d9d (patch)
treeb114b2953d380c4365cf06f91a366a50df011210 /t/20-config.t
parentbb4aa6f01a066bb5b35fc8aed08a0ecfa8334eb3 (diff)
downloadsbotools2-96ebe3dceeca539856a16968e4a8630ebc930d9d.tar.xz
20-config.t: test handling of comments, empty lines, and duplicate settings
Diffstat (limited to 't/20-config.t')
-rwxr-xr-xt/20-config.t51
1 files changed, 49 insertions, 2 deletions
diff --git a/t/20-config.t b/t/20-config.t
index dccc0f0..330a0c3 100755
--- a/t/20-config.t
+++ b/t/20-config.t
@@ -8,7 +8,7 @@ use FindBin '$RealBin';
use lib $RealBin;
use Test::Sbotools qw/ sboconfig /;
-plan tests => 9;
+plan tests => 17;
# 1-7: test invalid arguments
sboconfig '-c', 'invalid', { exit => 1, expected => "You have provided an invalid parameter for -c\n" };
@@ -21,7 +21,7 @@ sboconfig '-V', 'invalid', { exit => 1, expected => "You have provided an invali
# 8-9: move original dir away and run tests on the config file
SKIP: {
- skip "Only run this test under Travis CI", 2 unless $ENV{TRAVIS};
+ skip "Only run this test under Travis CI", 10 unless $ENV{TRAVIS};
my $dir = '/etc/sbotools';
rename $dir, "$dir.moved";
@@ -35,6 +35,53 @@ SKIP: {
ok(-d $dir, "$dir created correctly.");
unlink "$dir/sbotools.conf";
+
+ # set up sbotools.conf
+ open my $fh, '>', "$dir/sbotools.conf" or do {
+ my $err = $!;
+ fail "Writing sbotools.conf";
+ diag "Could not open $dir/sbotools.conf for writing: $err";
+ skip 7, "Could not write sbotools.conf";
+ goto CLEANUP;
+ };
+
+ say $fh "#comment=foo";
+ say $fh "#comment=bar";
+ say $fh "";
+ say $fh "";
+ say $fh "FOO=FOO";
+ say $fh "FOO=BAR";
+ say $fh "";
+ say $fh "SLACKWARE_VERSION=14.0";
+ say $fh "SLACKWARE_VERSION=14.2";
+
+ close $fh;
+
+ sboconfig '-V', '14.1', { test => 0 };
+
+ open my $cfh, '<', "$dir/sbotools.conf" or do {
+ my $err = $!;
+ fail "Reading sbotools.conf";
+ diag "Could not open $dir/sbotools.conf for reading: $err";
+ skip 7, "Could not read sbotools.conf";
+ goto CLEANUP;
+ };
+
+ chomp(my @lines = readline $cfh);
+
+ close $cfh;
+
+ is($lines[0], "#comment=foo", "First comment preserved.");
+ is($lines[1], "#comment=bar", "Second comment preserved.");
+ is($lines[2], "", "First empty line preserved.");
+ is($lines[3], "", "Second empty line preserved.");
+ is($lines[4], "FOO=FOO", "First setting preserved.");
+ is($lines[5], "", "Second setting correctly collapsed. Third empty line preserved.");
+ is($lines[6], "SLACKWARE_VERSION=14.1", "SLACKWARE_VERSION correctly set.");
+ is($lines[7], undef, "SLACKWARE_VERSION correctly collapsed.");
+
+ CLEANUP:
+ unlink "$dir/sbotools.conf";
rmdir $dir;
rename "$dir.moved", $dir;
}