blob: 9feb4bd6059efae6e381f80956946b5ae8e25b36 [file] [log] [blame]
cjhopman1b668a2e92014-09-09 16:30:401// 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.
4
5#include "testing/gtest/include/gtest/gtest.h"
6#include "tools/gn/ninja_group_target_writer.h"
7#include "tools/gn/target.h"
8#include "tools/gn/test_with_scope.h"
9
10TEST(NinjaGroupTargetWriter, Run) {
cjhopman1b668a2e92014-09-09 16:30:4011 Err err;
sdefresne3fed8052016-07-01 13:29:4712 TestWithScope setup;
cjhopman1b668a2e92014-09-09 16:30:4013
cjhopman1b668a2e92014-09-09 16:30:4014 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
cjhopman1b668a2e92014-09-09 16:30:4015 target.set_output_type(Target::GROUP);
brettwc2e821a32014-09-17 01:07:1416 target.visibility().SetPublic();
cjhopman1b668a2e92014-09-09 16:30:4017
18 Target dep(setup.settings(), Label(SourceDir("//foo/"), "dep"));
19 dep.set_output_type(Target::ACTION);
brettwc2e821a32014-09-17 01:07:1420 dep.visibility().SetPublic();
cjhopman1b668a2e92014-09-09 16:30:4021 dep.SetToolchain(setup.toolchain());
22 ASSERT_TRUE(dep.OnResolved(&err));
23
24 Target dep2(setup.settings(), Label(SourceDir("//foo/"), "dep2"));
25 dep2.set_output_type(Target::ACTION);
brettwc2e821a32014-09-17 01:07:1426 dep2.visibility().SetPublic();
cjhopman1b668a2e92014-09-09 16:30:4027 dep2.SetToolchain(setup.toolchain());
28 ASSERT_TRUE(dep2.OnResolved(&err));
29
30 Target datadep(setup.settings(), Label(SourceDir("//foo/"), "datadep"));
31 datadep.set_output_type(Target::ACTION);
brettwc2e821a32014-09-17 01:07:1432 datadep.visibility().SetPublic();
cjhopman1b668a2e92014-09-09 16:30:4033 datadep.SetToolchain(setup.toolchain());
34 ASSERT_TRUE(datadep.OnResolved(&err));
35
brettwc2e821a32014-09-17 01:07:1436 target.public_deps().push_back(LabelTargetPair(&dep));
37 target.public_deps().push_back(LabelTargetPair(&dep2));
38 target.data_deps().push_back(LabelTargetPair(&datadep));
cjhopman1b668a2e92014-09-09 16:30:4039
40 target.SetToolchain(setup.toolchain());
41 ASSERT_TRUE(target.OnResolved(&err));
42
43 std::ostringstream out;
44 NinjaGroupTargetWriter writer(&target, out);
45 writer.Run();
46
47 const char expected[] =
48 "build obj/foo/bar.stamp: stamp obj/foo/dep.stamp obj/foo/dep2.stamp || obj/foo/datadep.stamp\n";
49 EXPECT_EQ(expected, out.str());
50}