Преглед изворни кода

update-alternatives: complete rewrite

Full rewrite of update-alternatives. It was badly needed so that
we can actually understand its behaviour and implement new features
on top of it. This commit doesn't add any new feature but still improves
the behaviour of --config: it has a nicer output (with choices sorted
alphabetically, closes: #437060) and it accepts a path as well as the
index of the choice (to make it easier to write non regression tests for
this action). The test-suite is adjusted accordingly.
Raphael Hertzog пре 17 година
родитељ
комит
b51a311246
4 измењених фајлова са 789 додато и 678 уклоњено
  1. 9 0
      ChangeLog
  2. 3 0
      debian/changelog
  3. 10 8
      scripts/t/900_update_alternatives.t
  4. 767 670
      scripts/update-alternatives.pl

+ 9 - 0
ChangeLog

@@ -1,3 +1,12 @@
+2009-02-22  Raphael Hertzog  <hertzog@debian.org>
+
+	* scripts/update-alternatives.pl: Rewrite it entirely in a more
+	object-oriented way. The only behaviour changes concern --config:
+	the output is nicer and sorted, it accets a path as well as the
+	index of the choice.
+	* scripts/t/900_update_alternatives.t: Test suite adjusted to the
+	--config change.
+
 2009-02-22  Raphael Hertzog  <hertzog@debian.org>
 
 	* scripts/dpkg-gencontrol.pl, scripts/dpkg-gensymbols.pl: Reset

+ 3 - 0
debian/changelog

@@ -153,6 +153,9 @@ dpkg (1.15.0) UNRELEASED; urgency=low
   * Reset umask to 0022 in dpkg-gencontrol and dpkg-gensymbols to ensure that
     files created in the DEBIAN directory have sane permissions.
     Closes: #516481
+  * Rewrite update-alternatives (so that we can understand it again) and
+    implement new features on top of it:
+    - the --config output is now sorted. Closes: #437060
 
   [ Pierre Habouzit ]
   * Add a --query option to update-alternatives. Closes: #336091, #441904

+ 10 - 8
scripts/t/900_update_alternatives.t

@@ -99,8 +99,11 @@ sub set_choice {
 sub config_choice {
     my ($id, %opts) = @_;
     my ($input,	$output) = ("", "");
-    if (defined $id) {
-	$input = $id + 1;
+    if ($id >= 0) {
+	my $alt = $choices[$id];
+	$input = $alt->{path};
+    } else {
+	$input = "0";
     }
     $input .= "\n";
     $opts{from_string} = \$input;
@@ -162,7 +165,8 @@ sub check_choice {
     if (defined $id) {
 	# Check status
 	call_ua([ "--query", "$main_name" ], to_string => \$output);
-	ok(($output =~ /^Status: $mode$/im), "$msg: status is not $mode.");
+	$output =~ /^Status: (.*)$/im;
+	is($1, $mode, "$msg: status is not $mode.");
 	# Check links
 	my $alt = $choices[$id];
 	check_link("$altdir/$main_name", $alt->{path}, $msg);
@@ -221,11 +225,9 @@ ok(unlink("$altdir/generic-test"), "failed removal");
 install_choice(1);
 check_choice(0, "auto", "<altdir>/generic-test lost, back to auto");
 # test --config
-# TODO: for now order of choices in config depends on order of --install calls
-# it's not very "test-friendly"
-config_choice(1);
-check_choice(0, "manual", "config to best but manual");
 config_choice(0);
+check_choice(0, "manual", "config to best but manual");
+config_choice(1);
 check_choice(1, "manual", "config to manual");
 config_choice(-1);
 check_choice(0, "auto", "config auto");
@@ -263,4 +265,4 @@ system("echo garbage > $admindir/generic-test");
 install_choice(0, error_to_file => "/dev/null", expect_failure => 1);
 
 # TODO: add checks for invalid values of parameters, add checks for
-# usage of links as both master and slave
+# usage of links as both master and slave, install in non-existing dir

Разлика између датотеке није приказан због своје велике величине
+ 767 - 670
scripts/update-alternatives.pl