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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 SourceDir srcroot("//"); | 83 SourceDir srcroot("//"); |
84 EXPECT_EQ("", FindLastDirComponent(srcroot)); | 84 EXPECT_EQ("", FindLastDirComponent(srcroot)); |
85 | 85 |
86 SourceDir regular1("//foo/"); | 86 SourceDir regular1("//foo/"); |
87 EXPECT_EQ("foo", FindLastDirComponent(regular1)); | 87 EXPECT_EQ("foo", FindLastDirComponent(regular1)); |
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) { |
| 94 SourceDir output_dir("//out/Debug/"); |
| 95 |
| 96 // Some outside. |
| 97 Err err; |
| 98 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "//foo", Value(), false, |
| 99 &err)); |
| 100 EXPECT_TRUE(err.has_error()); |
| 101 err = Err(); |
| 102 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "//out/Debugit", Value(), |
| 103 false, &err)); |
| 104 EXPECT_TRUE(err.has_error()); |
| 105 |
| 106 // Some inside. |
| 107 err = Err(); |
| 108 EXPECT_TRUE(EnsureStringIsInOutputDir(output_dir, "//out/Debug/", Value(), |
| 109 false, &err)); |
| 110 EXPECT_FALSE(err.has_error()); |
| 111 EXPECT_TRUE(EnsureStringIsInOutputDir(output_dir, "//out/Debug/foo", Value(), |
| 112 false, &err)); |
| 113 EXPECT_FALSE(err.has_error()); |
| 114 |
| 115 // Pattern but no template expansions are allowed. |
| 116 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "{{source_gen_dir}}", |
| 117 Value(), false, &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()); |
| 135 } |
| 136 |
93 TEST(FilesystemUtils, IsPathAbsolute) { | 137 TEST(FilesystemUtils, IsPathAbsolute) { |
94 EXPECT_TRUE(IsPathAbsolute("/foo/bar")); | 138 EXPECT_TRUE(IsPathAbsolute("/foo/bar")); |
95 EXPECT_TRUE(IsPathAbsolute("/")); | 139 EXPECT_TRUE(IsPathAbsolute("/")); |
96 EXPECT_FALSE(IsPathAbsolute("")); | 140 EXPECT_FALSE(IsPathAbsolute("")); |
97 EXPECT_FALSE(IsPathAbsolute("//")); | 141 EXPECT_FALSE(IsPathAbsolute("//")); |
98 EXPECT_FALSE(IsPathAbsolute("//foo/bar")); | 142 EXPECT_FALSE(IsPathAbsolute("//foo/bar")); |
99 | 143 |
100 #if defined(OS_WIN) | 144 #if defined(OS_WIN) |
101 EXPECT_TRUE(IsPathAbsolute("C:/foo")); | 145 EXPECT_TRUE(IsPathAbsolute("C:/foo")); |
102 EXPECT_TRUE(IsPathAbsolute("C:/")); | 146 EXPECT_TRUE(IsPathAbsolute("C:/")); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 build_settings.SetBuildDir(SourceDir("//")); | 436 build_settings.SetBuildDir(SourceDir("//")); |
393 Settings settings(&build_settings, ""); | 437 Settings settings(&build_settings, ""); |
394 | 438 |
395 EXPECT_EQ("//", GetToolchainOutputDir(&settings).value()); | 439 EXPECT_EQ("//", GetToolchainOutputDir(&settings).value()); |
396 EXPECT_EQ("//gen/", GetToolchainGenDir(&settings).value()); | 440 EXPECT_EQ("//gen/", GetToolchainGenDir(&settings).value()); |
397 EXPECT_EQ("//obj/", | 441 EXPECT_EQ("//obj/", |
398 GetOutputDirForSourceDir(&settings, SourceDir("//")).value()); | 442 GetOutputDirForSourceDir(&settings, SourceDir("//")).value()); |
399 EXPECT_EQ("//gen/", | 443 EXPECT_EQ("//gen/", |
400 GetGenDirForSourceDir(&settings, SourceDir("//")).value()); | 444 GetGenDirForSourceDir(&settings, SourceDir("//")).value()); |
401 } | 445 } |
OLD | NEW |