| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.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/err.h" | 10 #include "tools/gn/err.h" |
| 11 #include "tools/gn/label.h" | 11 #include "tools/gn/label.h" |
| 12 #include "tools/gn/value.h" | 12 #include "tools/gn/value.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 struct ParseDepStringCase { | 16 struct ParseDepStringCase { |
| 17 const char* cur_dir; | 17 const char* cur_dir; |
| 18 const char* str; | 18 const char* str; |
| 19 bool success; | 19 bool success; |
| 20 const char* expected_dir; | 20 const char* expected_dir; |
| 21 const char* expected_name; | 21 const char* expected_name; |
| 22 const char* expected_toolchain_dir; | 22 const char* expected_toolchain_dir; |
| 23 const char* expected_toolchain_name; | 23 const char* expected_toolchain_name; |
| 24 }; | 24 }; |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 TEST(Label, Resolve) { | 28 TEST(Label, Resolve) { |
| 29 ParseDepStringCase cases[] = { | 29 ParseDepStringCase cases[] = { |
| 30 // cur input succ expected dir n
ame tc dir tc name | 30 {"//chrome/", "", false, "", "", "", ""}, |
| 31 { "//chrome/", "", false, "", "
", "", "" }, | 31 {"//chrome/", "/", false, "", "", "", ""}, |
| 32 { "//chrome/", "/", false, "", "
", "", "" }, | 32 {"//chrome/", ":", false, "", "", "", ""}, |
| 33 { "//chrome/", ":", false, "", "
", "", "" }, | 33 {"//chrome/", "/:", false, "", "", "", ""}, |
| 34 { "//chrome/", "/:", false, "", "
", "", "" }, | 34 {"//chrome/", "blah", true, "//chrome/blah/", "blah", "//t/", "d"}, |
| 35 { "//chrome/", "blah", true, "//chrome/blah/", "
blah", "//t/", "d" }, | 35 {"//chrome/", "blah:bar", true, "//chrome/blah/", "bar", "//t/", "d"}, |
| 36 { "//chrome/", "blah:bar", true, "//chrome/blah/", "
bar", "//t/", "d" }, | 36 // Absolute paths. |
| 37 // Absolute paths. | 37 {"//chrome/", "/chrome:bar", true, "/chrome/", "bar", "//t/", "d"}, |
| 38 { "//chrome/", "/chrome:bar", true , "/chrome/", "
bar", "//t/", "d" }, | 38 {"//chrome/", "/chrome/:bar", true, "/chrome/", "bar", "//t/", "d"}, |
| 39 { "//chrome/", "/chrome/:bar", true, "/chrome/", "
bar", "//t/", "d" }, | |
| 40 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
| 41 { "//chrome/", "/C:/chrome:bar", true , "/C:/chrome/", "
bar", "//t/", "d" }, | 40 {"//chrome/", "/C:/chrome:bar", true, "/C:/chrome/", "bar", "//t/", "d"}, |
| 42 { "//chrome/", "/C:/chrome/:bar", true, "/C:/chrome/", "
bar", "//t/", "d" }, | 41 {"//chrome/", "/C:/chrome/:bar", true, "/C:/chrome/", "bar", "//t/", "d"}, |
| 43 { "//chrome/", "C:/chrome:bar", false, "", "
", "", "" }, | 42 {"//chrome/", "C:/chrome:bar", true, "/C:/chrome/", "bar", "//t/", "d"}, |
| 44 #endif | 43 #endif |
| 45 // Refers to root dir. | 44 // Refers to root dir. |
| 46 { "//chrome/", "//:bar", true, "//", "
bar", "//t/", "d" }, | 45 {"//chrome/", "//:bar", true, "//", "bar", "//t/", "d"}, |
| 47 // Implicit directory | 46 // Implicit directory |
| 48 { "//chrome/", ":bar", true, "//chrome/", "
bar", "//t/", "d" }, | 47 {"//chrome/", ":bar", true, "//chrome/", "bar", "//t/", "d"}, |
| 49 { "//chrome/renderer/", ":bar", true, "//chrome/renderer/", "
bar", "//t/", "d" }, | 48 {"//chrome/renderer/", ":bar", true, "//chrome/renderer/", "bar", "//t/", |
| 50 // Implicit names. | 49 "d"}, |
| 51 { "//chrome/", "//base", true, "//base/", "
base", "//t/", "d" }, | 50 // Implicit names. |
| 52 { "//chrome/", "//base/i18n", true, "//base/i18n/", "
i18n", "//t/", "d" }, | 51 {"//chrome/", "//base", true, "//base/", "base", "//t/", "d"}, |
| 53 { "//chrome/", "//base/i18n:foo", true, "//base/i18n/", "
foo", "//t/", "d" }, | 52 {"//chrome/", "//base/i18n", true, "//base/i18n/", "i18n", "//t/", "d"}, |
| 54 { "//chrome/", "//", false, "", "
", "", "" }, | 53 {"//chrome/", "//base/i18n:foo", true, "//base/i18n/", "foo", "//t/", "d"}, |
| 55 // Toolchain parsing. | 54 {"//chrome/", "//", false, "", "", "", ""}, |
| 56 { "//chrome/", "//chrome:bar(//t:n)", true, "//chrome/", "
bar", "//t/", "n" }, | 55 // Toolchain parsing. |
| 57 { "//chrome/", "//chrome:bar(//t)", true, "//chrome/", "
bar", "//t/", "t" }, | 56 {"//chrome/", "//chrome:bar(//t:n)", true, "//chrome/", "bar", "//t/", "n"}, |
| 58 { "//chrome/", "//chrome:bar(//t:)", true, "//chrome/", "
bar", "//t/", "t" }, | 57 {"//chrome/", "//chrome:bar(//t)", true, "//chrome/", "bar", "//t/", "t"}, |
| 59 { "//chrome/", "//chrome:bar()", true, "//chrome/", "
bar", "//t/", "d" }, | 58 {"//chrome/", "//chrome:bar(//t:)", true, "//chrome/", "bar", "//t/", "t"}, |
| 60 { "//chrome/", "//chrome:bar(foo)", true, "//chrome/", "
bar", "//chrome/foo/", "foo" }, | 59 {"//chrome/", "//chrome:bar()", true, "//chrome/", "bar", "//t/", "d"}, |
| 61 { "//chrome/", "//chrome:bar(:foo)", true, "//chrome/", "
bar", "//chrome/", "foo" }, | 60 {"//chrome/", "//chrome:bar(foo)", true, "//chrome/", "bar", |
| 62 // TODO(brettw) it might be nice to make this an error: | 61 "//chrome/foo/", "foo"}, |
| 63 //{ "//chrome/", "//chrome:bar())", false, "",
"", "", "" }, | 62 {"//chrome/", "//chrome:bar(:foo)", true, "//chrome/", "bar", "//chrome/", |
| 64 { "//chrome/", "//chrome:bar(//t:bar(tc))", false, "", "
", "", "" }, | 63 "foo"}, |
| 65 { "//chrome/", "//chrome:bar(()", false, "", "
", "", "" }, | 64 // TODO(brettw) it might be nice to make this an error: |
| 66 { "//chrome/", "(t:b)", false, "", "
", "", "" }, | 65 //{"//chrome/", "//chrome:bar())", false, "", "", "", "" }, |
| 67 { "//chrome/", ":bar(//t/b)", true, "//chrome/", "
bar", "//t/b/", "b" }, | 66 {"//chrome/", "//chrome:bar(//t:bar(tc))", false, "", "", "", ""}, |
| 68 { "//chrome/", ":bar(/t/b)", true, "//chrome/", "
bar", "/t/b/", "b" }, | 67 {"//chrome/", "//chrome:bar(()", false, "", "", "", ""}, |
| 69 { "//chrome/", ":bar(t/b)", true, "//chrome/", "
bar", "//chrome/t/b/", "b" }, | 68 {"//chrome/", "(t:b)", false, "", "", "", ""}, |
| 69 {"//chrome/", ":bar(//t/b)", true, "//chrome/", "bar", "//t/b/", "b"}, |
| 70 {"//chrome/", ":bar(/t/b)", true, "//chrome/", "bar", "/t/b/", "b"}, |
| 71 {"//chrome/", ":bar(t/b)", true, "//chrome/", "bar", "//chrome/t/b/", "b"}, |
| 70 }; | 72 }; |
| 71 | 73 |
| 72 Label default_toolchain(SourceDir("//t/"), "d"); | 74 Label default_toolchain(SourceDir("//t/"), "d"); |
| 73 | 75 |
| 74 for (size_t i = 0; i < arraysize(cases); i++) { | 76 for (size_t i = 0; i < arraysize(cases); i++) { |
| 75 const ParseDepStringCase& cur = cases[i]; | 77 const ParseDepStringCase& cur = cases[i]; |
| 76 | 78 |
| 77 std::string location, name; | 79 std::string location, name; |
| 78 Err err; | 80 Err err; |
| 79 Value v(nullptr, Value::STRING); | 81 Value v(nullptr, Value::STRING); |
| 80 v.string_value() = cur.str; | 82 v.string_value() = cur.str; |
| 81 Label result = | 83 Label result = |
| 82 Label::Resolve(SourceDir(cur.cur_dir), default_toolchain, v, &err); | 84 Label::Resolve(SourceDir(cur.cur_dir), default_toolchain, v, &err); |
| 83 EXPECT_EQ(cur.success, !err.has_error()) << i << " " << cur.str; | 85 EXPECT_EQ(cur.success, !err.has_error()) << i << " " << cur.str; |
| 84 if (!err.has_error() && cur.success) { | 86 if (!err.has_error() && cur.success) { |
| 85 EXPECT_EQ(cur.expected_dir, result.dir().value()) | 87 EXPECT_EQ(cur.expected_dir, result.dir().value()) << i << " " << cur.str; |
| 86 << i << " " << cur.str; | 88 EXPECT_EQ(cur.expected_name, result.name()) << i << " " << cur.str; |
| 87 EXPECT_EQ(cur.expected_name, result.name()) | 89 EXPECT_EQ(cur.expected_toolchain_dir, result.toolchain_dir().value()) |
| 88 << i << " " << cur.str; | |
| 89 EXPECT_EQ(cur.expected_toolchain_dir, | |
| 90 result.toolchain_dir().value()) | |
| 91 << i << " " << cur.str; | 90 << i << " " << cur.str; |
| 92 EXPECT_EQ(cur.expected_toolchain_name, result.toolchain_name()) | 91 EXPECT_EQ(cur.expected_toolchain_name, result.toolchain_name()) |
| 93 << i << " " << cur.str; | 92 << i << " " << cur.str; |
| 94 } | 93 } |
| 95 } | 94 } |
| 96 } | 95 } |
| OLD | NEW |