Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 | |
| 5 #include <sstream> | |
| 6 | |
| 7 #include "testing/gmock/include/gmock/gmock.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 #include "tools/gn/ninja_build_writer.h" | |
| 10 #include "tools/gn/scheduler.h" | |
| 11 #include "tools/gn/target.h" | |
| 12 #include "tools/gn/test_with_scope.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 | |
| 17 } // namespace | |
| 18 | |
| 19 TEST(NinjaBuildWriter, TwoTargets) { | |
| 20 Scheduler scheduler; | |
| 21 TestWithScope setup; | |
| 22 Err err; | |
| 23 | |
| 24 Target target_foo(setup.settings(), Label(SourceDir("//foo/"), "bar")); | |
| 25 target_foo.set_output_type(Target::ACTION); | |
| 26 target_foo.action_values().set_script(SourceFile("//foo/script.py")); | |
| 27 target_foo.action_values().outputs() = SubstitutionList::MakeForTest( | |
| 28 "//out/Debug/out1.out", "//out/Debug/out2.out"); | |
| 29 target_foo.SetToolchain(setup.toolchain()); | |
| 30 ASSERT_TRUE(target_foo.OnResolved(&err)); | |
| 31 | |
| 32 Target target_bar(setup.settings(), Label(SourceDir("//bar/"), "bar")); | |
| 33 target_bar.set_output_type(Target::ACTION); | |
| 34 target_bar.action_values().set_script(SourceFile("//bar/script.py")); | |
| 35 target_bar.action_values().outputs() = SubstitutionList::MakeForTest( | |
| 36 "//out/Debug/out3.out", "//out/Debug/out4.out"); | |
| 37 target_bar.SetToolchain(setup.toolchain()); | |
| 38 ASSERT_TRUE(target_bar.OnResolved(&err)); | |
| 39 | |
| 40 std::ostringstream ninja_out; | |
| 41 std::ostringstream depfile_out; | |
| 42 std::vector<const Settings*> all_settings = {setup.settings()}; | |
| 43 std::vector<const Target*> targets = {&target_foo, &target_bar}; | |
| 44 NinjaBuildWriter writer(setup.build_settings(), all_settings, | |
| 45 setup.toolchain(), targets, ninja_out, depfile_out); | |
| 46 ASSERT_TRUE(writer.Run(&err)); | |
| 47 | |
| 48 const char expected_rule_gn[] = "rule gn\n"; | |
| 49 const char expected_build_ninja[] = | |
| 50 "build build.ninja: gn\n" | |
| 51 " generator = 1\n" | |
| 52 " depfile = build.ninja.d\n" | |
| 53 "\n"; | |
| 54 const char expected_link_pool[] = | |
| 55 "pool link_pool\n" | |
| 56 " depth = 0\n" | |
| 57 "\n"; | |
| 58 const char expected_toolchain[] = | |
| 59 "subninja toolchain.ninja\n" | |
| 60 "\n"; | |
| 61 const char expected_targets[] = | |
| 62 "build foo$:bar: phony obj/foo/bar.stamp\n" | |
| 63 "build bar$:bar: phony obj/bar/bar.stamp\n" | |
| 64 "build bar: phony obj/bar/bar.stamp\n" | |
| 65 "\n"; | |
| 66 const char expected_root_target[] = | |
| 67 "build all: phony obj/foo/bar.stamp $\n" | |
| 68 " obj/bar/bar.stamp\n" | |
| 69 "default all\n"; | |
| 70 EXPECT_THAT(ninja_out.str(), testing::HasSubstr(expected_rule_gn)); | |
|
brettw
2016/03/25 22:43:10
I'm not a fan of gmock and haven't used it in the
agrieve
2016/03/29 15:59:33
Thanks! Helpful rant actually. I agree!
| |
| 71 EXPECT_THAT(ninja_out.str(), testing::HasSubstr(expected_build_ninja)); | |
| 72 EXPECT_THAT(ninja_out.str(), testing::HasSubstr(expected_link_pool)); | |
| 73 EXPECT_THAT(ninja_out.str(), testing::HasSubstr(expected_toolchain)); | |
| 74 EXPECT_THAT(ninja_out.str(), testing::HasSubstr(expected_targets)); | |
| 75 EXPECT_THAT(ninja_out.str(), testing::HasSubstr(expected_root_target)); | |
| 76 } | |
| 77 | |
| 78 TEST(NinjaBuildWriter, DuplicateOutputs) { | |
| 79 Scheduler scheduler; | |
| 80 TestWithScope setup; | |
| 81 Err err; | |
| 82 | |
| 83 //setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | |
| 84 | |
| 85 Target target_foo(setup.settings(), Label(SourceDir("//foo/"), "bar")); | |
| 86 target_foo.set_output_type(Target::ACTION); | |
| 87 target_foo.action_values().set_script(SourceFile("//foo/script.py")); | |
| 88 target_foo.action_values().outputs() = SubstitutionList::MakeForTest( | |
| 89 "//out/Debug/out1.out", "//out/Debug/out2.out"); | |
| 90 target_foo.SetToolchain(setup.toolchain()); | |
| 91 ASSERT_TRUE(target_foo.OnResolved(&err)); | |
| 92 | |
| 93 Target target_bar(setup.settings(), Label(SourceDir("//bar/"), "bar")); | |
| 94 target_bar.set_output_type(Target::ACTION); | |
| 95 target_bar.action_values().set_script(SourceFile("//bar/script.py")); | |
| 96 target_bar.action_values().outputs() = SubstitutionList::MakeForTest( | |
| 97 "//out/Debug/out3.out", "//out/Debug/out2.out"); | |
| 98 target_bar.SetToolchain(setup.toolchain()); | |
| 99 ASSERT_TRUE(target_bar.OnResolved(&err)); | |
| 100 | |
| 101 std::ostringstream ninja_out; | |
| 102 std::ostringstream depfile_out; | |
| 103 std::vector<const Settings*> all_settings = { setup.settings() }; | |
| 104 std::vector<const Target*> targets = { &target_foo, &target_bar }; | |
| 105 NinjaBuildWriter writer(setup.build_settings(), all_settings, | |
| 106 setup.toolchain(), targets, ninja_out, depfile_out); | |
| 107 ASSERT_FALSE(writer.Run(&err)); | |
| 108 | |
| 109 const char expected_help_test[] = | |
| 110 "Two or more targets generate the same output:\n" | |
| 111 " out2.out\n" | |
| 112 "\n" | |
| 113 "This is can often be fixed by changing one of the target names, or by \n" | |
| 114 "setting an output_name on one of them.\n" | |
| 115 "\n" | |
| 116 "Collisions:\n" | |
| 117 " //foo:bar\n" | |
| 118 " //bar:bar\n"; | |
| 119 | |
| 120 EXPECT_EQ(expected_help_test, err.help_text()); | |
| 121 } | |
| OLD | NEW |