Get error messages in the C locale for comparision with make output.
[make.git] / tests / scripts / functions / file
blob9a4cd024a1d5940288d7387549d2c0283f67cf8f
1 #                                                                    -*-perl-*-
3 $description = 'Test the $(file ...) function.';
5 # Test > and >>
6 run_make_test(q!
7 define A
10 endef
11 B = c d
12 $(file >file.out,$(A))
13 $(foreach L,$(B),$(file >>     file.out,$L))
14 x:;@echo hi; cat file.out
16               '', "hi\na\nb\nc\nd");
18 unlink('file.out');
20 # Test >> to a non-existent file
21 run_make_test(q!
22 define A
25 endef
26 $(file     >>     file.out,$(A))
27 x:;@cat file.out
29               '', "a\nb");
31 unlink('file.out');
33 # Test > to a read-only file
34 touch('file.out');
35 chmod(0444, 'file.out');
37 # Find the error that will be printed
38 # This seems complicated, but we need the message from the C locale
39 my $loc = undef;
40 if ($has_POSIX) {
41     $loc = POSIX::setlocale(POSIX::LC_MESSAGES);
42     POSIX::setlocale(POSIX::LC_MESSAGES, 'C');
44 my $e;
45 open(my $F, '>', 'file.out') and die "Opened read-only file!\n";
46 $e = "$!";
47 $loc and POSIX::setlocale(POSIX::LC_MESSAGES, $loc);
49 run_make_test(q!
50 define A
53 endef
54 $(file     >     file.out,$(A))
55 x:;@cat file.out
57               '', "#MAKEFILE#:6: *** open: file.out: $e.  Stop.",
58               512);
60 unlink('file.out');
62 # Use variables for operator and filename
63 run_make_test(q!
64 define A
67 endef
68 OP = >
69 FN = file.out
70 $(file     $(OP)     $(FN),$(A))
71 x:;@cat file.out
73               '', "a\nb");
75 unlink('file.out');
77 # Don't add newlines if one already exists
78 run_make_test(q!
79 define A
83 endef
84 $(file >file.out,$(A))
85 x:;@cat file.out
87               '', "a\nb");
89 unlink('file.out');
91 # Empty text
92 run_make_test(q!
93 $(file >file.out,)
94 $(file >>file.out,)
95 x:;@cat file.out
97               '', "\n\n");
99 unlink('file.out');