source: MondoRescue/branches/3.2/MondoRescue/t/01-read-all-link.t@ 3243

Last change on this file since 3243 was 3243, checked in by Bruno Cornec, 10 years ago
  • The test function of MondoRescue is now also working for distros not having natively Test::More and avoid to depend on it
  • Property svn:executable set to *
File size: 3.1 KB
RevLine 
[3228]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";
25my $libc;
26foreach my $f (<"/lib/libc.so.[0-9]*">) {
27 copy "$f","usr/lib" || die "$!";
28 $libc = $f;
29}
30
31# Create links on files
32chdir "$bd/usr/bin" || die "$!";
33symlink "perl","toto" || die "$!"; # in same dir
34chdir "$bd/var/spool/" || die "$!";
35symlink "../../usr/bin/perl","toto" || die "$!"; # in another dir relatively
36chdir "$bd/var" || die "$!";
37symlink "$bd/usr/bin/perl","truc" || die "$!"; # in another dir absolutely
38
39# Create links on dirs
40chdir "$bd/var/spool" || die "$!";
41symlink "mail","titi" || die "$!"; # in same dir
42chdir "$bd/var/lib" || die "$!";
43symlink "../spool/mail","titi" || die "$!"; # in another dir relatively
44chdir "$bd/var" || die "$!";
45symlink "$bd/var/spool/mail","tutu" || die "$!"; # in another dir absolutely
46
47print "Temporary dir: $bd\n";
48
49# Now try to see if we get the right links
50my $h = mr_file_read_all_link(
51 "$bd/usr/bin/toto",
52 "$bd/var/spool/toto",
53 "$bd/var/truc",
54 "$bd/var/spool/titi",
55 "$bd/var/lib/titi",
56 "$bd/var/tutu"
57 );
58
[3243]59my $more = 1;
60
61eval
62{
63 require Test::More;
64 Test::More->import();
65 no_plan();
66};
67# Test::More not found so simpler test
68if ($@) {
69 require Test;
70 Test->import();
71 $more = 0;
72 plan(tests => 12);
73}
[3228]74 # Got, expected, comment
[3243]75myis(@{$h->{"$bd/usr/bin/toto"}}[0], "$bd/usr/bin/toto", "File link in same dir to itself");
76myis(@{$h->{"$bd/usr/bin/toto"}}[1], "$bd/usr/bin/perl", "File link in same dir to link");
77myis(@{$h->{"$bd/var/truc"}}[0], "$bd/var/truc", "File link in another absolute dir to itself");
78myis(@{$h->{"$bd/var/truc"}}[1], "$bd/usr/bin/perl", "File link in another absolute dir to link");
79myis(@{$h->{"$bd/var/spool/toto"}}[0], "$bd/var/spool/toto", "File link in another relative dir to itself");
80myis(@{$h->{"$bd/var/spool/toto"}}[1], "$bd/usr/bin/perl", "File link in another relative dir to link");
81myis(@{$h->{"$bd/var/spool/titi"}}[0], "$bd/var/spool/titi", "Directory link in same dir to itself");
82myis(@{$h->{"$bd/var/spool/titi"}}[1], "$bd/var/spool/mail", "Directory link in same dir to link");
83myis(@{$h->{"$bd/var/lib/titi"}}[0], "$bd/var/lib/titi", "Directory link in another relative dir to itself");
84myis(@{$h->{"$bd/var/lib/titi"}}[1], "$bd/var/spool/mail", "Directory link in another relative dir to link");
85myis(@{$h->{"$bd/var/tutu"}}[0], "$bd/var/tutu", "Directory link in another absolute dir to itself");
86myis(@{$h->{"$bd/var/tutu"}}[1], "$bd/var/spool/mail", "Directory link in another absolute dir to link");
[3228]87chdir "/tmp";
88exit(0);
[3243]89
90sub myis {
91
92if ($more eq 1) {
93 return(is(@_));
94} else {
95 my $p1 = shift;
96 my $p2 = shift;
97 my $p3 = shift;
98 print "# test $p3\n";
99 return(ok($p1,$p2));
100}
101}
102
Note: See TracBrowser for help on using the repository browser.