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

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

Issue 711113004: original (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win compile fix Created 6 years, 1 month 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/path_output.cc ('k') | tools/gn/setup.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 "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 #include "tools/gn/output_file.h" 9 #include "tools/gn/output_file.h"
9 #include "tools/gn/path_output.h" 10 #include "tools/gn/path_output.h"
10 #include "tools/gn/source_dir.h" 11 #include "tools/gn/source_dir.h"
11 #include "tools/gn/source_file.h" 12 #include "tools/gn/source_file.h"
12 13
13 TEST(PathOutput, Basic) { 14 TEST(PathOutput, Basic) {
14 SourceDir build_dir("//out/Debug/"); 15 SourceDir build_dir("//out/Debug/");
15 PathOutput writer(build_dir, ESCAPE_NONE); 16 base::StringPiece source_root("/source/root");
17 PathOutput writer(build_dir, source_root, ESCAPE_NONE);
16 { 18 {
17 // Normal source-root path. 19 // Normal source-root path.
18 std::ostringstream out; 20 std::ostringstream out;
19 writer.WriteFile(out, SourceFile("//foo/bar.cc")); 21 writer.WriteFile(out, SourceFile("//foo/bar.cc"));
20 EXPECT_EQ("../../foo/bar.cc", out.str()); 22 EXPECT_EQ("../../foo/bar.cc", out.str());
21 } 23 }
22 { 24 {
23 // File in the root dir. 25 // File in the root dir.
24 std::ostringstream out; 26 std::ostringstream out;
25 writer.WriteFile(out, SourceFile("//foo.cc")); 27 writer.WriteFile(out, SourceFile("//foo.cc"));
(...skipping 20 matching lines...) Expand all
46 std::ostringstream out; 48 std::ostringstream out;
47 writer.WriteFile(out, SourceFile("/foo/bar.cc")); 49 writer.WriteFile(out, SourceFile("/foo/bar.cc"));
48 EXPECT_EQ("/foo/bar.cc", out.str()); 50 EXPECT_EQ("/foo/bar.cc", out.str());
49 } 51 }
50 #endif 52 #endif
51 } 53 }
52 54
53 // Same as basic but the output dir is the root. 55 // Same as basic but the output dir is the root.
54 TEST(PathOutput, BasicInRoot) { 56 TEST(PathOutput, BasicInRoot) {
55 SourceDir build_dir("//"); 57 SourceDir build_dir("//");
56 PathOutput writer(build_dir, ESCAPE_NONE); 58 base::StringPiece source_root("/source/root");
59 PathOutput writer(build_dir, source_root, ESCAPE_NONE);
57 { 60 {
58 // Normal source-root path. 61 // Normal source-root path.
59 std::ostringstream out; 62 std::ostringstream out;
60 writer.WriteFile(out, SourceFile("//foo/bar.cc")); 63 writer.WriteFile(out, SourceFile("//foo/bar.cc"));
61 EXPECT_EQ("foo/bar.cc", out.str()); 64 EXPECT_EQ("foo/bar.cc", out.str());
62 } 65 }
63 { 66 {
64 // File in the root dir. 67 // File in the root dir.
65 std::ostringstream out; 68 std::ostringstream out;
66 writer.WriteFile(out, SourceFile("//foo.cc")); 69 writer.WriteFile(out, SourceFile("//foo.cc"));
67 EXPECT_EQ("foo.cc", out.str()); 70 EXPECT_EQ("foo.cc", out.str());
68 } 71 }
69 } 72 }
70 73
71 TEST(PathOutput, NinjaEscaping) { 74 TEST(PathOutput, NinjaEscaping) {
72 SourceDir build_dir("//out/Debug/"); 75 SourceDir build_dir("//out/Debug/");
73 PathOutput writer(build_dir, ESCAPE_NINJA); 76 base::StringPiece source_root("/source/root");
77 PathOutput writer(build_dir, source_root, ESCAPE_NINJA);
74 { 78 {
75 // Spaces and $ in filenames. 79 // Spaces and $ in filenames.
76 std::ostringstream out; 80 std::ostringstream out;
77 writer.WriteFile(out, SourceFile("//foo/foo bar$.cc")); 81 writer.WriteFile(out, SourceFile("//foo/foo bar$.cc"));
78 EXPECT_EQ("../../foo/foo$ bar$$.cc", out.str()); 82 EXPECT_EQ("../../foo/foo$ bar$$.cc", out.str());
79 } 83 }
80 { 84 {
81 // Not other weird stuff 85 // Not other weird stuff
82 std::ostringstream out; 86 std::ostringstream out;
83 writer.WriteFile(out, SourceFile("//foo/\"foo\\bar\".cc")); 87 writer.WriteFile(out, SourceFile("//foo/\"foo\\bar\".cc"));
84 EXPECT_EQ("../../foo/\"foo\\bar\".cc", out.str()); 88 EXPECT_EQ("../../foo/\"foo\\bar\".cc", out.str());
85 } 89 }
86 } 90 }
87 91
88 TEST(PathOutput, NinjaForkEscaping) { 92 TEST(PathOutput, NinjaForkEscaping) {
89 SourceDir build_dir("//out/Debug/"); 93 SourceDir build_dir("//out/Debug/");
90 PathOutput writer(build_dir, ESCAPE_NINJA_COMMAND); 94 base::StringPiece source_root("/source/root");
95 PathOutput writer(build_dir, source_root, ESCAPE_NINJA_COMMAND);
91 96
92 // Spaces in filenames should get quoted on Windows. 97 // Spaces in filenames should get quoted on Windows.
93 writer.set_escape_platform(ESCAPE_PLATFORM_WIN); 98 writer.set_escape_platform(ESCAPE_PLATFORM_WIN);
94 { 99 {
95 std::ostringstream out; 100 std::ostringstream out;
96 writer.WriteFile(out, SourceFile("//foo/foo bar.cc")); 101 writer.WriteFile(out, SourceFile("//foo/foo bar.cc"));
97 EXPECT_EQ("\"../../foo/foo$ bar.cc\"", out.str()); 102 EXPECT_EQ("\"../../foo/foo$ bar.cc\"", out.str());
98 } 103 }
99 104
100 // Spaces in filenames should get escaped on Posix. 105 // Spaces in filenames should get escaped on Posix.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 writer.set_escape_platform(ESCAPE_PLATFORM_POSIX); 138 writer.set_escape_platform(ESCAPE_PLATFORM_POSIX);
134 { 139 {
135 std::ostringstream out; 140 std::ostringstream out;
136 writer.WriteFile(out, SourceFile("//foo\\bar.cc")); 141 writer.WriteFile(out, SourceFile("//foo\\bar.cc"));
137 EXPECT_EQ("../../foo\\\\bar.cc", out.str()); 142 EXPECT_EQ("../../foo\\\\bar.cc", out.str());
138 } 143 }
139 } 144 }
140 145
141 TEST(PathOutput, InhibitQuoting) { 146 TEST(PathOutput, InhibitQuoting) {
142 SourceDir build_dir("//out/Debug/"); 147 SourceDir build_dir("//out/Debug/");
143 PathOutput writer(build_dir, ESCAPE_NINJA_COMMAND); 148 base::StringPiece source_root("/source/root");
149 PathOutput writer(build_dir, source_root, ESCAPE_NINJA_COMMAND);
144 writer.set_inhibit_quoting(true); 150 writer.set_inhibit_quoting(true);
145 151
146 writer.set_escape_platform(ESCAPE_PLATFORM_WIN); 152 writer.set_escape_platform(ESCAPE_PLATFORM_WIN);
147 { 153 {
148 // We should get unescaped spaces in the output with no quotes. 154 // We should get unescaped spaces in the output with no quotes.
149 std::ostringstream out; 155 std::ostringstream out;
150 writer.WriteFile(out, SourceFile("//foo/foo bar.cc")); 156 writer.WriteFile(out, SourceFile("//foo/foo bar.cc"));
151 EXPECT_EQ("../../foo/foo$ bar.cc", out.str()); 157 EXPECT_EQ("../../foo/foo$ bar.cc", out.str());
152 } 158 }
153 159
154 writer.set_escape_platform(ESCAPE_PLATFORM_POSIX); 160 writer.set_escape_platform(ESCAPE_PLATFORM_POSIX);
155 { 161 {
156 // Escapes the space. 162 // Escapes the space.
157 std::ostringstream out; 163 std::ostringstream out;
158 writer.WriteFile(out, SourceFile("//foo/foo bar.cc")); 164 writer.WriteFile(out, SourceFile("//foo/foo bar.cc"));
159 EXPECT_EQ("../../foo/foo\\$ bar.cc", out.str()); 165 EXPECT_EQ("../../foo/foo\\$ bar.cc", out.str());
160 } 166 }
161 } 167 }
162 168
163 TEST(PathOutput, WriteDir) { 169 TEST(PathOutput, WriteDir) {
164 { 170 {
165 SourceDir build_dir("//out/Debug/"); 171 SourceDir build_dir("//out/Debug/");
166 PathOutput writer(build_dir, ESCAPE_NINJA); 172 base::StringPiece source_root("/source/root");
173 PathOutput writer(build_dir, source_root, ESCAPE_NINJA);
167 { 174 {
168 std::ostringstream out; 175 std::ostringstream out;
169 writer.WriteDir(out, SourceDir("//foo/bar/"), 176 writer.WriteDir(out, SourceDir("//foo/bar/"),
170 PathOutput::DIR_INCLUDE_LAST_SLASH); 177 PathOutput::DIR_INCLUDE_LAST_SLASH);
171 EXPECT_EQ("../../foo/bar/", out.str()); 178 EXPECT_EQ("../../foo/bar/", out.str());
172 } 179 }
173 { 180 {
174 std::ostringstream out; 181 std::ostringstream out;
175 writer.WriteDir(out, SourceDir("//foo/bar/"), 182 writer.WriteDir(out, SourceDir("//foo/bar/"),
176 PathOutput::DIR_NO_LAST_SLASH); 183 PathOutput::DIR_NO_LAST_SLASH);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 259 }
253 { 260 {
254 std::ostringstream out; 261 std::ostringstream out;
255 writer.WriteDir(out, OutputFile(), 262 writer.WriteDir(out, OutputFile(),
256 PathOutput::DIR_INCLUDE_LAST_SLASH); 263 PathOutput::DIR_INCLUDE_LAST_SLASH);
257 EXPECT_EQ("", out.str()); 264 EXPECT_EQ("", out.str());
258 } 265 }
259 } 266 }
260 { 267 {
261 // Empty build dir writer. 268 // Empty build dir writer.
262 PathOutput root_writer(SourceDir("//"), ESCAPE_NINJA); 269 base::StringPiece source_root("/source/root");
270 PathOutput root_writer(SourceDir("//"), source_root, ESCAPE_NINJA);
263 { 271 {
264 std::ostringstream out; 272 std::ostringstream out;
265 root_writer.WriteDir(out, SourceDir("//"), 273 root_writer.WriteDir(out, SourceDir("//"),
266 PathOutput::DIR_INCLUDE_LAST_SLASH); 274 PathOutput::DIR_INCLUDE_LAST_SLASH);
267 EXPECT_EQ("./", out.str()); 275 EXPECT_EQ("./", out.str());
268 } 276 }
269 { 277 {
270 std::ostringstream out; 278 std::ostringstream out;
271 root_writer.WriteDir(out, SourceDir("//"), 279 root_writer.WriteDir(out, SourceDir("//"),
272 PathOutput::DIR_NO_LAST_SLASH); 280 PathOutput::DIR_NO_LAST_SLASH);
273 EXPECT_EQ(".", out.str()); 281 EXPECT_EQ(".", out.str());
274 } 282 }
275 } 283 }
276 } 284 }
OLDNEW
« no previous file with comments | « tools/gn/path_output.cc ('k') | tools/gn/setup.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698