Update parsing of dumpsys batterystats
[chromium-blink-merge.git] / tools / gn / ninja_copy_target_writer_unittest.cc
blobe9f24371ba27db5c35399d25c7b6ff17076b4c04
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.
5 #include <algorithm>
6 #include <sstream>
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 // Tests mutliple files with an output pattern and no toolchain dependency.
14 TEST(NinjaCopyTargetWriter, Run) {
15 TestWithScope setup;
16 setup.settings()->set_target_os(Settings::LINUX);
17 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
18 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
19 target.set_output_type(Target::COPY_FILES);
21 target.sources().push_back(SourceFile("//foo/input1.txt"));
22 target.sources().push_back(SourceFile("//foo/input2.txt"));
24 target.action_values().outputs().push_back(
25 "//out/Debug/{{source_name_part}}.out");
27 std::ostringstream out;
28 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out);
29 writer.Run();
31 const char expected_linux[] =
32 "build input1.out: copy ../../foo/input1.txt\n"
33 "build input2.out: copy ../../foo/input2.txt\n"
34 "\n"
35 "build obj/foo/bar.stamp: stamp input1.out input2.out\n";
36 std::string out_str = out.str();
37 EXPECT_EQ(expected_linux, out_str);
40 // Tests a single file with no output pattern and a toolchain dependency.
41 TEST(NinjaCopyTargetWriter, ToolchainDeps) {
42 TestWithScope setup;
43 setup.settings()->set_target_os(Settings::LINUX);
44 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
45 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
46 target.set_output_type(Target::COPY_FILES);
48 // Toolchain dependency. Here we make a target in the same toolchain for
49 // simplicity, but in real life (using the Builder) this would be rejected
50 // because it would be a circular dependency (the target depends on its
51 // toolchain, and the toolchain depends on this target).
52 Target toolchain_dep_target(setup.settings(),
53 Label(SourceDir("//foo/"), "setup"));
54 toolchain_dep_target.set_output_type(Target::ACTION);
55 setup.toolchain()->deps().push_back(LabelTargetPair(&toolchain_dep_target));
57 target.sources().push_back(SourceFile("//foo/input1.txt"));
59 target.action_values().outputs().push_back("//out/Debug/output.out");
61 std::ostringstream out;
62 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out);
63 writer.Run();
65 const char expected_linux[] =
66 "build obj/foo/bar.inputdeps.stamp: stamp obj/foo/setup.stamp\n"
67 "build output.out: copy ../../foo/input1.txt | "
68 "obj/foo/bar.inputdeps.stamp\n"
69 "\n"
70 "build obj/foo/bar.stamp: stamp output.out\n";
71 std::string out_str = out.str();
72 EXPECT_EQ(expected_linux, out_str);