Landing Recent QUIC changes until 8/19/2015 17:00 UTC.
[chromium-blink-merge.git] / tools / gn / function_get_label_info_unittest.cc
blobddec8302c9a79ab308e59c025b858303833e55fc
1 // Copyright 2014 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/functions.h"
7 #include "tools/gn/test_with_scope.h"
9 namespace {
11 class GetLabelInfoTest : public testing::Test {
12 public:
13 GetLabelInfoTest() : testing::Test() {
14 setup_.scope()->set_source_dir(SourceDir("//src/foo/"));
17 // Convenience wrapper to call GetLabelInfo.
18 std::string Call(const std::string& label, const std::string& what) {
19 FunctionCallNode function;
21 std::vector<Value> args;
22 args.push_back(Value(nullptr, label));
23 args.push_back(Value(nullptr, what));
25 Err err;
26 Value result = functions::RunGetLabelInfo(setup_.scope(), &function,
27 args, &err);
28 if (err.has_error()) {
29 EXPECT_TRUE(result.type() == Value::NONE);
30 return std::string();
32 return result.string_value();
35 protected:
36 // Note: TestWithScope's default toolchain is "//toolchain:default" and
37 // output dir is "//out/Debug".
38 TestWithScope setup_;
41 } // namespace
43 TEST_F(GetLabelInfoTest, BadInput) {
44 EXPECT_EQ("", Call(":name", "incorrect_value"));
45 EXPECT_EQ("", Call("", "name"));
48 TEST_F(GetLabelInfoTest, Name) {
49 EXPECT_EQ("name", Call(":name", "name"));
50 EXPECT_EQ("name", Call("//foo/bar:name", "name"));
51 EXPECT_EQ("name", Call("//foo/bar:name(//other:tc)", "name"));
54 TEST_F(GetLabelInfoTest, Dir) {
55 EXPECT_EQ("//src/foo", Call(":name", "dir"));
56 EXPECT_EQ("//foo/bar", Call("//foo/bar:baz", "dir"));
57 EXPECT_EQ("//foo/bar", Call("//foo/bar:baz(//other:tc)", "dir"));
60 TEST_F(GetLabelInfoTest, RootOutDir) {
61 EXPECT_EQ("//out/Debug", Call(":name", "root_out_dir"));
62 EXPECT_EQ("//out/Debug/random",
63 Call(":name(//toolchain:random)", "root_out_dir"));
66 TEST_F(GetLabelInfoTest, RootGenDir) {
67 EXPECT_EQ("//out/Debug/gen", Call(":name", "root_gen_dir"));
68 EXPECT_EQ("//out/Debug/gen",
69 Call(":name(//toolchain:default)", "root_gen_dir"));
70 EXPECT_EQ("//out/Debug/random/gen",
71 Call(":name(//toolchain:random)", "root_gen_dir"));
74 TEST_F(GetLabelInfoTest, TargetOutDir) {
75 EXPECT_EQ("//out/Debug/obj/src/foo", Call(":name", "target_out_dir"));
76 EXPECT_EQ("//out/Debug", Call(":name", "root_out_dir"));
78 EXPECT_EQ("//out/Debug/obj/foo",
79 Call("//foo:name(//toolchain:default)", "target_out_dir"));
80 EXPECT_EQ("//out/Debug/random/obj/foo",
81 Call("//foo:name(//toolchain:random)", "target_out_dir"));
84 TEST_F(GetLabelInfoTest, LabelNoToolchain) {
85 EXPECT_EQ("//src/foo:name", Call(":name", "label_no_toolchain"));
86 EXPECT_EQ("//src/foo:name",
87 Call("//src/foo:name(//toolchain:random)", "label_no_toolchain"));
90 TEST_F(GetLabelInfoTest, LabelWithToolchain) {
91 EXPECT_EQ("//src/foo:name(//toolchain:default)",
92 Call(":name", "label_with_toolchain"));
93 EXPECT_EQ("//src/foo:name(//toolchain:random)",
94 Call(":name(//toolchain:random)", "label_with_toolchain"));
97 TEST_F(GetLabelInfoTest, Toolchain) {
98 EXPECT_EQ("//toolchain:default", Call(":name", "toolchain"));
99 EXPECT_EQ("//toolchain:random",
100 Call(":name(//toolchain:random)", "toolchain"));