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/output_file.h" |
8 #include "tools/gn/path_output.h" | 9 #include "tools/gn/path_output.h" |
9 #include "tools/gn/source_dir.h" | 10 #include "tools/gn/source_dir.h" |
10 #include "tools/gn/source_file.h" | 11 #include "tools/gn/source_file.h" |
11 | 12 |
12 TEST(PathOutput, Basic) { | 13 TEST(PathOutput, Basic) { |
13 SourceDir build_dir("//out/Debug/"); | 14 SourceDir build_dir("//out/Debug/"); |
14 PathOutput writer(build_dir, ESCAPE_NONE); | 15 PathOutput writer(build_dir, ESCAPE_NONE); |
15 { | 16 { |
16 // Normal source-root path. | 17 // Normal source-root path. |
17 std::ostringstream out; | 18 std::ostringstream out; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 { | 207 { |
207 std::ostringstream out; | 208 std::ostringstream out; |
208 writer.WriteDir(out, SourceDir("/"), | 209 writer.WriteDir(out, SourceDir("/"), |
209 PathOutput::DIR_NO_LAST_SLASH); | 210 PathOutput::DIR_NO_LAST_SLASH); |
210 EXPECT_EQ("/.", out.str()); | 211 EXPECT_EQ("/.", out.str()); |
211 } | 212 } |
212 | 213 |
213 // Output inside current dir. | 214 // Output inside current dir. |
214 { | 215 { |
215 std::ostringstream out; | 216 std::ostringstream out; |
216 | |
217 | |
218 writer.WriteDir(out, SourceDir("//out/Debug/"), | 217 writer.WriteDir(out, SourceDir("//out/Debug/"), |
219 PathOutput::DIR_INCLUDE_LAST_SLASH); | 218 PathOutput::DIR_INCLUDE_LAST_SLASH); |
220 EXPECT_EQ("./", out.str()); | 219 EXPECT_EQ("./", out.str()); |
221 } | 220 } |
222 { | 221 { |
223 std::ostringstream out; | 222 std::ostringstream out; |
224 writer.WriteDir(out, SourceDir("//out/Debug/"), | 223 writer.WriteDir(out, SourceDir("//out/Debug/"), |
225 PathOutput::DIR_NO_LAST_SLASH); | 224 PathOutput::DIR_NO_LAST_SLASH); |
226 EXPECT_EQ(".", out.str()); | 225 EXPECT_EQ(".", out.str()); |
227 } | 226 } |
228 { | 227 { |
229 std::ostringstream out; | 228 std::ostringstream out; |
230 writer.WriteDir(out, SourceDir("//out/Debug/foo/"), | 229 writer.WriteDir(out, SourceDir("//out/Debug/foo/"), |
231 PathOutput::DIR_INCLUDE_LAST_SLASH); | 230 PathOutput::DIR_INCLUDE_LAST_SLASH); |
232 EXPECT_EQ("foo/", out.str()); | 231 EXPECT_EQ("foo/", out.str()); |
233 } | 232 } |
234 { | 233 { |
235 std::ostringstream out; | 234 std::ostringstream out; |
236 writer.WriteDir(out, SourceDir("//out/Debug/foo/"), | 235 writer.WriteDir(out, SourceDir("//out/Debug/foo/"), |
237 PathOutput::DIR_NO_LAST_SLASH); | 236 PathOutput::DIR_NO_LAST_SLASH); |
238 EXPECT_EQ("foo", out.str()); | 237 EXPECT_EQ("foo", out.str()); |
239 } | 238 } |
| 239 |
| 240 // WriteDir using an OutputFile. |
| 241 { |
| 242 std::ostringstream out; |
| 243 writer.WriteDir(out, OutputFile("foo/"), |
| 244 PathOutput::DIR_INCLUDE_LAST_SLASH); |
| 245 EXPECT_EQ("foo/", out.str()); |
| 246 } |
| 247 { |
| 248 std::ostringstream out; |
| 249 writer.WriteDir(out, OutputFile("foo/"), |
| 250 PathOutput::DIR_NO_LAST_SLASH); |
| 251 EXPECT_EQ("foo", out.str()); |
| 252 } |
| 253 { |
| 254 std::ostringstream out; |
| 255 writer.WriteDir(out, OutputFile(), |
| 256 PathOutput::DIR_INCLUDE_LAST_SLASH); |
| 257 EXPECT_EQ("", out.str()); |
| 258 } |
240 } | 259 } |
241 { | 260 { |
242 // Empty build dir writer. | 261 // Empty build dir writer. |
243 PathOutput root_writer(SourceDir("//"), ESCAPE_NINJA); | 262 PathOutput root_writer(SourceDir("//"), ESCAPE_NINJA); |
244 { | 263 { |
245 std::ostringstream out; | 264 std::ostringstream out; |
246 root_writer.WriteDir(out, SourceDir("//"), | 265 root_writer.WriteDir(out, SourceDir("//"), |
247 PathOutput::DIR_INCLUDE_LAST_SLASH); | 266 PathOutput::DIR_INCLUDE_LAST_SLASH); |
248 EXPECT_EQ("./", out.str()); | 267 EXPECT_EQ("./", out.str()); |
249 } | 268 } |
250 { | 269 { |
251 std::ostringstream out; | 270 std::ostringstream out; |
252 root_writer.WriteDir(out, SourceDir("//"), | 271 root_writer.WriteDir(out, SourceDir("//"), |
253 PathOutput::DIR_NO_LAST_SLASH); | 272 PathOutput::DIR_NO_LAST_SLASH); |
254 EXPECT_EQ(".", out.str()); | 273 EXPECT_EQ(".", out.str()); |
255 } | 274 } |
256 } | 275 } |
257 } | 276 } |
OLD | NEW |