OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <algorithm> | 5 #include <algorithm> |
6 #include <sstream> | 6 #include <sstream> |
7 | 7 |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "tools/gn/ninja_copy_target_writer.h" | 9 #include "tools/gn/ninja_copy_target_writer.h" |
10 #include "tools/gn/target.h" | 10 #include "tools/gn/target.h" |
11 #include "tools/gn/test_with_scope.h" | 11 #include "tools/gn/test_with_scope.h" |
12 | 12 |
13 // Tests multiple files with an output pattern and no toolchain dependency. | 13 // Tests multiple files with an output pattern and no toolchain dependency. |
14 TEST(NinjaCopyTargetWriter, Run) { | 14 TEST(NinjaCopyTargetWriter, Run) { |
| 15 Err err; |
15 TestWithScope setup; | 16 TestWithScope setup; |
16 Err err; | |
17 | 17 |
18 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | |
19 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 18 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
20 target.set_output_type(Target::COPY_FILES); | 19 target.set_output_type(Target::COPY_FILES); |
21 | 20 |
22 target.sources().push_back(SourceFile("//foo/input1.txt")); | 21 target.sources().push_back(SourceFile("//foo/input1.txt")); |
23 target.sources().push_back(SourceFile("//foo/input2.txt")); | 22 target.sources().push_back(SourceFile("//foo/input2.txt")); |
24 | 23 |
25 target.action_values().outputs() = | 24 target.action_values().outputs() = |
26 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out"); | 25 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out"); |
27 | 26 |
28 target.SetToolchain(setup.toolchain()); | 27 target.SetToolchain(setup.toolchain()); |
29 ASSERT_TRUE(target.OnResolved(&err)); | 28 ASSERT_TRUE(target.OnResolved(&err)); |
30 | 29 |
31 std::ostringstream out; | 30 std::ostringstream out; |
32 NinjaCopyTargetWriter writer(&target, out); | 31 NinjaCopyTargetWriter writer(&target, out); |
33 writer.Run(); | 32 writer.Run(); |
34 | 33 |
35 const char expected_linux[] = | 34 const char expected_linux[] = |
36 "build input1.out: copy ../../foo/input1.txt\n" | 35 "build input1.out: copy ../../foo/input1.txt\n" |
37 "build input2.out: copy ../../foo/input2.txt\n" | 36 "build input2.out: copy ../../foo/input2.txt\n" |
38 "\n" | 37 "\n" |
39 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; | 38 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; |
40 std::string out_str = out.str(); | 39 std::string out_str = out.str(); |
41 EXPECT_EQ(expected_linux, out_str); | 40 EXPECT_EQ(expected_linux, out_str); |
42 } | 41 } |
43 | 42 |
44 // Tests a single file with no output pattern. | 43 // Tests a single file with no output pattern. |
45 TEST(NinjaCopyTargetWriter, ToolchainDeps) { | 44 TEST(NinjaCopyTargetWriter, ToolchainDeps) { |
| 45 Err err; |
46 TestWithScope setup; | 46 TestWithScope setup; |
47 Err err; | |
48 | 47 |
49 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | |
50 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 48 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
51 target.set_output_type(Target::COPY_FILES); | 49 target.set_output_type(Target::COPY_FILES); |
52 | 50 |
53 target.sources().push_back(SourceFile("//foo/input1.txt")); | 51 target.sources().push_back(SourceFile("//foo/input1.txt")); |
54 | 52 |
55 target.action_values().outputs() = | 53 target.action_values().outputs() = |
56 SubstitutionList::MakeForTest("//out/Debug/output.out"); | 54 SubstitutionList::MakeForTest("//out/Debug/output.out"); |
57 | 55 |
58 target.SetToolchain(setup.toolchain()); | 56 target.SetToolchain(setup.toolchain()); |
59 ASSERT_TRUE(target.OnResolved(&err)); | 57 ASSERT_TRUE(target.OnResolved(&err)); |
60 | 58 |
61 std::ostringstream out; | 59 std::ostringstream out; |
62 NinjaCopyTargetWriter writer(&target, out); | 60 NinjaCopyTargetWriter writer(&target, out); |
63 writer.Run(); | 61 writer.Run(); |
64 | 62 |
65 const char expected_linux[] = | 63 const char expected_linux[] = |
66 "build output.out: copy ../../foo/input1.txt\n" | 64 "build output.out: copy ../../foo/input1.txt\n" |
67 "\n" | 65 "\n" |
68 "build obj/foo/bar.stamp: stamp output.out\n"; | 66 "build obj/foo/bar.stamp: stamp output.out\n"; |
69 std::string out_str = out.str(); | 67 std::string out_str = out.str(); |
70 EXPECT_EQ(expected_linux, out_str); | 68 EXPECT_EQ(expected_linux, out_str); |
71 } | 69 } |
72 | 70 |
73 TEST(NinjaCopyTargetWriter, OrderOnlyDeps) { | 71 TEST(NinjaCopyTargetWriter, OrderOnlyDeps) { |
| 72 Err err; |
74 TestWithScope setup; | 73 TestWithScope setup; |
75 Err err; | |
76 | |
77 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | |
78 | 74 |
79 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 75 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
80 target.set_output_type(Target::COPY_FILES); | 76 target.set_output_type(Target::COPY_FILES); |
81 target.sources().push_back(SourceFile("//foo/input1.txt")); | 77 target.sources().push_back(SourceFile("//foo/input1.txt")); |
82 target.action_values().outputs() = | 78 target.action_values().outputs() = |
83 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out"); | 79 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out"); |
84 target.inputs().push_back(SourceFile("//foo/script.py")); | 80 target.inputs().push_back(SourceFile("//foo/script.py")); |
85 target.SetToolchain(setup.toolchain()); | 81 target.SetToolchain(setup.toolchain()); |
86 ASSERT_TRUE(target.OnResolved(&err)); | 82 ASSERT_TRUE(target.OnResolved(&err)); |
87 | 83 |
88 std::ostringstream out; | 84 std::ostringstream out; |
89 NinjaCopyTargetWriter writer(&target, out); | 85 NinjaCopyTargetWriter writer(&target, out); |
90 writer.Run(); | 86 writer.Run(); |
91 | 87 |
92 const char expected_linux[] = | 88 const char expected_linux[] = |
93 "build input1.out: copy ../../foo/input1.txt || ../../foo/script.py\n" | 89 "build input1.out: copy ../../foo/input1.txt || ../../foo/script.py\n" |
94 "\n" | 90 "\n" |
95 "build obj/foo/bar.stamp: stamp input1.out\n"; | 91 "build obj/foo/bar.stamp: stamp input1.out\n"; |
96 std::string out_str = out.str(); | 92 std::string out_str = out.str(); |
97 EXPECT_EQ(expected_linux, out_str); | 93 EXPECT_EQ(expected_linux, out_str); |
98 } | 94 } |
OLD | NEW |