source: MondoRescue/branches/3.3/MondoRescue/t/01-read-all-link.t@ 3795

Last change on this file since 3795 was 3795, checked in by Bruno Cornec, 3 months ago

Untag v3.3.0 never really published in the past - will start from here

  • Property svn:executable set to *
File size: 3.0 KB
Line 
1#!/usr/bin/perl -w
2use File::Temp qw/ tempdir /;
3use File::Copy;
4use MondoRescue::File;
5use strict;
6
7# Create the structure for the tests
8my $bd = tempdir(
9 #CLEANUP => 1
10 );
11
12# Create directory structure
13chdir $bd || die "Unable to chdir to $bd";
14mkdir "usr",0755 || die "$!";
15mkdir "usr/bin",0755 || die "$!";
16mkdir "usr/lib",0755 || die "$!";
17mkdir "var",0755 || die "$!";
18mkdir "var/spool",0755 || die "$!";
19mkdir "var/spool/mail",0755 || die "$!";
20mkdir "var/lib",0755 || die "$!";
21
22# Copy some files in it
23copy "/usr/bin/perl","usr/bin" || die "$!";
24chmod 0755,"usr/bin/perl";
25foreach my $f (<"/lib/libc.so.[0-9]*">) {
26 copy "$f","usr/lib" || die "$!";
27}
28
29# Create links on files
30chdir "$bd/usr/bin" || die "$!";
31symlink "perl","toto" || die "$!"; # in same dir
32chdir "$bd/var/spool/" || die "$!";
33symlink "../../usr/bin/perl","toto" || die "$!"; # in another dir relatively
34chdir "$bd/var" || die "$!";
35symlink "$bd/usr/bin/perl","truc" || die "$!"; # in another dir absolutely
36
37# Create links on dirs
38chdir "$bd/var/spool" || die "$!";
39symlink "mail","titi" || die "$!"; # in same dir
40chdir "$bd/var/lib" || die "$!";
41symlink "../spool/mail","titi" || die "$!"; # in another dir relatively
42chdir "$bd/var" || die "$!";
43symlink "$bd/var/spool/mail","tutu" || die "$!"; # in another dir absolutely
44
45print "Temporary dir: $bd\n";
46
47# Now try to see if we get the right links
48my $h = mr_file_read_all_link(
49 "$bd/usr/bin/toto",
50 "$bd/var/spool/toto",
51 "$bd/var/truc",
52 "$bd/var/spool/titi",
53 "$bd/var/lib/titi",
54 "$bd/var/tutu"
55 );
56
57eval {
58 require Test;
59 Test->import();
60};
61if ($@) {
62 require Test::Simple;
63 Test::Simple->import();
64}
65plan(tests => 12);
66
67 # Got, expected, comment
68myis($h->{"$bd/usr/bin/toto"}->{"$bd/usr/bin/toto"}, 1, "File link in same dir to itself");
69myis($h->{"$bd/usr/bin/toto"}->{"$bd/usr/bin/perl"}, 1, "File link in same dir to link");
70myis($h->{"$bd/var/truc"}->{"$bd/var/truc"}, 1, "File link in another absolute dir to itself");
71myis($h->{"$bd/var/truc"}->{"$bd/usr/bin/perl"}, 1, "File link in another absolute dir to link");
72myis($h->{"$bd/var/spool/toto"}->{"$bd/var/spool/toto"}, 1, "File link in another relative dir to itself");
73myis($h->{"$bd/var/spool/toto"}->{"$bd/usr/bin/perl"}, 1, "File link in another relative dir to link");
74myis($h->{"$bd/var/spool/titi"}->{"$bd/var/spool/titi"}, 1, "Directory link in same dir to itself");
75myis($h->{"$bd/var/spool/titi"}->{"$bd/var/spool/mail"}, 1, "Directory link in same dir to link");
76myis($h->{"$bd/var/lib/titi"}->{"$bd/var/lib/titi"}, 1, "Directory link in another relative dir to itself");
77myis($h->{"$bd/var/lib/titi"}->{"$bd/var/spool/mail"}, 1, "Directory link in another relative dir to link");
78myis($h->{"$bd/var/tutu"}->{"$bd/var/tutu"}, 1, "Directory link in another absolute dir to itself");
79myis($h->{"$bd/var/tutu"}->{"$bd/var/spool/mail"}, 1, "Directory link in another absolute dir to link");
80chdir "/tmp";
81exit(0);
82
83sub myis {
84
85my $p1 = shift;
86my $p2 = shift;
87my $p3 = shift;
88print "# test $p3\n";
89return(ok($p1,$p2));
90}
Note: See TracBrowser for help on using the repository browser.