VirtualBox

source: kBuild/trunk/src/kmk/tests/scripts/functions/file@ 3140

Last change on this file since 3140 was 3140, checked in by bird, 7 years ago

kmk: Merged in changes from GNU make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6 / https://git.savannah.gnu.org/git/make.git).

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1# -*-perl-*-
2
3$description = 'Test the $(file ...) function.';
4
5# Test > and >>
6run_make_test(q!
7define A
8a
9b
10endef
11B = c d
12$(file >file.out,$(A))
13$(foreach L,$(B),$(file >> file.out,$L))
14x:;@echo hi; cat file.out
15!,
16 '', "hi\na\nb\nc\nd");
17
18unlink('file.out');
19
20# Test >> to a non-existent file
21run_make_test(q!
22define A
23a
24b
25endef
26$(file >> file.out,$(A))
27x:;@cat file.out
28!,
29 '', "a\nb");
30
31unlink('file.out');
32
33# Test > with no content
34run_make_test(q!
35$(file >4touch)
36.PHONY:x
37x:;@cat 4touch
38!,
39 '', '');
40
41# Test >> with no content
42run_make_test(q!
43$(file >>4touch)
44.PHONY:x
45x:;@cat 4touch
46!,
47 '', '');
48unlink('4touch');
49
50# Test > to a read-only file
51touch('file.out');
52chmod(0444, 'file.out');
53
54# Find the error that will be printed
55# This seems complicated, but we need the message from the C locale
56my $loc = undef;
57if ($has_POSIX) {
58 $loc = POSIX::setlocale(POSIX::LC_MESSAGES);
59 POSIX::setlocale(POSIX::LC_MESSAGES, 'C');
60}
61my $e;
62open(my $F, '>', 'file.out') and die "Opened read-only file!\n";
63$e = "$!";
64$loc and POSIX::setlocale(POSIX::LC_MESSAGES, $loc);
65
66run_make_test(q!
67define A
68a
69b
70endef
71$(file > file.out,$(A))
72x:;@cat file.out
73!,
74 '', "#MAKEFILE#:6: *** open: file.out: $e. Stop.",
75 512);
76
77unlink('file.out');
78
79# Use variables for operator and filename
80run_make_test(q!
81define A
82a
83b
84endef
85OP = >
86FN = file.out
87$(file $(OP) $(FN),$(A))
88x:;@cat file.out
89!,
90 '', "a\nb");
91
92unlink('file.out');
93
94# Don't add newlines if one already exists
95run_make_test(q!
96define A
97a
98b
99
100endef
101$(file >file.out,$(A))
102x:;@cat file.out
103!,
104 '', "a\nb");
105
106unlink('file.out');
107
108# Empty text
109run_make_test(q!
110$(file >file.out,)
111$(file >>file.out,)
112x:;@cat file.out
113!,
114 '', "\n\n");
115
116unlink('file.out');
117
118# Reading files
119run_make_test(q!
120$(file >file.out,A = foo)
121X1 := $(file <file.out)
122$(file >>file.out,B = bar)
123$(eval $(file <file.out))
124
125x:;@echo '$(X1)'; echo '$(A)'; echo '$(B)'
126!,
127 '', "A = foo\nfoo\nbar\n");
128
129unlink('file.out');
130
131# Reading from non-existent file
132run_make_test(q!
133X1 := $(file <file.out)
134x:;@echo '$(X1)';
135!,
136 '', "\n");
137
138# Extra arguments in read mode
139run_make_test(q!
140X1 := $(file <file.out,foo)
141x:;@echo '$(X1)';
142!,
143 '', "#MAKEFILE#:2: *** file: too many arguments. Stop.\n", 512);
144
145
146# Missing filename
147run_make_test('$(file >)', '',
148 "#MAKEFILE#:1: *** file: missing filename. Stop.\n", 512);
149
150run_make_test('$(file >>)', '',
151 "#MAKEFILE#:1: *** file: missing filename. Stop.\n", 512);
152
153run_make_test('$(file <)', '',
154 "#MAKEFILE#:1: *** file: missing filename. Stop.\n", 512);
155
156# Bad call
157
158run_make_test('$(file foo)', '',
159 "#MAKEFILE#:1: *** file: invalid file operation: foo. Stop.\n", 512);
160
1611;
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette