| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 SourceDir regular2("//foo/bar/"); | 89 SourceDir regular2("//foo/bar/"); |
| 90 EXPECT_EQ("bar", FindLastDirComponent(regular2)); | 90 EXPECT_EQ("bar", FindLastDirComponent(regular2)); |
| 91 } | 91 } |
| 92 | 92 |
| 93 TEST(FilesystemUtils, EnsureStringIsInOutputDir) { | 93 TEST(FilesystemUtils, EnsureStringIsInOutputDir) { |
| 94 SourceDir output_dir("//out/Debug/"); | 94 SourceDir output_dir("//out/Debug/"); |
| 95 | 95 |
| 96 // Some outside. | 96 // Some outside. |
| 97 Err err; | 97 Err err; |
| 98 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "//foo", Value(), false, | 98 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "//foo", Value(), &err)); |
| 99 &err)); | |
| 100 EXPECT_TRUE(err.has_error()); | 99 EXPECT_TRUE(err.has_error()); |
| 101 err = Err(); | 100 err = Err(); |
| 102 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "//out/Debugit", Value(), | 101 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "//out/Debugit", Value(), |
| 103 false, &err)); | 102 &err)); |
| 104 EXPECT_TRUE(err.has_error()); | 103 EXPECT_TRUE(err.has_error()); |
| 105 | 104 |
| 106 // Some inside. | 105 // Some inside. |
| 107 err = Err(); | 106 err = Err(); |
| 108 EXPECT_TRUE(EnsureStringIsInOutputDir(output_dir, "//out/Debug/", Value(), | 107 EXPECT_TRUE(EnsureStringIsInOutputDir(output_dir, "//out/Debug/", Value(), |
| 109 false, &err)); | 108 &err)); |
| 110 EXPECT_FALSE(err.has_error()); | 109 EXPECT_FALSE(err.has_error()); |
| 111 EXPECT_TRUE(EnsureStringIsInOutputDir(output_dir, "//out/Debug/foo", Value(), | 110 EXPECT_TRUE(EnsureStringIsInOutputDir(output_dir, "//out/Debug/foo", Value(), |
| 112 false, &err)); | 111 &err)); |
| 113 EXPECT_FALSE(err.has_error()); | 112 EXPECT_FALSE(err.has_error()); |
| 114 | 113 |
| 115 // Pattern but no template expansions are allowed. | 114 // Pattern but no template expansions are allowed. |
| 116 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "{{source_gen_dir}}", | 115 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "{{source_gen_dir}}", |
| 117 Value(), false, &err)); | 116 Value(), &err)); |
| 118 EXPECT_TRUE(err.has_error()); | |
| 119 | |
| 120 // Pattern with template expansions allowed. | |
| 121 err = Err(); | |
| 122 EXPECT_TRUE(EnsureStringIsInOutputDir(output_dir, "{{source_gen_dir}}", | |
| 123 Value(), true, &err)); | |
| 124 EXPECT_FALSE(err.has_error()); | |
| 125 | |
| 126 // Template expansion that doesn't include the absolute directory. | |
| 127 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "{{source}}", | |
| 128 Value(), true, &err)); | |
| 129 EXPECT_TRUE(err.has_error()); | |
| 130 err = Err(); | |
| 131 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, | |
| 132 "{{source_root_relative_dir}}", | |
| 133 Value(), true, &err)); | |
| 134 EXPECT_TRUE(err.has_error()); | 117 EXPECT_TRUE(err.has_error()); |
| 135 } | 118 } |
| 136 | 119 |
| 137 TEST(FilesystemUtils, IsPathAbsolute) { | 120 TEST(FilesystemUtils, IsPathAbsolute) { |
| 138 EXPECT_TRUE(IsPathAbsolute("/foo/bar")); | 121 EXPECT_TRUE(IsPathAbsolute("/foo/bar")); |
| 139 EXPECT_TRUE(IsPathAbsolute("/")); | 122 EXPECT_TRUE(IsPathAbsolute("/")); |
| 140 EXPECT_FALSE(IsPathAbsolute("")); | 123 EXPECT_FALSE(IsPathAbsolute("")); |
| 141 EXPECT_FALSE(IsPathAbsolute("//")); | 124 EXPECT_FALSE(IsPathAbsolute("//")); |
| 142 EXPECT_FALSE(IsPathAbsolute("//foo/bar")); | 125 EXPECT_FALSE(IsPathAbsolute("//foo/bar")); |
| 143 | 126 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 build_settings.SetBuildDir(SourceDir("//")); | 419 build_settings.SetBuildDir(SourceDir("//")); |
| 437 Settings settings(&build_settings, ""); | 420 Settings settings(&build_settings, ""); |
| 438 | 421 |
| 439 EXPECT_EQ("//", GetToolchainOutputDir(&settings).value()); | 422 EXPECT_EQ("//", GetToolchainOutputDir(&settings).value()); |
| 440 EXPECT_EQ("//gen/", GetToolchainGenDir(&settings).value()); | 423 EXPECT_EQ("//gen/", GetToolchainGenDir(&settings).value()); |
| 441 EXPECT_EQ("//obj/", | 424 EXPECT_EQ("//obj/", |
| 442 GetOutputDirForSourceDir(&settings, SourceDir("//")).value()); | 425 GetOutputDirForSourceDir(&settings, SourceDir("//")).value()); |
| 443 EXPECT_EQ("//gen/", | 426 EXPECT_EQ("//gen/", |
| 444 GetGenDirForSourceDir(&settings, SourceDir("//")).value()); | 427 GetGenDirForSourceDir(&settings, SourceDir("//")).value()); |
| 445 } | 428 } |
| OLD | NEW |