• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "gn/ninja_group_target_writer.h"
6 #include "gn/target.h"
7 #include "gn/test_with_scope.h"
8 #include "util/test/test.h"
9 
TEST(NinjaGroupTargetWriter,Run)10 TEST(NinjaGroupTargetWriter, Run) {
11   Err err;
12   TestWithScope setup;
13 
14   Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
15   target.set_output_type(Target::GROUP);
16   target.visibility().SetPublic();
17 
18   Target dep(setup.settings(), Label(SourceDir("//foo/"), "dep"));
19   dep.set_output_type(Target::ACTION);
20   dep.visibility().SetPublic();
21   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);
26   dep2.visibility().SetPublic();
27   dep2.SetToolchain(setup.toolchain());
28   ASSERT_TRUE(dep2.OnResolved(&err));
29 
30   Target bundle_data_dep(setup.settings(),
31                          Label(SourceDir("//foo/"), "bundle_data_dep"));
32   bundle_data_dep.sources().push_back(SourceFile("//foo/some_data.txt"));
33   bundle_data_dep.set_output_type(Target::BUNDLE_DATA);
34   bundle_data_dep.visibility().SetPublic();
35   bundle_data_dep.SetToolchain(setup.toolchain());
36   ASSERT_TRUE(bundle_data_dep.OnResolved(&err));
37 
38   Target datadep(setup.settings(), Label(SourceDir("//foo/"), "datadep"));
39   datadep.set_output_type(Target::ACTION);
40   datadep.visibility().SetPublic();
41   datadep.SetToolchain(setup.toolchain());
42   ASSERT_TRUE(datadep.OnResolved(&err));
43 
44   target.public_deps().push_back(LabelTargetPair(&dep));
45   target.public_deps().push_back(LabelTargetPair(&dep2));
46   target.public_deps().push_back(LabelTargetPair(&bundle_data_dep));
47   target.data_deps().push_back(LabelTargetPair(&datadep));
48 
49   target.SetToolchain(setup.toolchain());
50   ASSERT_TRUE(target.OnResolved(&err));
51 
52   std::ostringstream out;
53   NinjaGroupTargetWriter writer(&target, out);
54   writer.Run();
55 
56   const char expected[] =
57       "build obj/foo/bar.stamp: stamp obj/foo/dep.stamp obj/foo/dep2.stamp || "
58       "obj/foo/bundle_data_dep.stamp obj/foo/datadep.stamp\n";
59   EXPECT_EQ(expected, out.str());
60 }
61