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 "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "tools/gn/filesystem_utils.h" | 9 #include "tools/gn/filesystem_utils.h" |
10 | 10 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 EXPECT_EQ("foo/bar/", | 238 EXPECT_EQ("foo/bar/", |
239 RebaseSourceAbsolutePath("//a/b/foo/bar/", SourceDir("//a/b/"))); | 239 RebaseSourceAbsolutePath("//a/b/foo/bar/", SourceDir("//a/b/"))); |
240 | 240 |
241 // One could argue about this case. Since the input doesn't have a slash it | 241 // One could argue about this case. Since the input doesn't have a slash it |
242 // would normally not be treated like a directory and we'd go up, which is | 242 // would normally not be treated like a directory and we'd go up, which is |
243 // simpler. However, since it matches the output directory's name, we could | 243 // simpler. However, since it matches the output directory's name, we could |
244 // potentially infer that it's the same and return "." for this. | 244 // potentially infer that it's the same and return "." for this. |
245 EXPECT_EQ("../bar", | 245 EXPECT_EQ("../bar", |
246 RebaseSourceAbsolutePath("//foo/bar", SourceDir("//foo/bar/"))); | 246 RebaseSourceAbsolutePath("//foo/bar", SourceDir("//foo/bar/"))); |
247 } | 247 } |
| 248 |
| 249 TEST(FilesystemUtils, DirectoryWithNoLastSlash) { |
| 250 EXPECT_EQ("", DirectoryWithNoLastSlash(SourceDir())); |
| 251 EXPECT_EQ("/.", DirectoryWithNoLastSlash(SourceDir("/"))); |
| 252 EXPECT_EQ("//.", DirectoryWithNoLastSlash(SourceDir("//"))); |
| 253 EXPECT_EQ("//foo", DirectoryWithNoLastSlash(SourceDir("//foo/"))); |
| 254 EXPECT_EQ("/bar", DirectoryWithNoLastSlash(SourceDir("/bar/"))); |
| 255 } |
| 256 |
| 257 TEST(FilesystemUtils, GetToolchainDirs) { |
| 258 BuildSettings build_settings; |
| 259 build_settings.SetBuildDir(SourceDir("//out/Debug/")); |
| 260 |
| 261 Settings default_settings(&build_settings, ""); |
| 262 EXPECT_EQ("//out/Debug/", |
| 263 GetToolchainOutputDir(&default_settings).value()); |
| 264 EXPECT_EQ("//out/Debug/gen/", |
| 265 GetToolchainGenDir(&default_settings).value()); |
| 266 |
| 267 Settings other_settings(&build_settings, "two"); |
| 268 EXPECT_EQ("//out/Debug/two/", |
| 269 GetToolchainOutputDir(&other_settings).value()); |
| 270 EXPECT_EQ("//out/Debug/two/gen/", |
| 271 GetToolchainGenDir(&other_settings).value()); |
| 272 } |
| 273 |
| 274 TEST(FilesystemUtils, GetOutDirForSourceDir) { |
| 275 BuildSettings build_settings; |
| 276 build_settings.SetBuildDir(SourceDir("//out/Debug/")); |
| 277 |
| 278 // Test the default toolchain. |
| 279 Settings default_settings(&build_settings, ""); |
| 280 EXPECT_EQ("//out/Debug/obj/", |
| 281 GetOutputDirForSourceDir(&default_settings, |
| 282 SourceDir("//")).value()); |
| 283 EXPECT_EQ("//out/Debug/obj/foo/bar/", |
| 284 GetOutputDirForSourceDir(&default_settings, |
| 285 SourceDir("//foo/bar/")).value()); |
| 286 |
| 287 // Secondary toolchain. |
| 288 Settings other_settings(&build_settings, "two"); |
| 289 EXPECT_EQ("//out/Debug/two/obj/", |
| 290 GetOutputDirForSourceDir(&other_settings, SourceDir("//")).value()); |
| 291 EXPECT_EQ("//out/Debug/two/obj/foo/bar/", |
| 292 GetOutputDirForSourceDir(&other_settings, |
| 293 SourceDir("//foo/bar/")).value()); |
| 294 } |
| 295 |
| 296 TEST(FilesystemUtils, GetGenDirForSourceDir) { |
| 297 BuildSettings build_settings; |
| 298 build_settings.SetBuildDir(SourceDir("//out/Debug/")); |
| 299 |
| 300 // Test the default toolchain. |
| 301 Settings default_settings(&build_settings, ""); |
| 302 EXPECT_EQ("//out/Debug/gen/", |
| 303 GetGenDirForSourceDir(&default_settings, SourceDir("//")).value()); |
| 304 EXPECT_EQ("//out/Debug/gen/foo/bar/", |
| 305 GetGenDirForSourceDir(&default_settings, |
| 306 SourceDir("//foo/bar/")).value()); |
| 307 |
| 308 // Secondary toolchain. |
| 309 Settings other_settings(&build_settings, "two"); |
| 310 EXPECT_EQ("//out/Debug/two/gen/", |
| 311 GetGenDirForSourceDir(&other_settings, SourceDir("//")).value()); |
| 312 EXPECT_EQ("//out/Debug/two/gen/foo/bar/", |
| 313 GetGenDirForSourceDir(&other_settings, |
| 314 SourceDir("//foo/bar/")).value()); |
| 315 } |
| 316 |
| 317 // Tests handling of output dirs when build dir is the same as the root. |
| 318 TEST(FilesystemUtils, GetDirForEmptyBuildDir) { |
| 319 BuildSettings build_settings; |
| 320 build_settings.SetBuildDir(SourceDir("//")); |
| 321 Settings settings(&build_settings, ""); |
| 322 |
| 323 EXPECT_EQ("//", GetToolchainOutputDir(&settings).value()); |
| 324 EXPECT_EQ("//gen/", GetToolchainGenDir(&settings).value()); |
| 325 EXPECT_EQ("//obj/", |
| 326 GetOutputDirForSourceDir(&settings, SourceDir("//")).value()); |
| 327 EXPECT_EQ("//gen/", |
| 328 GetGenDirForSourceDir(&settings, SourceDir("//")).value()); |
| 329 } |
OLD | NEW |