OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "tools/gn/ninja_target_writer.h" | 8 #include "tools/gn/ninja_target_writer.h" |
9 #include "tools/gn/test_with_scope.h" | 9 #include "tools/gn/test_with_scope.h" |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 class TestingNinjaTargetWriter : public NinjaTargetWriter { | 13 class TestingNinjaTargetWriter : public NinjaTargetWriter { |
14 public: | 14 public: |
15 TestingNinjaTargetWriter(const Target* target, | 15 TestingNinjaTargetWriter(const Target* target, |
16 const Toolchain* toolchain, | 16 const Toolchain* toolchain, |
17 std::ostream& out) | 17 std::ostream& out) |
18 : NinjaTargetWriter(target, toolchain, out) { | 18 : NinjaTargetWriter(target, toolchain, out) { |
19 } | 19 } |
20 | 20 |
21 virtual void Run() OVERRIDE {} | 21 virtual void Run() OVERRIDE {} |
22 | 22 |
23 // Make this public so the test can call it. | 23 // Make this public so the test can call it. |
24 std::string WriteInputDepsStampAndGetDep() { | 24 std::string WriteInputDepsStampAndGetDep( |
25 return NinjaTargetWriter::WriteInputDepsStampAndGetDep(); | 25 const std::vector<const Target*>& extra_hard_deps) { |
| 26 return NinjaTargetWriter::WriteInputDepsStampAndGetDep(extra_hard_deps); |
26 } | 27 } |
27 }; | 28 }; |
28 | 29 |
29 } // namespace | 30 } // namespace |
30 | 31 |
31 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDep) { | 32 TEST(NinjaTargetWriter, WriteInputDepsStampAndGetDep) { |
32 TestWithScope setup; | 33 TestWithScope setup; |
33 | 34 |
34 // Make a base target that's a hard dep (action). | 35 // Make a base target that's a hard dep (action). |
35 Target base_target(setup.settings(), Label(SourceDir("//foo/"), "base")); | 36 Target base_target(setup.settings(), Label(SourceDir("//foo/"), "base")); |
(...skipping 15 matching lines...) Expand all Loading... |
51 action.deps().push_back(LabelTargetPair(&target)); | 52 action.deps().push_back(LabelTargetPair(&target)); |
52 | 53 |
53 base_target.OnResolved(); | 54 base_target.OnResolved(); |
54 target.OnResolved(); | 55 target.OnResolved(); |
55 action.OnResolved(); | 56 action.OnResolved(); |
56 | 57 |
57 // Input deps for the base (should be nothing, it has no hard deps). | 58 // Input deps for the base (should be nothing, it has no hard deps). |
58 { | 59 { |
59 std::ostringstream stream; | 60 std::ostringstream stream; |
60 TestingNinjaTargetWriter writer(&base_target, setup.toolchain(), stream); | 61 TestingNinjaTargetWriter writer(&base_target, setup.toolchain(), stream); |
61 std::string dep = writer.WriteInputDepsStampAndGetDep(); | 62 std::string dep = |
| 63 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); |
62 | 64 |
63 EXPECT_TRUE(dep.empty()); | 65 EXPECT_TRUE(dep.empty()); |
64 EXPECT_TRUE(stream.str().empty()); | 66 EXPECT_TRUE(stream.str().empty()); |
65 } | 67 } |
66 | 68 |
67 // Input deps for the target (should depend on the base). | 69 // Input deps for the target (should depend on the base). |
68 { | 70 { |
69 std::ostringstream stream; | 71 std::ostringstream stream; |
70 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream); | 72 TestingNinjaTargetWriter writer(&target, setup.toolchain(), stream); |
71 std::string dep = writer.WriteInputDepsStampAndGetDep(); | 73 std::string dep = |
| 74 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); |
72 | 75 |
73 EXPECT_EQ(" | obj/foo/target.inputdeps.stamp", dep); | 76 EXPECT_EQ(" | obj/foo/target.inputdeps.stamp", dep); |
74 EXPECT_EQ("obj/foo/target.inputdeps.stamp: stamp " | 77 EXPECT_EQ("obj/foo/target.inputdeps.stamp: stamp " |
75 "../../foo/input.txt obj/foo/base.stamp\n", | 78 "../../foo/input.txt obj/foo/base.stamp\n", |
76 stream.str()); | 79 stream.str()); |
77 } | 80 } |
78 | 81 |
79 // Input deps for action which should depend on the base since its a hard dep | 82 // Input deps for action which should depend on the base since its a hard dep |
80 // that is a (indirect) dependency, as well as the the action source. | 83 // that is a (indirect) dependency, as well as the the action source. |
81 { | 84 { |
82 std::ostringstream stream; | 85 std::ostringstream stream; |
83 TestingNinjaTargetWriter writer(&action, setup.toolchain(), stream); | 86 TestingNinjaTargetWriter writer(&action, setup.toolchain(), stream); |
84 std::string dep = writer.WriteInputDepsStampAndGetDep(); | 87 std::string dep = |
| 88 writer.WriteInputDepsStampAndGetDep(std::vector<const Target*>()); |
85 | 89 |
86 EXPECT_EQ(" | obj/foo/action.inputdeps.stamp", dep); | 90 EXPECT_EQ(" | obj/foo/action.inputdeps.stamp", dep); |
87 EXPECT_EQ("obj/foo/action.inputdeps.stamp: stamp " | 91 EXPECT_EQ("obj/foo/action.inputdeps.stamp: stamp " |
88 "../../foo/action_source.txt obj/foo/base.stamp\n", | 92 "../../foo/action_source.txt obj/foo/base.stamp\n", |
89 stream.str()); | 93 stream.str()); |
90 } | 94 } |
91 } | 95 } |
OLD | NEW |