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