diff options
author | Rafael Garcia-Suarez <rgarciasuarez@mandriva.org> | 2004-06-24 01:41:00 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@mandriva.org> | 2004-06-24 01:41:00 +0000 |
commit | cb09736fef2b456d9e0fa0efd886339d26a451bd (patch) | |
tree | 774461b1a211caa31b2bcd3b85da81d1ec4eae5a | |
parent | c13069d9cf136a8f3ae26e9919b278c7414a0086 (diff) | |
download | urpmi-cb09736fef2b456d9e0fa0efd886339d26a451bd.tar urpmi-cb09736fef2b456d9e0fa0efd886339d26a451bd.tar.gz urpmi-cb09736fef2b456d9e0fa0efd886339d26a451bd.tar.bz2 urpmi-cb09736fef2b456d9e0fa0efd886339d26a451bd.tar.xz urpmi-cb09736fef2b456d9e0fa0efd886339d26a451bd.zip |
Tests and fixes for the urpmi.cfg parser
-rw-r--r-- | t/cfg.t | 48 | ||||
-rw-r--r-- | urpm/cfg.pm | 15 |
2 files changed, 59 insertions, 4 deletions
diff --git a/t/cfg.t b/t/cfg.t new file mode 100644 index 00000000..6845b890 --- /dev/null +++ b/t/cfg.t @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +use Test::More tests => 4; +use MDK::Common; + +BEGIN { use_ok 'urpm::cfg' } + +my $file = 'testurpmi.cfg'; +open my $f, '>', $file or die $!; +print $f (my $cfgtext = <<URPMICFG); +{ + downloader: wget + fuzzy: no + verify-rpm: 0 +} + +update\\ 1 http://foo/bar/ { + compress: 1 + fuzzy: 1 + keep: yes + update + verify-rpm: yes +} + +update_2 ftp://foo/bar/ { + hdlist: hdlist.update2.cz + ignore + priority-upgrade: kernel + synthesis + with_hdlist: hdlist.update2.cz +} + +URPMICFG +close $f; + +my $config = urpm::cfg::load_config($file); +ok( ref $config, 'config loaded' ); + +ok( urpm::cfg::dump_config($file.2, $config), 'config written' ); + +$cfgtext =~ s/\byes\b/1/g; +$cfgtext =~ s/\bno\b/0/g; +my $cfgtext2 = cat_($file.2); +$cfgtext2 =~ s/# generated.*\n//; +is( $cfgtext, $cfgtext2, 'config is the same' ) + or system qw( diff -u ), $file, $file.2; + +END { unlink $file, $file.2 } diff --git a/urpm/cfg.pm b/urpm/cfg.pm index 0d9238d2..2b50c6f9 100644 --- a/urpm/cfg.pm +++ b/urpm/cfg.pm @@ -104,8 +104,9 @@ sub load_config ($) { |auto |resume)(?:\s*:\s*(.*))?$/x ) { - my $yes = !$no; - $config{$medium}{$k} = $v =~ /^(yes|on|1|)$/i ? $yes : !$yes; + my $yes = $no ? 0 : 1; + $no = $yes ? 0 : 1; + $config{$medium}{$k} = $v =~ /^(yes|on|1|)$/i ? $yes : $no; next; } #- obsolete @@ -129,8 +130,12 @@ sub dump_config ($$) { }; print $f "# generated ".(scalar localtime)."\n"; for my $m (@media) { - print $f quotespace($m), ' ', quotespace($config->{$m}{url}), " {\n"; - for (grep { $_ ne 'url' } keys %{$config->{$m}}) { + if ($m) { + print $f quotespace($m), ' ', quotespace($config->{$m}{url}), " {\n"; + } else { + print $f "{\n"; + } + for (sort grep { $_ ne 'url' } keys %{$config->{$m}}) { if (/^(update|ignore|synthesis|virtual)$/) { print $f " $_\n"; } else { @@ -143,6 +148,8 @@ sub dump_config ($$) { return 1; } +1; + __END__ =back |