1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/gn/functions.h"
#include "tools/gn/test_with_scope.h"
namespace {
class GetLabelInfoTest : public testing::Test {
public:
GetLabelInfoTest() : testing::Test() {
setup_.scope()->set_source_dir(SourceDir("//src/foo/"));
}
// Convenience wrapper to call GetLabelInfo.
std::string Call(const std::string& label, const std::string& what) {
FunctionCallNode function;
std::vector<Value> args;
args.push_back(Value(nullptr, label));
args.push_back(Value(nullptr, what));
Err err;
Value result = functions::RunGetLabelInfo(setup_.scope(), &function,
args, &err);
if (err.has_error()) {
EXPECT_TRUE(result.type() == Value::NONE);
return std::string();
}
return result.string_value();
}
protected:
// Note: TestWithScope's default toolchain is "//toolchain:default" and
// output dir is "//out/Debug".
TestWithScope setup_;
};
} // namespace
TEST_F(GetLabelInfoTest, BadInput) {
EXPECT_EQ("", Call(":name", "incorrect_value"));
EXPECT_EQ("", Call("", "name"));
}
TEST_F(GetLabelInfoTest, Name) {
EXPECT_EQ("name", Call(":name", "name"));
EXPECT_EQ("name", Call("//foo/bar:name", "name"));
}
TEST_F(GetLabelInfoTest, Dir) {
EXPECT_EQ("//src/foo", Call(":name", "dir"));
EXPECT_EQ("//foo/bar", Call("//foo/bar:baz", "dir"));
}
TEST_F(GetLabelInfoTest, RootOutDir) {
EXPECT_EQ("//out/Debug", Call(":name", "root_out_dir"));
EXPECT_EQ("//out/Debug/random",
Call(":name(//toolchain:random)", "root_out_dir"));
}
TEST_F(GetLabelInfoTest, RootGetDir) {
EXPECT_EQ("//out/Debug/gen", Call(":name", "root_gen_dir"));
EXPECT_EQ("//out/Debug/random/gen",
Call(":name(//toolchain:random)", "root_gen_dir"));
}
TEST_F(GetLabelInfoTest, TargetOutDir) {
EXPECT_EQ("//out/Debug/obj/src/foo", Call(":name", "target_out_dir"));
EXPECT_EQ("//out/Debug", Call(":name", "root_out_dir"));
}
TEST_F(GetLabelInfoTest, LabelNoToolchain) {
EXPECT_EQ("//src/foo:name", Call(":name", "label_no_toolchain"));
EXPECT_EQ("//src/foo:name",
Call("//src/foo:name(//toolchain:random)", "label_no_toolchain"));
}
TEST_F(GetLabelInfoTest, LabelWithToolchain) {
EXPECT_EQ("//src/foo:name(//toolchain:default)",
Call(":name", "label_with_toolchain"));
EXPECT_EQ("//src/foo:name(//toolchain:random)",
Call(":name(//toolchain:random)", "label_with_toolchain"));
}
TEST_F(GetLabelInfoTest, Toolchain) {
EXPECT_EQ("//toolchain:default", Call(":name", "toolchain"));
EXPECT_EQ("//toolchain:random",
Call(":name(//toolchain:random)", "toolchain"));
}
|