diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-18 22:02:50 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-18 22:02:50 +0000 |
commit | b90c75afa26473fae4e6c2333beb241b7da27203 (patch) | |
tree | bc4f2383ca103e063dcf1d724c85172ca25e3b5d /tools/gn/escape_unittest.cc | |
parent | ebad924529462695b44cb0090d568a808ce83365 (diff) | |
download | chromium_src-b90c75afa26473fae4e6c2333beb241b7da27203.zip chromium_src-b90c75afa26473fae4e6c2333beb241b7da27203.tar.gz chromium_src-b90c75afa26473fae4e6c2333beb241b7da27203.tar.bz2 |
Update GN copy file rule.
This merges the syntax of the script and copy file rules and adds lots of documentation.
In doing this I realized that the template handling and escaping was bad in the script rules, so I did a bunch of work and added much better tests.
BUG=288991
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/23536068
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223954 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/gn/escape_unittest.cc')
-rw-r--r-- | tools/gn/escape_unittest.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/gn/escape_unittest.cc b/tools/gn/escape_unittest.cc index a7c19b3..a637e87 100644 --- a/tools/gn/escape_unittest.cc +++ b/tools/gn/escape_unittest.cc @@ -2,3 +2,45 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "testing/gtest/include/gtest/gtest.h" +#include "tools/gn/escape.h" + +TEST(Escape, UsedQuotes) { + EscapeOptions shell_options; + shell_options.mode = ESCAPE_SHELL; + + EscapeOptions ninja_options; + ninja_options.mode = ESCAPE_NINJA; + + EscapeOptions ninja_shell_options; + ninja_shell_options.mode = ESCAPE_NINJA_SHELL; + + // Shell escaping with quoting inhibited. + bool used_quotes = false; + shell_options.inhibit_quoting = true; + EXPECT_EQ("foo bar", EscapeString("foo bar", shell_options, &used_quotes)); + EXPECT_TRUE(used_quotes); + + // Shell escaping with regular quoting. + used_quotes = false; + shell_options.inhibit_quoting = false; + EXPECT_EQ("\"foo bar\"", + EscapeString("foo bar", shell_options, &used_quotes)); + EXPECT_TRUE(used_quotes); + + // Ninja shell escaping should be the same. + used_quotes = false; + EXPECT_EQ("\"foo$ bar\"", + EscapeString("foo bar", ninja_shell_options, &used_quotes)); + EXPECT_TRUE(used_quotes); + + // Ninja escaping shouldn't use quoting. + used_quotes = false; + EXPECT_EQ("foo$ bar", EscapeString("foo bar", ninja_options, &used_quotes)); + EXPECT_FALSE(used_quotes); + + // Used quotes not reset if it's already true. + used_quotes = true; + EscapeString("foo", ninja_options, &used_quotes); + EXPECT_TRUE(used_quotes); +} |