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

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

Issue 1214933007: Normalize paths in GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Actually "git add" the test file. Created 5 years, 5 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
« no previous file with comments | « tools/gn/gn.gyp ('k') | tools/gn/source_file.cc » ('j') | 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 <sstream> 5 #include <sstream>
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "tools/gn/output_file.h" 9 #include "tools/gn/output_file.h"
10 #include "tools/gn/path_output.h" 10 #include "tools/gn/path_output.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 PathOutput writer(build_dir, source_root, ESCAPE_NINJA); 77 PathOutput writer(build_dir, source_root, ESCAPE_NINJA);
78 { 78 {
79 // Spaces and $ in filenames. 79 // Spaces and $ in filenames.
80 std::ostringstream out; 80 std::ostringstream out;
81 writer.WriteFile(out, SourceFile("//foo/foo bar$.cc")); 81 writer.WriteFile(out, SourceFile("//foo/foo bar$.cc"));
82 EXPECT_EQ("../../foo/foo$ bar$$.cc", out.str()); 82 EXPECT_EQ("../../foo/foo$ bar$$.cc", out.str());
83 } 83 }
84 { 84 {
85 // Not other weird stuff 85 // Not other weird stuff
86 std::ostringstream out; 86 std::ostringstream out;
87 writer.WriteFile(out, SourceFile("//foo/\"foo\\bar\".cc")); 87 writer.WriteFile(out, SourceFile("//foo/\"foo\".cc"));
88 EXPECT_EQ("../../foo/\"foo\\bar\".cc", out.str()); 88 EXPECT_EQ("../../foo/\"foo\".cc", out.str());
89 } 89 }
90 } 90 }
91 91
92 TEST(PathOutput, NinjaForkEscaping) { 92 TEST(PathOutput, NinjaForkEscaping) {
93 SourceDir build_dir("//out/Debug/"); 93 SourceDir build_dir("//out/Debug/");
94 base::StringPiece source_root("/source/root"); 94 base::StringPiece source_root("/source/root");
95 PathOutput writer(build_dir, source_root, ESCAPE_NINJA_COMMAND); 95 PathOutput writer(build_dir, source_root, ESCAPE_NINJA_COMMAND);
96 96
97 // Spaces in filenames should get quoted on Windows. 97 // Spaces in filenames should get quoted on Windows.
98 writer.set_escape_platform(ESCAPE_PLATFORM_WIN); 98 writer.set_escape_platform(ESCAPE_PLATFORM_WIN);
(...skipping 21 matching lines...) Expand all
120 // change in the future. 120 // change in the future.
121 EXPECT_EQ("\"../../foo/\\\"foobar\\\".cc\"", out.str()); 121 EXPECT_EQ("\"../../foo/\\\"foobar\\\".cc\"", out.str());
122 } 122 }
123 writer.set_escape_platform(ESCAPE_PLATFORM_POSIX); 123 writer.set_escape_platform(ESCAPE_PLATFORM_POSIX);
124 { 124 {
125 std::ostringstream out; 125 std::ostringstream out;
126 writer.WriteFile(out, SourceFile("//foo/\"foobar\".cc")); 126 writer.WriteFile(out, SourceFile("//foo/\"foobar\".cc"));
127 EXPECT_EQ("../../foo/\\\"foobar\\\".cc", out.str()); 127 EXPECT_EQ("../../foo/\\\"foobar\\\".cc", out.str());
128 } 128 }
129 129
130
131 // Backslashes should get escaped on non-Windows and preserved on Windows. 130 // Backslashes should get escaped on non-Windows and preserved on Windows.
132 writer.set_escape_platform(ESCAPE_PLATFORM_WIN); 131 writer.set_escape_platform(ESCAPE_PLATFORM_WIN);
133 { 132 {
134 std::ostringstream out; 133 std::ostringstream out;
135 writer.WriteFile(out, SourceFile("//foo\\bar.cc")); 134 writer.WriteFile(out, OutputFile("foo\\bar.cc"));
136 EXPECT_EQ("../../foo\\bar.cc", out.str()); 135 EXPECT_EQ("foo\\bar.cc", out.str());
137 } 136 }
138 writer.set_escape_platform(ESCAPE_PLATFORM_POSIX); 137 writer.set_escape_platform(ESCAPE_PLATFORM_POSIX);
139 { 138 {
140 std::ostringstream out; 139 std::ostringstream out;
141 writer.WriteFile(out, SourceFile("//foo\\bar.cc")); 140 writer.WriteFile(out, OutputFile("foo\\bar.cc"));
142 EXPECT_EQ("../../foo\\\\bar.cc", out.str()); 141 EXPECT_EQ("foo\\\\bar.cc", out.str());
143 } 142 }
144 } 143 }
145 144
146 TEST(PathOutput, InhibitQuoting) { 145 TEST(PathOutput, InhibitQuoting) {
147 SourceDir build_dir("//out/Debug/"); 146 SourceDir build_dir("//out/Debug/");
148 base::StringPiece source_root("/source/root"); 147 base::StringPiece source_root("/source/root");
149 PathOutput writer(build_dir, source_root, ESCAPE_NINJA_COMMAND); 148 PathOutput writer(build_dir, source_root, ESCAPE_NINJA_COMMAND);
150 writer.set_inhibit_quoting(true); 149 writer.set_inhibit_quoting(true);
151 150
152 writer.set_escape_platform(ESCAPE_PLATFORM_WIN); 151 writer.set_escape_platform(ESCAPE_PLATFORM_WIN);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 EXPECT_EQ("./", out.str()); 274 EXPECT_EQ("./", out.str());
276 } 275 }
277 { 276 {
278 std::ostringstream out; 277 std::ostringstream out;
279 root_writer.WriteDir(out, SourceDir("//"), 278 root_writer.WriteDir(out, SourceDir("//"),
280 PathOutput::DIR_NO_LAST_SLASH); 279 PathOutput::DIR_NO_LAST_SLASH);
281 EXPECT_EQ(".", out.str()); 280 EXPECT_EQ(".", out.str());
282 } 281 }
283 } 282 }
284 } 283 }
OLDNEW
« no previous file with comments | « tools/gn/gn.gyp ('k') | tools/gn/source_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698