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
3 // found in the LICENSE file.
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "tools/gn/file_template.h"
10 #include "tools/gn/ninja_copy_target_writer.h"
11 #include "tools/gn/test_with_scope.h"
13 TEST(NinjaCopyTargetWriter
, Run
) {
15 setup
.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
16 Target
target(setup
.settings(), Label(SourceDir("//foo/"), "bar"));
17 target
.set_output_type(Target::COPY_FILES
);
19 target
.sources().push_back(SourceFile("//foo/input1.txt"));
20 target
.sources().push_back(SourceFile("//foo/input2.txt"));
22 target
.action_values().outputs().push_back(
23 SourceFile("//out/Debug/{{source_name_part}}.out"));
27 setup
.settings()->set_target_os(Settings::LINUX
);
29 std::ostringstream out
;
30 NinjaCopyTargetWriter
writer(&target
, setup
.toolchain(), out
);
33 const char expected_linux
[] =
34 "build input1.out: copy ../../foo/input1.txt\n"
35 "build input2.out: copy ../../foo/input2.txt\n"
37 "build obj/foo/bar.stamp: stamp input1.out input2.out\n";
38 std::string out_str
= out
.str();
40 std::replace(out_str
.begin(), out_str
.end(), '\\', '/');
42 EXPECT_EQ(expected_linux
, out_str
);
47 setup
.settings()->set_target_os(Settings::WIN
);
49 std::ostringstream out
;
50 NinjaCopyTargetWriter
writer(&target
, setup
.toolchain(), out
);
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.
55 const char expected_win
[] =
56 "build input1.out: copy ../../foo/input1.txt\n"
57 "build input2.out: copy ../../foo/input2.txt\n"
59 "build obj/foo/bar.stamp: stamp input1.out input2.out\n";
60 std::string out_str
= out
.str();
62 std::replace(out_str
.begin(), out_str
.end(), '\\', '/');
64 EXPECT_EQ(expected_win
, out_str
);