Verify that backslashes before non-special characters are preserved.
[make.git] / tests / scripts / features / escape
blob9b2adb5c9dbc36930eaf376323d1e4848e552868
1 #                                                                    -*-perl-*-
2 $description = "Test various types of escaping in makefiles.";
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.";
11 close(MAKEFILE);
14 # TEST 1
16 run_make_test('
17 $(path)foo : ; @echo "touch ($@)"
19 foo\ bar: ; @echo "touch ($@)"
21 sharp: foo\#bar.ext
22 foo\#bar.ext: ; @echo "foo#bar.ext = ($@)"',
23               '',
24               'touch (foo)');
26 # TEST 2: This one should fail, since the ":" is unquoted.
28 run_make_test(undef,
29               'path=pre:',
30               "#MAKEFILE#:2: *** target pattern contains no '%'.  Stop.",
31               512);
33 # TEST 3: This one should work, since we escape the ":".
35 run_make_test(undef,
36               "'path=pre\\:'",
37               'touch (pre:foo)');
39 # TEST 4: This one should fail, since the escape char is escaped.
41 run_make_test(undef,
42               "'path=pre\\\\:'",
43               "#MAKEFILE#:2: *** target pattern contains no '%'.  Stop.",
44               512);
46 # TEST 5: This one should work
48 run_make_test(undef,
49               "'foo bar'",
50               'touch (foo bar)');
52 # TEST 6: Test escaped comments
54 run_make_test(undef,
55               'sharp',
56               'foo#bar.ext = (foo#bar.ext)');
58 # Test escaped colons in prerequisites
59 # Quoting of backslashes in q!! is kind of messy.
60 run_make_test(q!
61 foo: foo\\:bar foo\\\\\\:bar foo\\\\\\\\\\:bar
62 foo foo\\:bar foo\\\\\\:bar foo\\\\\\\\\\:bar: ; @echo '$@'
64               '', "foo:bar\nfoo\\:bar\nfoo\\\\:bar\nfoo\n");
66 # Test backslash before non-special chars: should be kept as-is
68 run_make_test(q!
69 all: ..\foo
70 .DEFAULT: ; @echo '$@'
72               '', '..\foo');
74 # This tells the test driver that the perl test script executed properly.