OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "tools/gn/escape.h" | 8 #include "tools/gn/escape.h" |
9 #include "tools/gn/file_template.h" | 9 #include "tools/gn/file_template.h" |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 templates.push_back("-i"); | 56 templates.push_back("-i"); |
57 templates.push_back("{{source}}"); | 57 templates.push_back("{{source}}"); |
58 templates.push_back("--out=foo bar\"{{source_name_part}}\".o"); | 58 templates.push_back("--out=foo bar\"{{source_name_part}}\".o"); |
59 templates.push_back(""); // Test empty string. | 59 templates.push_back(""); // Test empty string. |
60 | 60 |
61 FileTemplate t(templates); | 61 FileTemplate t(templates); |
62 | 62 |
63 std::ostringstream out; | 63 std::ostringstream out; |
64 t.WriteWithNinjaExpansions(out); | 64 t.WriteWithNinjaExpansions(out); |
65 | 65 |
| 66 #if defined(OS_WIN) |
66 // The third argument should get quoted since it contains a space, and the | 67 // The third argument should get quoted since it contains a space, and the |
67 // embedded quotes should get shell escaped. | 68 // embedded quotes should get shell escaped. |
68 EXPECT_EQ( | 69 EXPECT_EQ( |
69 " -i ${source} \"--out=foo$ bar\\\"${source_name_part}\\\".o\" \"\"", | 70 " -i ${source} \"--out=foo$ bar\\\"${source_name_part}\\\".o\" \"\"", |
70 out.str()); | 71 out.str()); |
| 72 #else |
| 73 // On Posix we don't need to quote the whole thing and can escape all |
| 74 // individual bad chars. |
| 75 EXPECT_EQ( |
| 76 " -i ${source} --out=foo\\$ bar\\\"${source_name_part}\\\".o \"\"", |
| 77 out.str()); |
| 78 #endif |
71 } | 79 } |
72 | 80 |
73 TEST(FileTemplate, NinjaVariables) { | 81 TEST(FileTemplate, NinjaVariables) { |
74 std::vector<std::string> templates; | 82 std::vector<std::string> templates; |
75 templates.push_back("-i"); | 83 templates.push_back("-i"); |
76 templates.push_back("{{source}}"); | 84 templates.push_back("{{source}}"); |
77 templates.push_back("--out=foo bar\"{{source_name_part}}\".o"); | 85 templates.push_back("--out=foo bar\"{{source_name_part}}\".o"); |
78 | 86 |
79 FileTemplate t(templates); | 87 FileTemplate t(templates); |
80 | 88 |
81 std::ostringstream out; | 89 std::ostringstream out; |
82 EscapeOptions options; | 90 EscapeOptions options; |
83 options.mode = ESCAPE_NINJA_SHELL; | 91 options.mode = ESCAPE_NINJA_COMMAND; |
84 t.WriteNinjaVariablesForSubstitution(out, "../../foo/bar.txt", options); | 92 t.WriteNinjaVariablesForSubstitution(out, "../../foo/bar.txt", options); |
85 | 93 |
86 // Just the variables used above should be written. | 94 // Just the variables used above should be written. |
87 EXPECT_EQ( | 95 EXPECT_EQ( |
88 " source = ../../foo/bar.txt\n" | 96 " source = ../../foo/bar.txt\n" |
89 " source_name_part = bar\n", | 97 " source_name_part = bar\n", |
90 out.str()); | 98 out.str()); |
91 } | 99 } |
OLD | NEW |