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
3 // found in the LICENSE file.
5 #include "base/files/file_path.h"
6 #include "base/strings/string_util.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "build/build_config.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "tools/gn/filesystem_utils.h"
11 #include "tools/gn/target.h"
13 TEST(FilesystemUtils
, FileExtensionOffset
) {
14 EXPECT_EQ(std::string::npos
, FindExtensionOffset(""));
15 EXPECT_EQ(std::string::npos
, FindExtensionOffset("foo/bar/baz"));
16 EXPECT_EQ(4u, FindExtensionOffset("foo."));
17 EXPECT_EQ(4u, FindExtensionOffset("f.o.bar"));
18 EXPECT_EQ(std::string::npos
, FindExtensionOffset("foo.bar/"));
19 EXPECT_EQ(std::string::npos
, FindExtensionOffset("foo.bar/baz"));
22 TEST(FilesystemUtils
, FindExtension
) {
24 EXPECT_EQ("", FindExtension(&input
).as_string());
25 input
= "foo/bar/baz";
26 EXPECT_EQ("", FindExtension(&input
).as_string());
28 EXPECT_EQ("", FindExtension(&input
).as_string());
30 EXPECT_EQ("bar", FindExtension(&input
).as_string());
32 EXPECT_EQ("", FindExtension(&input
).as_string());
33 input
= "foo.bar/baz";
34 EXPECT_EQ("", FindExtension(&input
).as_string());
37 TEST(FilesystemUtils
, FindFilenameOffset
) {
38 EXPECT_EQ(0u, FindFilenameOffset(""));
39 EXPECT_EQ(0u, FindFilenameOffset("foo"));
40 EXPECT_EQ(4u, FindFilenameOffset("foo/"));
41 EXPECT_EQ(4u, FindFilenameOffset("foo/bar"));
44 TEST(FilesystemUtils
, RemoveFilename
) {
48 EXPECT_STREQ("", s
.c_str());
52 EXPECT_STREQ("", s
.c_str());
56 EXPECT_STREQ("/", s
.c_str());
60 EXPECT_STREQ("foo/", s
.c_str());
64 EXPECT_STREQ("foo/bar/", s
.c_str());
67 TEST(FilesystemUtils
, FindDir
) {
69 EXPECT_EQ("", FindDir(&input
));
71 EXPECT_EQ("/", FindDir(&input
));
73 EXPECT_EQ("foo/", FindDir(&input
));
74 input
= "foo/bar/baz";
75 EXPECT_EQ("foo/bar/", FindDir(&input
));
78 TEST(FilesystemUtils
, FindLastDirComponent
) {
80 EXPECT_EQ("", FindLastDirComponent(empty
));
83 EXPECT_EQ("", FindLastDirComponent(root
));
85 SourceDir
srcroot("//");
86 EXPECT_EQ("", FindLastDirComponent(srcroot
));
88 SourceDir
regular1("//foo/");
89 EXPECT_EQ("foo", FindLastDirComponent(regular1
));
91 SourceDir
regular2("//foo/bar/");
92 EXPECT_EQ("bar", FindLastDirComponent(regular2
));
95 TEST(FilesystemUtils
, EnsureStringIsInOutputDir
) {
96 SourceDir
output_dir("//out/Debug/");
100 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir
, "//foo", nullptr, &err
));
101 EXPECT_TRUE(err
.has_error());
104 EnsureStringIsInOutputDir(output_dir
, "//out/Debugit", nullptr, &err
));
105 EXPECT_TRUE(err
.has_error());
110 EnsureStringIsInOutputDir(output_dir
, "//out/Debug/", nullptr, &err
));
111 EXPECT_FALSE(err
.has_error());
113 EnsureStringIsInOutputDir(output_dir
, "//out/Debug/foo", nullptr, &err
));
114 EXPECT_FALSE(err
.has_error());
116 // Pattern but no template expansions are allowed.
117 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir
, "{{source_gen_dir}}",
119 EXPECT_TRUE(err
.has_error());
122 TEST(FilesystemUtils
, IsPathAbsolute
) {
123 EXPECT_TRUE(IsPathAbsolute("/foo/bar"));
124 EXPECT_TRUE(IsPathAbsolute("/"));
125 EXPECT_FALSE(IsPathAbsolute(""));
126 EXPECT_FALSE(IsPathAbsolute("//"));
127 EXPECT_FALSE(IsPathAbsolute("//foo/bar"));
130 EXPECT_TRUE(IsPathAbsolute("C:/foo"));
131 EXPECT_TRUE(IsPathAbsolute("C:/"));
132 EXPECT_TRUE(IsPathAbsolute("C:\\foo"));
133 EXPECT_TRUE(IsPathAbsolute("C:\\"));
134 EXPECT_TRUE(IsPathAbsolute("/C:/foo"));
135 EXPECT_TRUE(IsPathAbsolute("/C:\\foo"));
139 TEST(FilesystemUtils
, MakeAbsolutePathRelativeIfPossible
) {
143 EXPECT_TRUE(MakeAbsolutePathRelativeIfPossible("C:\\base", "C:\\base\\foo",
145 EXPECT_EQ("//foo", dest
);
146 EXPECT_TRUE(MakeAbsolutePathRelativeIfPossible("C:\\base", "/C:/base/foo",
148 EXPECT_EQ("//foo", dest
);
149 EXPECT_TRUE(MakeAbsolutePathRelativeIfPossible("c:\\base", "C:\\base\\foo\\",
151 EXPECT_EQ("//foo\\", dest
);
153 EXPECT_FALSE(MakeAbsolutePathRelativeIfPossible("C:\\base", "C:\\ba", &dest
));
154 EXPECT_FALSE(MakeAbsolutePathRelativeIfPossible("C:\\base",
159 EXPECT_TRUE(MakeAbsolutePathRelativeIfPossible("/base", "/base/foo/", &dest
));
160 EXPECT_EQ("//foo/", dest
);
161 EXPECT_TRUE(MakeAbsolutePathRelativeIfPossible("/base", "/base/foo", &dest
));
162 EXPECT_EQ("//foo", dest
);
163 EXPECT_TRUE(MakeAbsolutePathRelativeIfPossible("/base/", "/base/foo/",
165 EXPECT_EQ("//foo/", dest
);
167 EXPECT_FALSE(MakeAbsolutePathRelativeIfPossible("/base", "/ba", &dest
));
168 EXPECT_FALSE(MakeAbsolutePathRelativeIfPossible("/base", "/notbase/foo",
173 TEST(FilesystemUtils
, NormalizePath
) {
176 NormalizePath(&input
);
177 EXPECT_EQ("", input
);
179 input
= "foo/bar.txt";
180 NormalizePath(&input
);
181 EXPECT_EQ("foo/bar.txt", input
);
184 NormalizePath(&input
);
185 EXPECT_EQ("", input
);
188 NormalizePath(&input
);
189 EXPECT_EQ("..", input
);
192 NormalizePath(&input
);
193 EXPECT_EQ("foo/bar", input
);
196 NormalizePath(&input
);
197 EXPECT_EQ("//foo", input
);
199 input
= "foo/..//bar";
200 NormalizePath(&input
);
201 EXPECT_EQ("bar", input
);
203 input
= "foo/../../bar";
204 NormalizePath(&input
);
205 EXPECT_EQ("../bar", input
);
207 input
= "/../foo"; // Don't go aboe the root dir.
208 NormalizePath(&input
);
209 EXPECT_EQ("/foo", input
);
211 input
= "//../foo"; // Don't go above the root dir.
212 NormalizePath(&input
);
213 EXPECT_EQ("//foo", input
);
216 NormalizePath(&input
);
217 EXPECT_EQ("../foo", input
);
220 NormalizePath(&input
);
221 EXPECT_EQ("..", input
);
224 NormalizePath(&input
);
225 EXPECT_EQ("", input
);
228 NormalizePath(&input
);
229 EXPECT_EQ("../../..", input
);
232 NormalizePath(&input
);
233 EXPECT_EQ("../", input
);
235 // Backslash normalization.
236 input
= "foo\\..\\..\\bar";
237 NormalizePath(&input
);
238 EXPECT_EQ("../bar", input
);
240 // Trailing slashes should get preserved.
241 input
= "//foo/bar/";
242 NormalizePath(&input
);
243 EXPECT_EQ("//foo/bar/", input
);
246 TEST(FilesystemUtils
, RebasePath
) {
247 base::StringPiece
source_root("/source/root");
250 EXPECT_EQ(".", RebasePath("//", SourceDir("//"), source_root
));
251 EXPECT_EQ(".", RebasePath("//foo/bar/", SourceDir("//foo/bar/"),
254 // Going up the tree.
255 EXPECT_EQ("../foo", RebasePath("//foo", SourceDir("//bar/"), source_root
));
256 EXPECT_EQ("../foo/", RebasePath("//foo/", SourceDir("//bar/"), source_root
));
257 EXPECT_EQ("../../foo", RebasePath("//foo", SourceDir("//bar/moo"),
259 EXPECT_EQ("../../foo/", RebasePath("//foo/", SourceDir("//bar/moo"),
262 // Going down the tree.
263 EXPECT_EQ("foo/bar", RebasePath("//foo/bar", SourceDir("//"), source_root
));
264 EXPECT_EQ("foo/bar/", RebasePath("//foo/bar/", SourceDir("//"),
267 // Going up and down the tree.
268 EXPECT_EQ("../../foo/bar", RebasePath("//foo/bar", SourceDir("//a/b/"),
270 EXPECT_EQ("../../foo/bar/", RebasePath("//foo/bar/", SourceDir("//a/b/"),
274 EXPECT_EQ("foo", RebasePath("//a/foo", SourceDir("//a/"), source_root
));
275 EXPECT_EQ("foo/", RebasePath("//a/foo/", SourceDir("//a/"), source_root
));
276 EXPECT_EQ("foo", RebasePath("//a/b/foo", SourceDir("//a/b/"), source_root
));
277 EXPECT_EQ("foo/", RebasePath("//a/b/foo/", SourceDir("//a/b/"),
279 EXPECT_EQ("foo/bar", RebasePath("//a/b/foo/bar", SourceDir("//a/b/"),
281 EXPECT_EQ("foo/bar/", RebasePath("//a/b/foo/bar/", SourceDir("//a/b/"),
284 // One could argue about this case. Since the input doesn't have a slash it
285 // would normally not be treated like a directory and we'd go up, which is
286 // simpler. However, since it matches the output directory's name, we could
287 // potentially infer that it's the same and return "." for this.
288 EXPECT_EQ("../bar", RebasePath("//foo/bar", SourceDir("//foo/bar/"),
291 // Check when only |input| is system-absolute
292 EXPECT_EQ("foo", RebasePath("/source/root/foo", SourceDir("//"),
293 base::StringPiece("/source/root")));
294 EXPECT_EQ("foo/", RebasePath("/source/root/foo/", SourceDir("//"),
295 base::StringPiece("/source/root")));
296 EXPECT_EQ("../../builddir/Out/Debug",
297 RebasePath("/builddir/Out/Debug", SourceDir("//"),
298 base::StringPiece("/source/root")));
299 EXPECT_EQ("../../../builddir/Out/Debug",
300 RebasePath("/builddir/Out/Debug", SourceDir("//"),
301 base::StringPiece("/source/root/foo")));
302 EXPECT_EQ("../../../builddir/Out/Debug/",
303 RebasePath("/builddir/Out/Debug/", SourceDir("//"),
304 base::StringPiece("/source/root/foo")));
305 EXPECT_EQ("../../path/to/foo",
306 RebasePath("/path/to/foo", SourceDir("//"),
307 base::StringPiece("/source/root")));
308 EXPECT_EQ("../../../path/to/foo",
309 RebasePath("/path/to/foo", SourceDir("//a"),
310 base::StringPiece("/source/root")));
311 EXPECT_EQ("../../../../path/to/foo",
312 RebasePath("/path/to/foo", SourceDir("//a/b"),
313 base::StringPiece("/source/root")));
315 // Check when only |dest_dir| is system-absolute.
317 RebasePath("//", SourceDir("/source/root"),
318 base::StringPiece("/source/root")));
320 RebasePath("//foo", SourceDir("/source/root"),
321 base::StringPiece("/source/root")));
323 RebasePath("//foo", SourceDir("/source/root/bar"),
324 base::StringPiece("/source/root")));
325 EXPECT_EQ("../../../source/root/foo",
326 RebasePath("//foo", SourceDir("/other/source/root"),
327 base::StringPiece("/source/root")));
328 EXPECT_EQ("../../../../source/root/foo",
329 RebasePath("//foo", SourceDir("/other/source/root/bar"),
330 base::StringPiece("/source/root")));
332 // Check when |input| and |dest_dir| are both system-absolute. Also,
333 // in this case |source_root| is never used so set it to a dummy
336 RebasePath("/source/root/foo", SourceDir("/source/root"),
337 base::StringPiece("/x/y/z")));
339 RebasePath("/source/root/foo/", SourceDir("/source/root"),
340 base::StringPiece("/x/y/z")));
341 EXPECT_EQ("../../builddir/Out/Debug",
342 RebasePath("/builddir/Out/Debug",SourceDir("/source/root"),
343 base::StringPiece("/x/y/z")));
344 EXPECT_EQ("../../../builddir/Out/Debug",
345 RebasePath("/builddir/Out/Debug", SourceDir("/source/root/foo"),
346 base::StringPiece("/source/root/foo")));
347 EXPECT_EQ("../../../builddir/Out/Debug/",
348 RebasePath("/builddir/Out/Debug/", SourceDir("/source/root/foo"),
349 base::StringPiece("/source/root/foo")));
350 EXPECT_EQ("../../path/to/foo",
351 RebasePath("/path/to/foo", SourceDir("/source/root"),
352 base::StringPiece("/x/y/z")));
353 EXPECT_EQ("../../../path/to/foo",
354 RebasePath("/path/to/foo", SourceDir("/source/root/a"),
355 base::StringPiece("/x/y/z")));
356 EXPECT_EQ("../../../../path/to/foo",
357 RebasePath("/path/to/foo", SourceDir("/source/root/a/b"),
358 base::StringPiece("/x/y/z")));
362 TEST(FilesystemUtils
, DirectoryWithNoLastSlash
) {
363 EXPECT_EQ("", DirectoryWithNoLastSlash(SourceDir()));
364 EXPECT_EQ("/.", DirectoryWithNoLastSlash(SourceDir("/")));
365 EXPECT_EQ("//.", DirectoryWithNoLastSlash(SourceDir("//")));
366 EXPECT_EQ("//foo", DirectoryWithNoLastSlash(SourceDir("//foo/")));
367 EXPECT_EQ("/bar", DirectoryWithNoLastSlash(SourceDir("/bar/")));
370 TEST(FilesystemUtils
, SourceDirForPath
) {
372 base::FilePath
root(L
"C:\\source\\foo\\");
373 EXPECT_EQ("/C:/foo/bar/", SourceDirForPath(root
,
374 base::FilePath(L
"C:\\foo\\bar")).value());
375 EXPECT_EQ("/", SourceDirForPath(root
,
376 base::FilePath(L
"/")).value());
377 EXPECT_EQ("//", SourceDirForPath(root
,
378 base::FilePath(L
"C:\\source\\foo")).value());
379 EXPECT_EQ("//bar/", SourceDirForPath(root
,
380 base::FilePath(L
"C:\\source\\foo\\bar\\")). value());
381 EXPECT_EQ("//bar/baz/", SourceDirForPath(root
,
382 base::FilePath(L
"C:\\source\\foo\\bar\\baz")).value());
384 // Should be case-and-slash-insensitive.
385 EXPECT_EQ("//baR/", SourceDirForPath(root
,
386 base::FilePath(L
"c:/SOURCE\\Foo/baR/")).value());
388 // Some "weird" Windows paths.
389 EXPECT_EQ("/foo/bar/", SourceDirForPath(root
,
390 base::FilePath(L
"/foo/bar/")).value());
391 EXPECT_EQ("/C:/foo/bar/", SourceDirForPath(root
,
392 base::FilePath(L
"C:foo/bar/")).value());
394 // Also allow absolute GN-style Windows paths.
395 EXPECT_EQ("/C:/foo/bar/", SourceDirForPath(root
,
396 base::FilePath(L
"/C:/foo/bar")).value());
397 EXPECT_EQ("//bar/", SourceDirForPath(root
,
398 base::FilePath(L
"/C:/source/foo/bar")).value());
401 base::FilePath empty
;
404 SourceDirForPath(empty
, base::FilePath(L
"C:\\source\\foo")).value());
406 base::FilePath
root("/source/foo/");
407 EXPECT_EQ("/foo/bar/", SourceDirForPath(root
,
408 base::FilePath("/foo/bar/")).value());
409 EXPECT_EQ("/", SourceDirForPath(root
,
410 base::FilePath("/")).value());
411 EXPECT_EQ("//", SourceDirForPath(root
,
412 base::FilePath("/source/foo")).value());
413 EXPECT_EQ("//bar/", SourceDirForPath(root
,
414 base::FilePath("/source/foo/bar/")).value());
415 EXPECT_EQ("//bar/baz/", SourceDirForPath(root
,
416 base::FilePath("/source/foo/bar/baz/")).value());
418 // Should be case-sensitive.
419 EXPECT_EQ("/SOURCE/foo/bar/", SourceDirForPath(root
,
420 base::FilePath("/SOURCE/foo/bar/")).value());
423 base::FilePath empty
;
424 EXPECT_EQ("/source/foo/",
425 SourceDirForPath(empty
, base::FilePath("/source/foo")).value());
429 TEST(FilesystemUtils
, GetToolchainDirs
) {
430 BuildSettings build_settings
;
431 build_settings
.SetBuildDir(SourceDir("//out/Debug/"));
433 // The default toolchain.
434 Settings
default_settings(&build_settings
, "");
435 Label
default_toolchain_label(SourceDir("//toolchain/"), "default");
436 default_settings
.set_toolchain_label(default_toolchain_label
);
437 default_settings
.set_default_toolchain_label(default_toolchain_label
);
439 // Default toolchain out dir.
440 EXPECT_EQ("//out/Debug/",
441 GetToolchainOutputDir(&default_settings
).value());
442 EXPECT_EQ("//out/Debug/",
443 GetToolchainOutputDir(&build_settings
, default_toolchain_label
,
446 // Default toolchain gen dir.
447 EXPECT_EQ("//out/Debug/gen/",
448 GetToolchainGenDir(&default_settings
).value());
450 GetToolchainGenDirAsOutputFile(&default_settings
).value());
451 EXPECT_EQ("//out/Debug/gen/",
452 GetToolchainGenDir(&build_settings
, default_toolchain_label
,
455 // Check a secondary toolchain.
456 Settings
other_settings(&build_settings
, "two/");
457 Label
other_toolchain_label(SourceDir("//toolchain/"), "two");
458 default_settings
.set_toolchain_label(other_toolchain_label
);
459 default_settings
.set_default_toolchain_label(default_toolchain_label
);
461 // Secondary toolchain out dir.
462 EXPECT_EQ("//out/Debug/two/",
463 GetToolchainOutputDir(&other_settings
).value());
464 EXPECT_EQ("//out/Debug/two/",
465 GetToolchainOutputDir(&build_settings
, other_toolchain_label
,
468 // Secondary toolchain gen dir.
469 EXPECT_EQ("//out/Debug/two/gen/",
470 GetToolchainGenDir(&other_settings
).value());
471 EXPECT_EQ("two/gen/",
472 GetToolchainGenDirAsOutputFile(&other_settings
).value());
473 EXPECT_EQ("//out/Debug/two/gen/",
474 GetToolchainGenDir(&build_settings
, other_toolchain_label
,
478 TEST(FilesystemUtils
, GetOutDirForSourceDir
) {
479 BuildSettings build_settings
;
480 build_settings
.SetBuildDir(SourceDir("//out/Debug/"));
482 // Test the default toolchain.
483 Label
default_toolchain_label(SourceDir("//toolchain/"), "default");
484 Settings
default_settings(&build_settings
, "");
485 default_settings
.set_toolchain_label(default_toolchain_label
);
486 default_settings
.set_default_toolchain_label(default_toolchain_label
);
487 EXPECT_EQ("//out/Debug/obj/",
488 GetOutputDirForSourceDir(
489 &default_settings
, SourceDir("//")).value());
491 GetOutputDirForSourceDirAsOutputFile(
492 &default_settings
, SourceDir("//")).value());
494 EXPECT_EQ("//out/Debug/obj/foo/bar/",
495 GetOutputDirForSourceDir(
496 &default_settings
, SourceDir("//foo/bar/")).value());
497 EXPECT_EQ("obj/foo/bar/",
498 GetOutputDirForSourceDirAsOutputFile(
499 &default_settings
, SourceDir("//foo/bar/")).value());
501 // Secondary toolchain.
502 Settings
other_settings(&build_settings
, "two/");
503 other_settings
.set_toolchain_label(Label(SourceDir("//toolchain/"), "two"));
504 other_settings
.set_default_toolchain_label(default_toolchain_label
);
505 EXPECT_EQ("//out/Debug/two/obj/",
506 GetOutputDirForSourceDir(
507 &other_settings
, SourceDir("//")).value());
508 EXPECT_EQ("two/obj/",
509 GetOutputDirForSourceDirAsOutputFile(
510 &other_settings
, SourceDir("//")).value());
512 EXPECT_EQ("//out/Debug/two/obj/foo/bar/",
513 GetOutputDirForSourceDir(&other_settings
,
514 SourceDir("//foo/bar/")).value());
515 EXPECT_EQ("two/obj/foo/bar/",
516 GetOutputDirForSourceDirAsOutputFile(
517 &other_settings
, SourceDir("//foo/bar/")).value());
519 // Absolute source path
520 EXPECT_EQ("//out/Debug/obj/ABS_PATH/abs/",
521 GetOutputDirForSourceDir(
522 &default_settings
, SourceDir("/abs")).value());
523 EXPECT_EQ("obj/ABS_PATH/abs/",
524 GetOutputDirForSourceDirAsOutputFile(
525 &default_settings
, SourceDir("/abs")).value());
527 EXPECT_EQ("//out/Debug/obj/ABS_PATH/C/abs/",
528 GetOutputDirForSourceDir(
529 &default_settings
, SourceDir("/C:/abs")).value());
530 EXPECT_EQ("obj/ABS_PATH/C/abs/",
531 GetOutputDirForSourceDirAsOutputFile(
532 &default_settings
, SourceDir("/C:/abs")).value());
536 TEST(FilesystemUtils
, GetGenDirForSourceDir
) {
537 BuildSettings build_settings
;
538 build_settings
.SetBuildDir(SourceDir("//out/Debug/"));
540 // Test the default toolchain.
541 Settings
default_settings(&build_settings
, "");
542 EXPECT_EQ("//out/Debug/gen/",
543 GetGenDirForSourceDir(
544 &default_settings
, SourceDir("//")).value());
546 GetGenDirForSourceDirAsOutputFile(
547 &default_settings
, SourceDir("//")).value());
549 EXPECT_EQ("//out/Debug/gen/foo/bar/",
550 GetGenDirForSourceDir(
551 &default_settings
, SourceDir("//foo/bar/")).value());
552 EXPECT_EQ("gen/foo/bar/",
553 GetGenDirForSourceDirAsOutputFile(
554 &default_settings
, SourceDir("//foo/bar/")).value());
556 // Secondary toolchain.
557 Settings
other_settings(&build_settings
, "two/");
558 EXPECT_EQ("//out/Debug/two/gen/",
559 GetGenDirForSourceDir(
560 &other_settings
, SourceDir("//")).value());
561 EXPECT_EQ("two/gen/",
562 GetGenDirForSourceDirAsOutputFile(
563 &other_settings
, SourceDir("//")).value());
565 EXPECT_EQ("//out/Debug/two/gen/foo/bar/",
566 GetGenDirForSourceDir(
567 &other_settings
, SourceDir("//foo/bar/")).value());
568 EXPECT_EQ("two/gen/foo/bar/",
569 GetGenDirForSourceDirAsOutputFile(
570 &other_settings
, SourceDir("//foo/bar/")).value());
573 TEST(FilesystemUtils
, GetTargetDirs
) {
574 BuildSettings build_settings
;
575 build_settings
.SetBuildDir(SourceDir("//out/Debug/"));
576 Settings
settings(&build_settings
, "");
578 Target
a(&settings
, Label(SourceDir("//foo/bar/"), "baz"));
579 EXPECT_EQ("//out/Debug/obj/foo/bar/", GetTargetOutputDir(&a
).value());
580 EXPECT_EQ("obj/foo/bar/", GetTargetOutputDirAsOutputFile(&a
).value());
581 EXPECT_EQ("//out/Debug/gen/foo/bar/", GetTargetGenDir(&a
).value());
582 EXPECT_EQ("gen/foo/bar/", GetTargetGenDirAsOutputFile(&a
).value());
585 // Tests handling of output dirs when build dir is the same as the root.
586 TEST(FilesystemUtils
, GetDirForEmptyBuildDir
) {
587 BuildSettings build_settings
;
588 build_settings
.SetBuildDir(SourceDir("//"));
589 Settings
settings(&build_settings
, "");
591 EXPECT_EQ("//", GetToolchainOutputDir(&settings
).value());
592 EXPECT_EQ("//gen/", GetToolchainGenDir(&settings
).value());
593 EXPECT_EQ("gen/", GetToolchainGenDirAsOutputFile(&settings
).value());
595 GetOutputDirForSourceDir(&settings
, SourceDir("//")).value());
597 GetOutputDirForSourceDirAsOutputFile(
598 &settings
, SourceDir("//")).value());
600 GetGenDirForSourceDirAsOutputFile(
601 &settings
, SourceDir("//")).value());