Debian Codegraph @

tests/scripts/features/escape

raw
1 # -*-perl-*-
2 $description = "Test various types of escaping in makefiles.";
3
4 $details = "\
5 Make sure that escaping of ':' works in target names.
6 Make sure escaping of whitespace works in target names.
7 Make sure that escaping of '#' works.
8 Make sure that backslash before non-special characters are kept.";
9
10
11 # TEST 1
12
13 run_make_test(q!
14 ifdef NOESC
15 path = pre:
16 endif
17 ifdef ONEESC
18 path = pre\:
19 endif
20 ifdef TWOESC
21 path = pre\\\\:
22 endif
23
24 $(path)foo : ; @echo "touch ($@)"
25
26 foo\ bar: ; @echo "touch ($@)"
27
28 sharp: foo\#bar.ext
29 foo\#bar.ext: ; @echo "foo#bar.ext = ($@)"
30 !,
31 '',
32 'touch (foo)');
33
34 # TEST 2: This one should fail, since the ":" is unquoted.
35
36 run_make_test(undef,
37 'NOESC=1',
38 "#MAKEFILE#:12: *** target pattern contains no '%'. Stop.",
39 512);
40
41 # TEST 3: This one should work, since we escape the ":".
42
43 run_make_test(undef,
44 'ONEESC=1',
45 'touch (pre:foo)');
46
47 # TEST 4: This one should fail, since the escape char is escaped.
48
49 run_make_test(undef,
50 'TWOESC=1',
51 "#MAKEFILE#:12: *** target pattern contains no '%'. Stop.",
52 512);
53
54 # TEST 5: This one should work
55
56 run_make_test(undef,
57 ['foo bar'],
58 'touch (foo bar)');
59
60 # TEST 6: Test escaped comments
61
62 run_make_test(undef,
63 'sharp',
64 'foo#bar.ext = (foo#bar.ext)');
65
66 # Test escaped colons in prerequisites
67 # Quoting of backslashes in q!! is kind of messy.
68 # Solaris sh does not properly handle backslashes even in '' so just
69 # check the output make prints, not what the shell interprets.
70 run_make_test(q!
71 foo: foo\\:bar foo\\\\\\:bar foo\\\\\\\\\\:bar
72 foo foo\\:bar foo\\\\\\:bar foo\\\\\\\\\\:bar: ; : '$@'
73 !,
74 '', ": 'foo:bar'\n: 'foo\\:bar'\n: 'foo\\\\:bar'\n: 'foo'\n");
75
76 # Test backslash before non-special chars: should be kept as-is
77
78 run_make_test(q!
79 all: ..\foo
80 .DEFAULT: ; : '$@'
81 !,
82 '', ": '..\\foo'\n");
83
84 # Test escaped comments in variable assignments
85 run_make_test(q!
86 self = $1
87 foo := $(call self,#foo#)#foo
88 bar := $(call self,\#bar\#)#bar
89 all:;@echo '$(foo) $(bar)'
90 !,
91 '',"#foo# \\#bar\\#");
92
93 # Test escaped comments in variable assignments in a variable
94 run_make_test(q!
95 C = \#
96 self = $1
97 foo := $(call self,$Cfoo$C)#foo
98 all:;@echo '$(foo)'
99 !,
100 '',"#foo#");
101
102 # This tells the test driver that the perl test script executed properly.
103 1;