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

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

Issue 630223002: gn: Support build directories outside the source tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch that compiles and passes unit tests on both Windows and Linux 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/source_dir.cc ('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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 #include "tools/gn/source_dir.h" 6 #include "tools/gn/source_dir.h"
7 #include "tools/gn/source_file.h" 7 #include "tools/gn/source_file.h"
8 8
9 TEST(SourceDir, ResolveRelativeFile) { 9 TEST(SourceDir, ResolveRelativeFile) {
10 SourceDir base("//base/"); 10 SourceDir base("//base/");
11 #if defined(OS_WIN)
12 base::StringPiece source_root("C:/source/root");
13 #else
14 base::StringPiece source_root("/source/root");
15 #endif
11 16
12 // Empty input is an error. 17 // Empty input is an error.
13 EXPECT_TRUE(base.ResolveRelativeFile("") == SourceFile()); 18 EXPECT_TRUE(base.ResolveRelativeFile("", source_root) == SourceFile());
14 19
15 // These things are directories, so should be an error. 20 // These things are directories, so should be an error.
16 EXPECT_TRUE(base.ResolveRelativeFile("//foo/bar/") == SourceFile()); 21 EXPECT_TRUE(base.ResolveRelativeFile("//foo/bar/", source_root) ==
17 EXPECT_TRUE(base.ResolveRelativeFile("bar/") == SourceFile()); 22 SourceFile());
23 EXPECT_TRUE(base.ResolveRelativeFile("bar/", source_root) ==
24 SourceFile());
18 25
19 // Absolute paths should be passed unchanged. 26 // Absolute paths should be passed unchanged.
20 EXPECT_TRUE(base.ResolveRelativeFile("//foo") == SourceFile("//foo")); 27 EXPECT_TRUE(base.ResolveRelativeFile("//foo",source_root) ==
21 EXPECT_TRUE(base.ResolveRelativeFile("/foo") == SourceFile("/foo")); 28 SourceFile("//foo"));
29 EXPECT_TRUE(base.ResolveRelativeFile("/foo", source_root) ==
30 SourceFile("/foo"));
22 31
23 // Basic relative stuff. 32 // Basic relative stuff.
24 EXPECT_TRUE(base.ResolveRelativeFile("foo") == SourceFile("//base/foo")); 33 EXPECT_TRUE(base.ResolveRelativeFile("foo", source_root) ==
25 EXPECT_TRUE(base.ResolveRelativeFile("./foo") == SourceFile("//base/foo")); 34 SourceFile("//base/foo"));
26 EXPECT_TRUE(base.ResolveRelativeFile("../foo") == SourceFile("//foo")); 35 EXPECT_TRUE(base.ResolveRelativeFile("./foo", source_root) ==
27 EXPECT_TRUE(base.ResolveRelativeFile("../../foo") == SourceFile("//foo")); 36 SourceFile("//base/foo"));
37 EXPECT_TRUE(base.ResolveRelativeFile("../foo", source_root) ==
38 SourceFile("//foo"));
39
40 // If the given relative path points outside the source root, we
41 // expect an absolute path.
42 #if defined(OS_WIN)
43 EXPECT_TRUE(base.ResolveRelativeFile("../../foo", source_root) ==
44 SourceFile("C:/source/foo"));
45 #else
46 EXPECT_TRUE(base.ResolveRelativeFile("../../foo", source_root) ==
47 SourceFile("/source/foo"));
48 #endif
28 49
29 #if defined(OS_WIN) 50 #if defined(OS_WIN)
30 // Note that we don't canonicalize the backslashes to forward slashes. 51 // Note that we don't canonicalize the backslashes to forward slashes.
31 // This could potentially be changed in the future which would mean we should 52 // This could potentially be changed in the future which would mean we should
32 // just change the expected result. 53 // just change the expected result.
33 EXPECT_TRUE(base.ResolveRelativeFile("C:\\foo\\bar.txt") == 54 EXPECT_TRUE(base.ResolveRelativeFile("C:\\foo\\bar.txt", source_root) ==
34 SourceFile("/C:/foo/bar.txt")); 55 SourceFile("/C:/foo/bar.txt"));
35 #endif 56 #endif
36 } 57 }
37 58
38 TEST(SourceDir, ResolveRelativeDir) { 59 TEST(SourceDir, ResolveRelativeDir) {
39 SourceDir base("//base/"); 60 SourceDir base("//base/");
61 #if defined(OS_WIN)
62 base::StringPiece source_root("C:/source/root");
63 #else
64 base::StringPiece source_root("/source/root");
65 #endif
40 66
41 // Empty input is an error. 67 // Empty input is an error.
42 EXPECT_TRUE(base.ResolveRelativeDir("") == SourceDir()); 68 EXPECT_TRUE(base.ResolveRelativeDir("", source_root) == SourceDir());
43 69
44 // Absolute paths should be passed unchanged. 70 // Absolute paths should be passed unchanged.
45 EXPECT_TRUE(base.ResolveRelativeDir("//foo") == SourceDir("//foo/")); 71 EXPECT_TRUE(base.ResolveRelativeDir("//foo", source_root) ==
46 EXPECT_TRUE(base.ResolveRelativeDir("/foo") == SourceDir("/foo/")); 72 SourceDir("//foo/"));
73 EXPECT_TRUE(base.ResolveRelativeDir("/foo", source_root) ==
74 SourceDir("/foo/"));
47 75
48 // Basic relative stuff. 76 // Basic relative stuff.
49 EXPECT_TRUE(base.ResolveRelativeDir("foo") == SourceDir("//base/foo/")); 77 EXPECT_TRUE(base.ResolveRelativeDir("foo", source_root) ==
50 EXPECT_TRUE(base.ResolveRelativeDir("./foo") == SourceDir("//base/foo/")); 78 SourceDir("//base/foo/"));
51 EXPECT_TRUE(base.ResolveRelativeDir("../foo") == SourceDir("//foo/")); 79 EXPECT_TRUE(base.ResolveRelativeDir("./foo", source_root) ==
52 EXPECT_TRUE(base.ResolveRelativeDir("../../foo/") == SourceDir("//foo/")); 80 SourceDir("//base/foo/"));
81 EXPECT_TRUE(base.ResolveRelativeDir("../foo", source_root) ==
82 SourceDir("//foo/"));
83
84 // If the given relative path points outside the source root, we
85 // expect an absolute path.
86 #if defined(OS_WIN)
87 EXPECT_TRUE(base.ResolveRelativeDir("../../foo", source_root) ==
88 SourceDir("C:/source/foo/"));
89 #else
90 EXPECT_TRUE(base.ResolveRelativeDir("../../foo", source_root) ==
91 SourceDir("/source/foo/"));
92 #endif
53 93
54 #if defined(OS_WIN) 94 #if defined(OS_WIN)
55 // Note that we don't canonicalize the existing backslashes to forward 95 // Note that we don't canonicalize the existing backslashes to forward
56 // slashes. This could potentially be changed in the future which would mean 96 // slashes. This could potentially be changed in the future which would mean
57 // we should just change the expected result. 97 // we should just change the expected result.
58 EXPECT_TRUE(base.ResolveRelativeDir("C:\\foo") == SourceDir("/C:/foo/")); 98 EXPECT_TRUE(base.ResolveRelativeDir("C:\\foo") == SourceDir("/C:/foo/"));
59 #endif 99 #endif
60 } 100 }
OLDNEW
« no previous file with comments | « tools/gn/source_dir.cc ('k') | tools/gn/source_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698