40d25648a939d1f40a6902b4254e6fa364f7a209
[platform/upstream/make.git] / tests / scripts / options / symlinks
1 #                                                                    -*-perl-*-
2
3 $description = "Test the -L option.";
4
5 $details = "Verify that symlink handling with and without -L works properly.";
6
7 # Only run these tests if the system sypports symlinks
8
9 # Apparently the Windows port of Perl reports that it does support symlinks
10 # (in that the symlink() function doesn't fail) but it really doesn't, so
11 # check for it explicitly.
12
13 if ($port_type eq 'W32' || !( eval { symlink("",""); 1 })) {
14   # This test is N/A 
15   -1;
16 } else {
17
18   # Set up a symlink sym -> dep
19   # We'll make both dep and targ older than sym
20   $pwd =~ m%/([^/]+)$%;
21   $dirnm = $1;
22   &utouch(-10, 'dep');
23   &utouch(-5, 'targ');
24   symlink("../$dirnm/dep", 'sym');
25
26   # Without -L, nothing should happen
27   # With -L, it should update targ
28   run_make_test('targ: sym ; @echo make $@ from $<', '',
29                 "#MAKE#: `targ' is up to date.");
30   run_make_test(undef, '-L', "make targ from sym");
31
32   # Now update dep; in all cases targ should be out of date.
33   &touch('dep');
34   run_make_test(undef, '', "make targ from sym");
35   run_make_test(undef, '-L', "make targ from sym");
36
37   # Now update targ; in all cases targ should be up to date.
38   &touch('targ');
39   run_make_test(undef, '', "#MAKE#: `targ' is up to date.");
40   run_make_test(undef, '-L', "#MAKE#: `targ' is up to date.");
41
42   # Add in a new link between sym and dep.  Be sure it's newer than targ.
43   sleep(1);
44   rename('dep', 'dep1');
45   symlink('dep1', 'dep');
46
47   # Without -L, nothing should happen
48   # With -L, it should update targ
49   run_make_test(undef, '', "#MAKE#: `targ' is up to date.");
50   run_make_test(undef, '-L', "make targ from sym");
51
52   rmfiles('targ', 'dep', 'sym', 'dep1');
53
54   # Check handling when symlinks point to non-existent files.  Without -L we
55   # should get an error: with -L we should use the timestamp of the symlink.
56
57   symlink("../$dirname/dep", 'sym');
58   run_make_test('targ: sym ; @echo make $@ from $<', '',
59                 "#MAKE#: *** No rule to make target `sym', needed by `targ'.  Stop.", 512);
60
61   run_make_test('targ: sym ; @echo make $@ from $<', '-L',
62                 'make targ from sym');
63
64
65   rmfiles('targ', 'sym');
66
67   1;
68 }