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