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"
11 class GetLabelInfoTest
: public testing::Test
{
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
));
26 Value result
= functions::RunGetLabelInfo(setup_
.scope(), &function
,
28 if (err
.has_error()) {
29 EXPECT_TRUE(result
.type() == Value::NONE
);
32 return result
.string_value();
36 // Note: TestWithScope's default toolchain is "//toolchain:default" and
37 // output dir is "//out/Debug".
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"));
53 TEST_F(GetLabelInfoTest
, Dir
) {
54 EXPECT_EQ("//src/foo", Call(":name", "dir"));
55 EXPECT_EQ("//foo/bar", Call("//foo/bar:baz", "dir"));
58 TEST_F(GetLabelInfoTest
, RootOutDir
) {
59 EXPECT_EQ("//out/Debug", Call(":name", "root_out_dir"));
60 EXPECT_EQ("//out/Debug/random",
61 Call(":name(//toolchain:random)", "root_out_dir"));
64 TEST_F(GetLabelInfoTest
, RootGetDir
) {
65 EXPECT_EQ("//out/Debug/gen", Call(":name", "root_gen_dir"));
66 EXPECT_EQ("//out/Debug/random/gen",
67 Call(":name(//toolchain:random)", "root_gen_dir"));
70 TEST_F(GetLabelInfoTest
, TargetOutDir
) {
71 EXPECT_EQ("//out/Debug/obj/src/foo", Call(":name", "target_out_dir"));
72 EXPECT_EQ("//out/Debug", Call(":name", "root_out_dir"));
75 TEST_F(GetLabelInfoTest
, LabelNoToolchain
) {
76 EXPECT_EQ("//src/foo:name", Call(":name", "label_no_toolchain"));
77 EXPECT_EQ("//src/foo:name",
78 Call("//src/foo:name(//toolchain:random)", "label_no_toolchain"));
81 TEST_F(GetLabelInfoTest
, LabelWithToolchain
) {
82 EXPECT_EQ("//src/foo:name(//toolchain:default)",
83 Call(":name", "label_with_toolchain"));
84 EXPECT_EQ("//src/foo:name(//toolchain:random)",
85 Call(":name(//toolchain:random)", "label_with_toolchain"));
88 TEST_F(GetLabelInfoTest
, Toolchain
) {
89 EXPECT_EQ("//toolchain:default", Call(":name", "toolchain"));
90 EXPECT_EQ("//toolchain:random",
91 Call(":name(//toolchain:random)", "toolchain"));