summaryrefslogtreecommitdiffstats
path: root/t/helper.pm
blob: 7c8d29b69f1bc20069489d01872f8cad51e8a1a2 (plain)
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
73
74
package helper;

use Test::More;
use base 'Exporter';
our @EXPORT = qw(need_root_and_prepare 
		 start_httpd httpd_port
		 urpmi_addmedia urpmi_removemedia
		 urpmi urpme
		 system_
	    );

my $using_root;
sub need_root_and_prepare() {
    if ($< != 0) {
	#- can't test
	pass();
	exit(0);
    }
    -d 'media' or die "02create_pkgs.t not done\n";

    system('rm -rf root');
    isnt(-d 'root', "test root dir can not be removed $!");
    mkdir 'root';
    $using_root = 1;
}

my $server_pid;
sub httpd_port { 6969 }
sub start_httpd() {
    $server_pid = fork();
    if ($server_pid == 0) {
	mkdir 'tmp';
	exec './simple-httpd', $pwd, "$pwd/tmp", httpd_port();
	exit 1;
    }
    'http://localhost:' . httpd_port();
}

chdir 't' if -d 't';

chomp($::pwd = `pwd`);
my $urpmi_debug_opt = '-q';
#$urpmi_debug_opt = '-v --debug';

sub urpmi_addmedia {
    my ($para) = @_;
    system_("perl -I.. ../urpmi.addmedia $urpmi_debug_opt --urpmi-root $::pwd/root $para");
}
sub urpmi_removemedia {
    my ($para) = @_;
    system_("perl -I.. ../urpmi.removemedia $urpmi_debug_opt --urpmi-root $::pwd/root $para");
}
sub urpmi {
    my ($para) = @_;
    system_("perl -I.. ../urpmi $urpmi_debug_opt --urpmi-root $::pwd/root --ignoresize $para");
}
sub urpme {
    my ($para) = @_;
    system_("perl -I.. ../urpme --urpmi-root $::pwd/root $para");
}

sub system_ {
    my ($cmd) = @_;
    system($cmd);
    ok($? == 0, $cmd);
}

END { 
    $using_root and system('rm -rf root');
    $server_pid and kill(9, $server_pid);
    system('rm -rf tmp');
}

1;