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/file_template.h" | |
10 #include "tools/gn/ninja_copy_target_writer.h" | 9 #include "tools/gn/ninja_copy_target_writer.h" |
11 #include "tools/gn/test_with_scope.h" | 10 #include "tools/gn/test_with_scope.h" |
12 | 11 |
13 // Tests mutliple files with an output pattern and no toolchain dependency. | 12 // Tests mutliple files with an output pattern and no toolchain dependency. |
14 TEST(NinjaCopyTargetWriter, Run) { | 13 TEST(NinjaCopyTargetWriter, Run) { |
15 TestWithScope setup; | 14 TestWithScope setup; |
16 setup.settings()->set_target_os(Settings::LINUX); | 15 setup.settings()->set_target_os(Settings::LINUX); |
17 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 16 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
18 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 17 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
19 target.set_output_type(Target::COPY_FILES); | 18 target.set_output_type(Target::COPY_FILES); |
20 | 19 |
21 target.sources().push_back(SourceFile("//foo/input1.txt")); | 20 target.sources().push_back(SourceFile("//foo/input1.txt")); |
22 target.sources().push_back(SourceFile("//foo/input2.txt")); | 21 target.sources().push_back(SourceFile("//foo/input2.txt")); |
23 | 22 |
24 target.action_values().outputs().push_back( | 23 target.action_values().outputs() = |
25 "//out/Debug/{{source_name_part}}.out"); | 24 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out"); |
26 | 25 |
27 std::ostringstream out; | 26 std::ostringstream out; |
28 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); | 27 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); |
29 writer.Run(); | 28 writer.Run(); |
30 | 29 |
31 const char expected_linux[] = | 30 const char expected_linux[] = |
32 "build input1.out: copy ../../foo/input1.txt\n" | 31 "build input1.out: copy ../../foo/input1.txt\n" |
33 "build input2.out: copy ../../foo/input2.txt\n" | 32 "build input2.out: copy ../../foo/input2.txt\n" |
34 "\n" | 33 "\n" |
35 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; | 34 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; |
36 std::string out_str = out.str(); | 35 std::string out_str = out.str(); |
37 EXPECT_EQ(expected_linux, out_str); | 36 EXPECT_EQ(expected_linux, out_str); |
38 } | 37 } |
39 | 38 |
40 // Tests a single file with no output pattern. | 39 // Tests a single file with no output pattern. |
41 TEST(NinjaCopyTargetWriter, ToolchainDeps) { | 40 TEST(NinjaCopyTargetWriter, ToolchainDeps) { |
42 TestWithScope setup; | 41 TestWithScope setup; |
43 setup.settings()->set_target_os(Settings::LINUX); | 42 setup.settings()->set_target_os(Settings::LINUX); |
44 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 43 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
45 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 44 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
46 target.set_output_type(Target::COPY_FILES); | 45 target.set_output_type(Target::COPY_FILES); |
47 | 46 |
48 target.sources().push_back(SourceFile("//foo/input1.txt")); | 47 target.sources().push_back(SourceFile("//foo/input1.txt")); |
49 | 48 |
50 target.action_values().outputs().push_back("//out/Debug/output.out"); | 49 target.action_values().outputs() = |
| 50 SubstitutionList::MakeForTest("//out/Debug/output.out"); |
51 | 51 |
52 std::ostringstream out; | 52 std::ostringstream out; |
53 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); | 53 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); |
54 writer.Run(); | 54 writer.Run(); |
55 | 55 |
56 const char expected_linux[] = | 56 const char expected_linux[] = |
57 "build output.out: copy ../../foo/input1.txt\n" | 57 "build output.out: copy ../../foo/input1.txt\n" |
58 "\n" | 58 "\n" |
59 "build obj/foo/bar.stamp: stamp output.out\n"; | 59 "build obj/foo/bar.stamp: stamp output.out\n"; |
60 std::string out_str = out.str(); | 60 std::string out_str = out.str(); |
61 EXPECT_EQ(expected_linux, out_str); | 61 EXPECT_EQ(expected_linux, out_str); |
62 } | 62 } |
OLD | NEW |