Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: tools/gn/escape_unittest.cc

Issue 305653008: Escape more characters for GN shell writing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« tools/gn/escape.cc ('K') | « tools/gn/escape.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/escape.h" 6 #include "tools/gn/escape.h"
7 7
8 TEST(Escape, Ninja) { 8 TEST(Escape, Ninja) {
9 EscapeOptions opts; 9 EscapeOptions opts;
10 opts.mode = ESCAPE_NINJA; 10 opts.mode = ESCAPE_NINJA;
11 std::string result = EscapeString("asdf: \"$\\bar", opts, NULL); 11 std::string result = EscapeString("asdf: \"$\\bar", opts, NULL);
12 EXPECT_EQ("asdf$:$ \"$$\\bar", result); 12 EXPECT_EQ("asdf$:$ \"$$\\bar", result);
13 } 13 }
14 14
15 TEST(Escape, Shell) { 15 TEST(Escape, Shell) {
16 EscapeOptions opts; 16 EscapeOptions opts;
17 opts.mode = ESCAPE_SHELL; 17 opts.mode = ESCAPE_SHELL;
18 std::string result = EscapeString("asdf: \"$\\bar", opts, NULL); 18 std::string result = EscapeString("asdf: \"$\\bar", opts, NULL);
19 #if defined(OS_WIN) 19 #if defined(OS_WIN)
20 // Windows shell doesn't escape backslashes, but it does backslash-escape 20 // Windows shell doesn't escape backslashes, but it does backslash-escape
21 // quotes. 21 // quotes.
22 EXPECT_EQ("\"asdf: \\\"$\\bar\"", result); 22 EXPECT_EQ("\"asdf: \\\"\\$\\bar\"", result);
23 #else 23 #else
24 EXPECT_EQ("\"asdf: \\\"$\\\\bar\"", result); 24 EXPECT_EQ("\"asdf: \\\"\\$\\\\bar\"", result);
25 #endif 25 #endif
26
27 // Some more generic shell chars.
28 result = EscapeString("a_;<*b", opts, NULL);
29 EXPECT_EQ("a_\\;\\<\\*b", result);
30 }
31
32 TEST(Escape, NinjaShell) {
33 EscapeOptions opts;
34 opts.mode = ESCAPE_NINJA_SHELL;
35
36 // When escaping for Ninja and the shell, we would escape a $, then escape
37 // the backslash again.
38 std::string result = EscapeString("a$b", opts, NULL);
39 EXPECT_EQ("a\\$$b", result);
26 } 40 }
27 41
28 TEST(Escape, UsedQuotes) { 42 TEST(Escape, UsedQuotes) {
29 EscapeOptions shell_options; 43 EscapeOptions shell_options;
30 shell_options.mode = ESCAPE_SHELL; 44 shell_options.mode = ESCAPE_SHELL;
31 45
32 EscapeOptions ninja_options; 46 EscapeOptions ninja_options;
33 ninja_options.mode = ESCAPE_NINJA; 47 ninja_options.mode = ESCAPE_NINJA;
34 48
35 EscapeOptions ninja_shell_options; 49 EscapeOptions ninja_shell_options;
(...skipping 21 matching lines...) Expand all
57 // Ninja escaping shouldn't use quoting. 71 // Ninja escaping shouldn't use quoting.
58 used_quotes = false; 72 used_quotes = false;
59 EXPECT_EQ("foo$ bar", EscapeString("foo bar", ninja_options, &used_quotes)); 73 EXPECT_EQ("foo$ bar", EscapeString("foo bar", ninja_options, &used_quotes));
60 EXPECT_FALSE(used_quotes); 74 EXPECT_FALSE(used_quotes);
61 75
62 // Used quotes not reset if it's already true. 76 // Used quotes not reset if it's already true.
63 used_quotes = true; 77 used_quotes = true;
64 EscapeString("foo", ninja_options, &used_quotes); 78 EscapeString("foo", ninja_options, &used_quotes);
65 EXPECT_TRUE(used_quotes); 79 EXPECT_TRUE(used_quotes);
66 } 80 }
OLDNEW
« tools/gn/escape.cc ('K') | « tools/gn/escape.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698