1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!/usr/bin/perl
use strict;
use lib '.', 't';
use helper;
use Expect;
use urpm::util;
use Test::More 'no_plan';
need_root_and_prepare();
my $medium_name = 'prefer';
urpmi_addmedia("$medium_name $::pwd/media/$medium_name");
urpmi("--auto --prefer b a");
check_installed_and_remove('a', 'b');
urpmi("--auto --prefer c a");
check_installed_and_remove('a', 'c');
test('/foo/', 'foo');
test('a,a_foo', '^(a|a_foo)$');
sub test {
my ($prefer, $regexp) = @_;
my $options = "--prefer '$prefer' a";
my @expected = (
[ 'What is your choice', "\n" ],
[ 'Proceed with the installation of the 2 packages?', "\n" ],
);
if (0) {
#- try it interactively for debugging
system_(urpm_cmd('urpmi', '-d') . " $options");
return;
}
my $cmd = urpmi_cmd() . " $options";
print "# $cmd\n";
my $expect = Expect->spawn($cmd);
my $choices;
foreach (@expected) {
my ($msg, $to_send) = @$_;
my $ok = $expect->expect(2, # timeout in seconds
[ $msg => sub { $choices ||= $expect->before; $expect->send($to_send); } ]);
print "$to_send";
ok($ok, qq(expecting "$msg"));
$ok or return;
}
my @choices = grep { s/^\s*\d+- (.*?)-.*?:.*/$1/ } split("\n", $choices);
is(int(@choices), 4, "4 choices in $choices");
my $other = '';
foreach (@choices) {
if (/$regexp/) {
ok(!$other, "line $_ must be before $other line");
} else {
$other = $_;
}
}
$expect->expect(2, [ 'eof' => sub {} ]);
$expect->soft_close;
is($expect->exitstatus, 0, $cmd);
check_installed_and_remove('a', $choices[0]);
}
|