blob: 44973a7198f8225b1b571cea0498a71d88bbd247 [file] [log] [blame]
[email protected]b90c75a2013-09-18 22:02:501// 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.
4
[email protected]c9f05402013-09-23 23:12:585#include <algorithm>
[email protected]b90c75a2013-09-18 22:02:506#include <sstream>
7
8#include "testing/gtest/include/gtest/gtest.h"
[email protected]b90c75a2013-09-18 22:02:509#include "tools/gn/ninja_copy_target_writer.h"
[email protected]0dfcae72014-08-19 22:52:1610#include "tools/gn/target.h"
[email protected]b90c75a2013-09-18 22:02:5011#include "tools/gn/test_with_scope.h"
12
dpranke44128e32014-10-31 23:01:2913// Tests multiple files with an output pattern and no toolchain dependency.
[email protected]b90c75a2013-09-18 22:02:5014TEST(NinjaCopyTargetWriter, Run) {
Brett Wilson85423a02014-09-02 19:29:4215 Err err;
sdefresne3fed8052016-07-01 13:29:4716 TestWithScope setup;
[email protected]0dfcae72014-08-19 22:52:1617
Dirk Prankec9126ec982017-08-17 15:05:0718 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
[email protected]b90c75a2013-09-18 22:02:5019 target.set_output_type(Target::COPY_FILES);
20
21 target.sources().push_back(SourceFile("//foo/input1.txt"));
22 target.sources().push_back(SourceFile("//foo/input2.txt"));
23
[email protected]012db5942014-08-06 20:38:4524 target.action_values().outputs() =
25 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out");
[email protected]b90c75a2013-09-18 22:02:5026
[email protected]0dfcae72014-08-19 22:52:1627 target.SetToolchain(setup.toolchain());
Brett Wilson85423a02014-09-02 19:29:4228 ASSERT_TRUE(target.OnResolved(&err));
[email protected]0dfcae72014-08-19 22:52:1629
[email protected]abc283c2014-06-26 18:12:3030 std::ostringstream out;
[email protected]0dfcae72014-08-19 22:52:1631 NinjaCopyTargetWriter writer(&target, out);
[email protected]abc283c2014-06-26 18:12:3032 writer.Run();
[email protected]b90c75a2013-09-18 22:02:5033
[email protected]abc283c2014-06-26 18:12:3034 const char expected_linux[] =
35 "build input1.out: copy ../../foo/input1.txt\n"
36 "build input2.out: copy ../../foo/input2.txt\n"
37 "\n"
38 "build obj/foo/bar.stamp: stamp input1.out input2.out\n";
39 std::string out_str = out.str();
40 EXPECT_EQ(expected_linux, out_str);
41}
[email protected]b90c75a2013-09-18 22:02:5042
[email protected]e161f842014-07-23 22:05:1943// Tests a single file with no output pattern.
[email protected]abc283c2014-06-26 18:12:3044TEST(NinjaCopyTargetWriter, ToolchainDeps) {
Brett Wilson85423a02014-09-02 19:29:4245 Err err;
sdefresne3fed8052016-07-01 13:29:4746 TestWithScope setup;
[email protected]0dfcae72014-08-19 22:52:1647
Dirk Prankec9126ec982017-08-17 15:05:0748 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
[email protected]abc283c2014-06-26 18:12:3049 target.set_output_type(Target::COPY_FILES);
[email protected]b90c75a2013-09-18 22:02:5050
[email protected]abc283c2014-06-26 18:12:3051 target.sources().push_back(SourceFile("//foo/input1.txt"));
[email protected]b90c75a2013-09-18 22:02:5052
[email protected]012db5942014-08-06 20:38:4553 target.action_values().outputs() =
54 SubstitutionList::MakeForTest("//out/Debug/output.out");
[email protected]abc283c2014-06-26 18:12:3055
[email protected]0dfcae72014-08-19 22:52:1656 target.SetToolchain(setup.toolchain());
Brett Wilson85423a02014-09-02 19:29:4257 ASSERT_TRUE(target.OnResolved(&err));
[email protected]0dfcae72014-08-19 22:52:1658
[email protected]abc283c2014-06-26 18:12:3059 std::ostringstream out;
[email protected]0dfcae72014-08-19 22:52:1660 NinjaCopyTargetWriter writer(&target, out);
[email protected]abc283c2014-06-26 18:12:3061 writer.Run();
62
63 const char expected_linux[] =
[email protected]e161f842014-07-23 22:05:1964 "build output.out: copy ../../foo/input1.txt\n"
[email protected]abc283c2014-06-26 18:12:3065 "\n"
66 "build obj/foo/bar.stamp: stamp output.out\n";
67 std::string out_str = out.str();
68 EXPECT_EQ(expected_linux, out_str);
[email protected]b90c75a2013-09-18 22:02:5069}
dpranke44128e32014-10-31 23:01:2970
71TEST(NinjaCopyTargetWriter, OrderOnlyDeps) {
dpranke44128e32014-10-31 23:01:2972 Err err;
sdefresne3fed8052016-07-01 13:29:4773 TestWithScope setup;
dpranke44128e32014-10-31 23:01:2974
Dirk Prankec9126ec982017-08-17 15:05:0775 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
dpranke44128e32014-10-31 23:01:2976 target.set_output_type(Target::COPY_FILES);
77 target.sources().push_back(SourceFile("//foo/input1.txt"));
78 target.action_values().outputs() =
79 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out");
80 target.inputs().push_back(SourceFile("//foo/script.py"));
81 target.SetToolchain(setup.toolchain());
82 ASSERT_TRUE(target.OnResolved(&err));
83
84 std::ostringstream out;
85 NinjaCopyTargetWriter writer(&target, out);
86 writer.Run();
87
88 const char expected_linux[] =
brettw4445f6172016-02-03 22:57:1489 "build input1.out: copy ../../foo/input1.txt || ../../foo/script.py\n"
dpranke44128e32014-10-31 23:01:2990 "\n"
91 "build obj/foo/bar.stamp: stamp input1.out\n";
92 std::string out_str = out.str();
93 EXPECT_EQ(expected_linux, out_str);
94}