Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: tools/gn/ninja_copy_target_writer_unittest.cc

Issue 2940873002: Implement tracking of BUILD.gn files used to define target, toolchain or (Closed)
Patch Set: Fix compilation after rebase. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/ninja_copy_target_writer.h" 9 #include "tools/gn/ninja_copy_target_writer.h"
10 #include "tools/gn/target.h" 10 #include "tools/gn/target.h"
11 #include "tools/gn/test_with_scope.h" 11 #include "tools/gn/test_with_scope.h"
12 12
13 // Tests multiple files with an output pattern and no toolchain dependency. 13 // Tests multiple files with an output pattern and no toolchain dependency.
14 TEST(NinjaCopyTargetWriter, Run) { 14 TEST(NinjaCopyTargetWriter, Run) {
15 Err err; 15 Err err;
16 TestWithScope setup; 16 TestWithScope setup;
17 17
18 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 18 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {});
19 target.set_output_type(Target::COPY_FILES); 19 target.set_output_type(Target::COPY_FILES);
20 20
21 target.sources().push_back(SourceFile("//foo/input1.txt")); 21 target.sources().push_back(SourceFile("//foo/input1.txt"));
22 target.sources().push_back(SourceFile("//foo/input2.txt")); 22 target.sources().push_back(SourceFile("//foo/input2.txt"));
23 23
24 target.action_values().outputs() = 24 target.action_values().outputs() =
25 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out"); 25 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out");
26 26
27 target.SetToolchain(setup.toolchain()); 27 target.SetToolchain(setup.toolchain());
28 ASSERT_TRUE(target.OnResolved(&err)); 28 ASSERT_TRUE(target.OnResolved(&err));
29 29
30 std::ostringstream out; 30 std::ostringstream out;
31 NinjaCopyTargetWriter writer(&target, out); 31 NinjaCopyTargetWriter writer(&target, out);
32 writer.Run(); 32 writer.Run();
33 33
34 const char expected_linux[] = 34 const char expected_linux[] =
35 "build input1.out: copy ../../foo/input1.txt\n" 35 "build input1.out: copy ../../foo/input1.txt\n"
36 "build input2.out: copy ../../foo/input2.txt\n" 36 "build input2.out: copy ../../foo/input2.txt\n"
37 "\n" 37 "\n"
38 "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; 38 "build obj/foo/bar.stamp: stamp input1.out input2.out\n";
39 std::string out_str = out.str(); 39 std::string out_str = out.str();
40 EXPECT_EQ(expected_linux, out_str); 40 EXPECT_EQ(expected_linux, out_str);
41 } 41 }
42 42
43 // Tests a single file with no output pattern. 43 // Tests a single file with no output pattern.
44 TEST(NinjaCopyTargetWriter, ToolchainDeps) { 44 TEST(NinjaCopyTargetWriter, ToolchainDeps) {
45 Err err; 45 Err err;
46 TestWithScope setup; 46 TestWithScope setup;
47 47
48 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 48 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {});
49 target.set_output_type(Target::COPY_FILES); 49 target.set_output_type(Target::COPY_FILES);
50 50
51 target.sources().push_back(SourceFile("//foo/input1.txt")); 51 target.sources().push_back(SourceFile("//foo/input1.txt"));
52 52
53 target.action_values().outputs() = 53 target.action_values().outputs() =
54 SubstitutionList::MakeForTest("//out/Debug/output.out"); 54 SubstitutionList::MakeForTest("//out/Debug/output.out");
55 55
56 target.SetToolchain(setup.toolchain()); 56 target.SetToolchain(setup.toolchain());
57 ASSERT_TRUE(target.OnResolved(&err)); 57 ASSERT_TRUE(target.OnResolved(&err));
58 58
59 std::ostringstream out; 59 std::ostringstream out;
60 NinjaCopyTargetWriter writer(&target, out); 60 NinjaCopyTargetWriter writer(&target, out);
61 writer.Run(); 61 writer.Run();
62 62
63 const char expected_linux[] = 63 const char expected_linux[] =
64 "build output.out: copy ../../foo/input1.txt\n" 64 "build output.out: copy ../../foo/input1.txt\n"
65 "\n" 65 "\n"
66 "build obj/foo/bar.stamp: stamp output.out\n"; 66 "build obj/foo/bar.stamp: stamp output.out\n";
67 std::string out_str = out.str(); 67 std::string out_str = out.str();
68 EXPECT_EQ(expected_linux, out_str); 68 EXPECT_EQ(expected_linux, out_str);
69 } 69 }
70 70
71 TEST(NinjaCopyTargetWriter, OrderOnlyDeps) { 71 TEST(NinjaCopyTargetWriter, OrderOnlyDeps) {
72 Err err; 72 Err err;
73 TestWithScope setup; 73 TestWithScope setup;
74 74
75 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 75 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"), {});
76 target.set_output_type(Target::COPY_FILES); 76 target.set_output_type(Target::COPY_FILES);
77 target.sources().push_back(SourceFile("//foo/input1.txt")); 77 target.sources().push_back(SourceFile("//foo/input1.txt"));
78 target.action_values().outputs() = 78 target.action_values().outputs() =
79 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out"); 79 SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out");
80 target.inputs().push_back(SourceFile("//foo/script.py")); 80 target.inputs().push_back(SourceFile("//foo/script.py"));
81 target.SetToolchain(setup.toolchain()); 81 target.SetToolchain(setup.toolchain());
82 ASSERT_TRUE(target.OnResolved(&err)); 82 ASSERT_TRUE(target.OnResolved(&err));
83 83
84 std::ostringstream out; 84 std::ostringstream out;
85 NinjaCopyTargetWriter writer(&target, out); 85 NinjaCopyTargetWriter writer(&target, out);
86 writer.Run(); 86 writer.Run();
87 87
88 const char expected_linux[] = 88 const char expected_linux[] =
89 "build input1.out: copy ../../foo/input1.txt || ../../foo/script.py\n" 89 "build input1.out: copy ../../foo/input1.txt || ../../foo/script.py\n"
90 "\n" 90 "\n"
91 "build obj/foo/bar.stamp: stamp input1.out\n"; 91 "build obj/foo/bar.stamp: stamp input1.out\n";
92 std::string out_str = out.str(); 92 std::string out_str = out.str();
93 EXPECT_EQ(expected_linux, out_str); 93 EXPECT_EQ(expected_linux, out_str);
94 } 94 }
OLDNEW
« no previous file with comments | « tools/gn/ninja_bundle_data_target_writer_unittest.cc ('k') | tools/gn/ninja_create_bundle_target_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698