[action] Add test for data_deps of an action target

Add a new test that shows how data_deps of an action are added as ninja
order-only deps for the rules created for the action.

This illustrates the currently behavior, where the order-only deps are
added to the stamp file rule, not to the action's own rule.

Change-Id: I0d9d7966621a5002e5f9df5b0718db7a8ea78e74
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/15740
Reviewed-by: Takuto Ikuta <tikuta@google.com>
Commit-Queue: Aaron Wood <aaronwood@google.com>
diff --git a/src/gn/ninja_action_target_writer_unittest.cc b/src/gn/ninja_action_target_writer_unittest.cc
index d291dc8..d061e76 100644
--- a/src/gn/ninja_action_target_writer_unittest.cc
+++ b/src/gn/ninja_action_target_writer_unittest.cc
@@ -158,6 +158,67 @@
   EXPECT_EQ(expected_linux, out.str());
 }
 
+TEST(NinjaActionTargetWriter, ActionWithOrderOnlyDeps) {
+  Err err;
+  TestWithScope setup;
+
+  // Some dependencies that the action can depend on. Use actions for these
+  // so they have a nice platform-independent stamp file that can appear in the
+  // output (rather than having to worry about how the current platform names
+  // binaries).
+  Target dep(setup.settings(), Label(SourceDir("//foo/"), "dep"));
+  dep.set_output_type(Target::ACTION);
+  dep.visibility().SetPublic();
+  dep.SetToolchain(setup.toolchain());
+  ASSERT_TRUE(dep.OnResolved(&err));
+
+  Target datadep(setup.settings(), Label(SourceDir("//foo/"), "datadep"));
+  datadep.set_output_type(Target::ACTION);
+  datadep.visibility().SetPublic();
+  datadep.SetToolchain(setup.toolchain());
+  ASSERT_TRUE(datadep.OnResolved(&err));
+
+  Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
+  target.set_output_type(Target::ACTION);
+
+  target.action_values().set_script(SourceFile("//foo/script.py"));
+
+  target.sources().push_back(SourceFile("//foo/source.txt"));
+  target.config_values().inputs().push_back(SourceFile("//foo/included.txt"));
+
+  target.action_values().outputs() =
+      SubstitutionList::MakeForTest("//out/Debug/foo.out");
+
+  target.private_deps().push_back(LabelTargetPair(&dep));
+  target.data_deps().push_back(LabelTargetPair(&datadep));
+
+  target.SetToolchain(setup.toolchain());
+  ASSERT_TRUE(target.OnResolved(&err));
+
+  setup.build_settings()->set_python_path(
+      base::FilePath(FILE_PATH_LITERAL("/usr/bin/python")));
+
+  std::ostringstream out;
+  NinjaActionTargetWriter writer(&target, out);
+  writer.Run();
+
+  const char expected[] =
+      "rule __foo_bar___rule\n"
+      "  command = /usr/bin/python ../../foo/script.py\n"
+      "  description = ACTION //foo:bar()\n"
+      "  restat = 1\n"
+      "\n"
+      "build foo.out: __foo_bar___rule | ../../foo/script.py "
+      "../../foo/included.txt ../../foo/source.txt obj/foo/dep.stamp\n"
+      "\n"
+      "build obj/foo/bar.stamp: stamp foo.out || "
+      "obj/foo/datadep.stamp\n";
+
+  std::string out_str = out.str();
+  EXPECT_EQ(expected, out_str);
+}
+
+
 TEST(NinjaActionTargetWriter, ForEach) {
   Err err;
   TestWithScope setup;