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

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

Issue 1455203002: [GN] Add support to rebase_path to resolve paths above the source root. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Add tests, handle Windows sources. Created 5 years 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') | no next file » | 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/err.h" 6 #include "tools/gn/err.h"
7 #include "tools/gn/source_dir.h" 7 #include "tools/gn/source_dir.h"
8 #include "tools/gn/source_file.h" 8 #include "tools/gn/source_file.h"
9 #include "tools/gn/value.h" 9 #include "tools/gn/value.h"
10 10
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 Value(nullptr, "../foo"), &err, source_root) == SourceFile("//foo")); 54 Value(nullptr, "../foo"), &err, source_root) == SourceFile("//foo"));
55 EXPECT_FALSE(err.has_error()); 55 EXPECT_FALSE(err.has_error());
56 56
57 // If the given relative path points outside the source root, we 57 // If the given relative path points outside the source root, we
58 // expect an absolute path. 58 // expect an absolute path.
59 #if defined(OS_WIN) 59 #if defined(OS_WIN)
60 EXPECT_TRUE(base.ResolveRelativeFile( 60 EXPECT_TRUE(base.ResolveRelativeFile(
61 Value(nullptr, "../../foo"), &err, source_root) == 61 Value(nullptr, "../../foo"), &err, source_root) ==
62 SourceFile("/C:/source/foo")); 62 SourceFile("/C:/source/foo"));
63 EXPECT_FALSE(err.has_error()); 63 EXPECT_FALSE(err.has_error());
64
65 EXPECT_TRUE(base.ResolveRelativeFile(
66 Value(nullptr, "//../foo"), &err, source_root) ==
67 SourceFile("/C:/source/foo"));
68 EXPECT_FALSE(err.has_error());
69
70 EXPECT_TRUE(base.ResolveRelativeFile(
71 Value(nullptr, "//../root/foo"), &err, source_root) ==
72 SourceFile("/C:/source/root/foo"));
73 EXPECT_FALSE(err.has_error());
74
75 EXPECT_TRUE(base.ResolveRelativeFile(
76 Value(nullptr, "//../../../foo/bar"), &err, source_root) ==
77 SourceFile("/foo/bar"));
78 EXPECT_FALSE(err.has_error());
64 #else 79 #else
65 EXPECT_TRUE(base.ResolveRelativeFile( 80 EXPECT_TRUE(base.ResolveRelativeFile(
66 Value(nullptr, "../../foo"), &err, source_root) == 81 Value(nullptr, "../../foo"), &err, source_root) ==
67 SourceFile("/source/foo")); 82 SourceFile("/source/foo"));
68 EXPECT_FALSE(err.has_error()); 83 EXPECT_FALSE(err.has_error());
84
85 EXPECT_TRUE(base.ResolveRelativeFile(
86 Value(nullptr, "//../foo"), &err, source_root) ==
87 SourceFile("/source/foo"));
88 EXPECT_FALSE(err.has_error());
89
90 EXPECT_TRUE(base.ResolveRelativeFile(
91 Value(nullptr, "//../root/foo"), &err, source_root) ==
92 SourceFile("/source/root/foo"));
93 EXPECT_FALSE(err.has_error());
94
95 EXPECT_TRUE(base.ResolveRelativeFile(
96 Value(nullptr, "//../../../foo/bar"), &err, source_root) ==
97 SourceFile("/foo/bar"));
98 EXPECT_FALSE(err.has_error());
69 #endif 99 #endif
70 100
71 #if defined(OS_WIN) 101 #if defined(OS_WIN)
72 // Note that we don't canonicalize the backslashes to forward slashes. 102 // Note that we don't canonicalize the backslashes to forward slashes.
73 // This could potentially be changed in the future which would mean we should 103 // This could potentially be changed in the future which would mean we should
74 // just change the expected result. 104 // just change the expected result.
75 EXPECT_TRUE(base.ResolveRelativeFile( 105 EXPECT_TRUE(base.ResolveRelativeFile(
76 Value(nullptr, "C:\\foo\\bar.txt"), &err, source_root) == 106 Value(nullptr, "C:\\foo\\bar.txt"), &err, source_root) ==
77 SourceFile("/C:/foo/bar.txt")); 107 SourceFile("/C:/foo/bar.txt"));
78 EXPECT_FALSE(err.has_error()); 108 EXPECT_FALSE(err.has_error());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 Value(nullptr, "../foo"), &err, source_root) == SourceDir("//foo/")); 143 Value(nullptr, "../foo"), &err, source_root) == SourceDir("//foo/"));
114 EXPECT_FALSE(err.has_error()); 144 EXPECT_FALSE(err.has_error());
115 145
116 // If the given relative path points outside the source root, we 146 // If the given relative path points outside the source root, we
117 // expect an absolute path. 147 // expect an absolute path.
118 #if defined(OS_WIN) 148 #if defined(OS_WIN)
119 EXPECT_TRUE(base.ResolveRelativeDir( 149 EXPECT_TRUE(base.ResolveRelativeDir(
120 Value(nullptr, "../../foo"), &err, source_root) == 150 Value(nullptr, "../../foo"), &err, source_root) ==
121 SourceDir("/C:/source/foo/")); 151 SourceDir("/C:/source/foo/"));
122 EXPECT_FALSE(err.has_error()); 152 EXPECT_FALSE(err.has_error());
153 EXPECT_TRUE(base.ResolveRelativeDir(
154 Value(nullptr, "//../foo"), &err, source_root) ==
155 SourceDir("/C:/source/foo/"));
156 EXPECT_FALSE(err.has_error());
157 EXPECT_TRUE(base.ResolveRelativeDir(
158 Value(nullptr, "//.."), &err, source_root) ==
159 SourceDir("/C:/source/"));
160 EXPECT_FALSE(err.has_error());
123 #else 161 #else
124 EXPECT_TRUE(base.ResolveRelativeDir( 162 EXPECT_TRUE(base.ResolveRelativeDir(
125 Value(nullptr, "../../foo"), &err, source_root) == 163 Value(nullptr, "../../foo"), &err, source_root) ==
126 SourceDir("/source/foo/")); 164 SourceDir("/source/foo/"));
127 EXPECT_FALSE(err.has_error()); 165 EXPECT_FALSE(err.has_error());
166 EXPECT_TRUE(base.ResolveRelativeDir(
167 Value(nullptr, "//../foo"), &err, source_root) ==
168 SourceDir("/source/foo/"));
169 EXPECT_FALSE(err.has_error());
170 EXPECT_TRUE(base.ResolveRelativeDir(
171 Value(nullptr, "//.."), &err, source_root) ==
172 SourceDir("/source/"));
173 EXPECT_FALSE(err.has_error());
128 #endif 174 #endif
129 175
130 #if defined(OS_WIN) 176 #if defined(OS_WIN)
131 // Canonicalize the existing backslashes to forward slashes and add a 177 // Canonicalize the existing backslashes to forward slashes and add a
132 // leading slash if necessary. 178 // leading slash if necessary.
133 EXPECT_TRUE(base.ResolveRelativeDir( 179 EXPECT_TRUE(base.ResolveRelativeDir(
134 Value(nullptr, "\\C:\\foo"), &err) == SourceDir("/C:/foo/")); 180 Value(nullptr, "\\C:\\foo"), &err) == SourceDir("/C:/foo/"));
135 EXPECT_FALSE(err.has_error()); 181 EXPECT_FALSE(err.has_error());
136 EXPECT_TRUE(base.ResolveRelativeDir( 182 EXPECT_TRUE(base.ResolveRelativeDir(
137 Value(nullptr, "C:\\foo"), &err) == SourceDir("/C:/foo/")); 183 Value(nullptr, "C:\\foo"), &err) == SourceDir("/C:/foo/"));
138 EXPECT_FALSE(err.has_error()); 184 EXPECT_FALSE(err.has_error());
139 #endif 185 #endif
140 } 186 }
OLDNEW
« no previous file with comments | « tools/gn/source_dir.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698