| 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/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/strings/string_util.h" | 6 #include "base/strings/string_util.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "tools/gn/filesystem_utils.h" | 10 #include "tools/gn/filesystem_utils.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 EXPECT_TRUE( | 112 EXPECT_TRUE( |
| 113 EnsureStringIsInOutputDir(output_dir, "//out/Debug/foo", nullptr, &err)); | 113 EnsureStringIsInOutputDir(output_dir, "//out/Debug/foo", nullptr, &err)); |
| 114 EXPECT_FALSE(err.has_error()); | 114 EXPECT_FALSE(err.has_error()); |
| 115 | 115 |
| 116 // Pattern but no template expansions are allowed. | 116 // Pattern but no template expansions are allowed. |
| 117 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "{{source_gen_dir}}", | 117 EXPECT_FALSE(EnsureStringIsInOutputDir(output_dir, "{{source_gen_dir}}", |
| 118 nullptr, &err)); | 118 nullptr, &err)); |
| 119 EXPECT_TRUE(err.has_error()); | 119 EXPECT_TRUE(err.has_error()); |
| 120 } | 120 } |
| 121 | 121 |
| 122 TEST(FilesystemUtils, ComputeStringInOutputDir) { |
| 123 SourceDir out_d("//out/Debug/"); |
| 124 SourceFile foo("//foo"); |
| 125 SourceFile debugit("//out/Debugit"); |
| 126 SourceFile out_less("//out/Debug"); |
| 127 |
| 128 // Some outside. |
| 129 Err err; |
| 130 EXPECT_EQ("", ComputeStringInOutputDir(out_d, foo, &err)); |
| 131 EXPECT_TRUE(err.has_error()); |
| 132 |
| 133 err = Err(); |
| 134 EXPECT_EQ("", ComputeStringInOutputDir(out_d, debugit, &err)); |
| 135 EXPECT_TRUE(err.has_error()); |
| 136 |
| 137 // Some inside. |
| 138 err = Err(); |
| 139 EXPECT_EQ("", ComputeStringInOutputDir(out_d, out_less, &err)); |
| 140 EXPECT_TRUE(err.has_error()); |
| 141 |
| 142 err = Err(); |
| 143 const char * const r_a = "a"; |
| 144 SourceFile a("//out/Debug/a"); |
| 145 EXPECT_EQ(r_a, ComputeStringInOutputDir(out_d, a, &err)); |
| 146 EXPECT_FALSE(err.has_error()); |
| 147 |
| 148 err = Err(); |
| 149 const char * const r_ofoo = "foo"; |
| 150 SourceFile ofoo("//out/Debug/foo"); |
| 151 EXPECT_EQ(r_ofoo, ComputeStringInOutputDir(out_d, ofoo, &err)); |
| 152 EXPECT_FALSE(err.has_error()); |
| 153 |
| 154 err = Err(); |
| 155 const char * const r_olong = "super-cal/bong/pas"; |
| 156 SourceFile olong("//out/Debug/super-cal/bong/pas"); |
| 157 EXPECT_EQ(r_olong, ComputeStringInOutputDir(out_d, olong, &err)); |
| 158 EXPECT_FALSE(err.has_error()); |
| 159 |
| 160 // Pattern but no template expansions are allowed. |
| 161 SourceFile wrong("//{{source_gen_dir}}"); |
| 162 EXPECT_EQ("", ComputeStringInOutputDir(out_d, wrong, &err)); |
| 163 EXPECT_TRUE(err.has_error()); |
| 164 |
| 165 } |
| 166 |
| 122 TEST(FilesystemUtils, IsPathAbsolute) { | 167 TEST(FilesystemUtils, IsPathAbsolute) { |
| 123 EXPECT_TRUE(IsPathAbsolute("/foo/bar")); | 168 EXPECT_TRUE(IsPathAbsolute("/foo/bar")); |
| 124 EXPECT_TRUE(IsPathAbsolute("/")); | 169 EXPECT_TRUE(IsPathAbsolute("/")); |
| 125 EXPECT_FALSE(IsPathAbsolute("")); | 170 EXPECT_FALSE(IsPathAbsolute("")); |
| 126 EXPECT_FALSE(IsPathAbsolute("//")); | 171 EXPECT_FALSE(IsPathAbsolute("//")); |
| 127 EXPECT_FALSE(IsPathAbsolute("//foo/bar")); | 172 EXPECT_FALSE(IsPathAbsolute("//foo/bar")); |
| 128 | 173 |
| 129 #if defined(OS_WIN) | 174 #if defined(OS_WIN) |
| 130 EXPECT_TRUE(IsPathAbsolute("C:/foo")); | 175 EXPECT_TRUE(IsPathAbsolute("C:/foo")); |
| 131 EXPECT_TRUE(IsPathAbsolute("C:/")); | 176 EXPECT_TRUE(IsPathAbsolute("C:/")); |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 EXPECT_EQ("gen/", GetToolchainGenDirAsOutputFile(&settings).value()); | 633 EXPECT_EQ("gen/", GetToolchainGenDirAsOutputFile(&settings).value()); |
| 589 EXPECT_EQ("//obj/", | 634 EXPECT_EQ("//obj/", |
| 590 GetOutputDirForSourceDir(&settings, SourceDir("//")).value()); | 635 GetOutputDirForSourceDir(&settings, SourceDir("//")).value()); |
| 591 EXPECT_EQ("obj/", | 636 EXPECT_EQ("obj/", |
| 592 GetOutputDirForSourceDirAsOutputFile( | 637 GetOutputDirForSourceDirAsOutputFile( |
| 593 &settings, SourceDir("//")).value()); | 638 &settings, SourceDir("//")).value()); |
| 594 EXPECT_EQ("gen/", | 639 EXPECT_EQ("gen/", |
| 595 GetGenDirForSourceDirAsOutputFile( | 640 GetGenDirForSourceDirAsOutputFile( |
| 596 &settings, SourceDir("//")).value()); | 641 &settings, SourceDir("//")).value()); |
| 597 } | 642 } |
| OLD | NEW |