| 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" | 9 #include "tools/gn/file_template.h" |
| 10 #include "tools/gn/ninja_copy_target_writer.h" | 10 #include "tools/gn/ninja_copy_target_writer.h" |
| 11 #include "tools/gn/test_with_scope.h" | 11 #include "tools/gn/test_with_scope.h" |
| 12 | 12 |
| 13 TEST(NinjaCopyTargetWriter, Run) { | 13 TEST(NinjaCopyTargetWriter, Run) { |
| 14 TestWithScope setup; | 14 TestWithScope setup; |
| 15 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 15 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
| 16 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); | 16 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); |
| 17 target.set_output_type(Target::COPY_FILES); | 17 target.set_output_type(Target::COPY_FILES); |
| 18 | 18 |
| 19 target.sources().push_back(SourceFile("//foo/input1.txt")); | 19 target.sources().push_back(SourceFile("//foo/input1.txt")); |
| 20 target.sources().push_back(SourceFile("//foo/input2.txt")); | 20 target.sources().push_back(SourceFile("//foo/input2.txt")); |
| 21 | 21 |
| 22 target.script_values().outputs().push_back( | 22 target.script_values().outputs().push_back( |
| 23 SourceFile("//out/Debug/{{source_name_part}}.out")); | 23 SourceFile("//out/Debug/{{source_name_part}}.out")); |
| 24 | 24 |
| 25 // Posix. | 25 // Posix. |
| 26 { | 26 { |
| 27 setup.settings()->set_target_os(Settings::LINUX); | 27 setup.settings()->set_target_os(Settings::LINUX); |
| 28 | 28 |
| 29 std::ostringstream out; | 29 std::ostringstream out; |
| 30 NinjaCopyTargetWriter writer(&target, out); | 30 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); |
| 31 writer.Run(); | 31 writer.Run(); |
| 32 | 32 |
| 33 const char expected_linux[] = | 33 const char expected_linux[] = |
| 34 "build input1.out: tc_copy ../../foo/input1.txt\n" | 34 "build input1.out: copy ../../foo/input1.txt\n" |
| 35 "build input2.out: tc_copy ../../foo/input2.txt\n" | 35 "build input2.out: copy ../../foo/input2.txt\n" |
| 36 "\n" | 36 "\n" |
| 37 "build obj/foo/bar.stamp: tc_stamp input1.out input2.out\n"; | 37 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; |
| 38 std::string out_str = out.str(); | 38 std::string out_str = out.str(); |
| 39 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
| 40 std::replace(out_str.begin(), out_str.end(), '\\', '/'); | 40 std::replace(out_str.begin(), out_str.end(), '\\', '/'); |
| 41 #endif | 41 #endif |
| 42 EXPECT_EQ(expected_linux, out_str); | 42 EXPECT_EQ(expected_linux, out_str); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Windows. | 45 // Windows. |
| 46 { | 46 { |
| 47 setup.settings()->set_target_os(Settings::WIN); | 47 setup.settings()->set_target_os(Settings::WIN); |
| 48 | 48 |
| 49 std::ostringstream out; | 49 std::ostringstream out; |
| 50 NinjaCopyTargetWriter writer(&target, out); | 50 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); |
| 51 writer.Run(); | 51 writer.Run(); |
| 52 | 52 |
| 53 // TODO(brettw) I think we'll need to worry about backslashes here | 53 // TODO(brettw) I think we'll need to worry about backslashes here |
| 54 // depending if we're on actual Windows or Linux pretending to be Windows. | 54 // depending if we're on actual Windows or Linux pretending to be Windows. |
| 55 const char expected_win[] = | 55 const char expected_win[] = |
| 56 "build input1.out: tc_copy ../../foo/input1.txt\n" | 56 "build input1.out: copy ../../foo/input1.txt\n" |
| 57 "build input2.out: tc_copy ../../foo/input2.txt\n" | 57 "build input2.out: copy ../../foo/input2.txt\n" |
| 58 "\n" | 58 "\n" |
| 59 "build obj/foo/bar.stamp: tc_stamp input1.out input2.out\n"; | 59 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; |
| 60 std::string out_str = out.str(); | 60 std::string out_str = out.str(); |
| 61 #if defined(OS_WIN) | 61 #if defined(OS_WIN) |
| 62 std::replace(out_str.begin(), out_str.end(), '\\', '/'); | 62 std::replace(out_str.begin(), out_str.end(), '\\', '/'); |
| 63 #endif | 63 #endif |
| 64 EXPECT_EQ(expected_win, out_str); | 64 EXPECT_EQ(expected_win, out_str); |
| 65 } | 65 } |
| 66 } | 66 } |
| OLD | NEW |