Add a test for source_set with modulemap This is to confirm current behavior for output of ninja build file when we use source_set with modulemap. context: https://chromium-review.googlesource.com/c/chromium/src/+/6364375/comment/f1cd4bd4_a41713cd/ Bug: 40440396 Change-Id: Ib5d62aa2253c78b60b876cc8ef0becf04ace4fd7 Reviewed-on: https://gn-review.googlesource.com/c/gn/+/18580 Commit-Queue: Takuto Ikuta <tikuta@google.com> Reviewed-by: Petr Hosek <phosek@google.com>
diff --git a/src/gn/ninja_c_binary_target_writer_unittest.cc b/src/gn/ninja_c_binary_target_writer_unittest.cc index 5bfd2a4..f336ac7 100644 --- a/src/gn/ninja_c_binary_target_writer_unittest.cc +++ b/src/gn/ninja_c_binary_target_writer_unittest.cc
@@ -2303,6 +2303,44 @@ EXPECT_EQ(expected, out_str) << expected << "\n" << out_str; } +TEST_F(NinjaCBinaryTargetWriterTest, ModuleMapInSourceSet) { + TestWithScope setup; + Err err; + + TestTarget target(setup, "//foo:bar", Target::SOURCE_SET); + target.sources().push_back(SourceFile("//foo/bar.cc")); + target.sources().push_back(SourceFile("//foo/bar.modulemap")); + target.source_types_used().Set(SourceFile::SOURCE_CPP); + target.source_types_used().Set(SourceFile::SOURCE_MODULEMAP); + ASSERT_TRUE(target.OnResolved(&err)); + + std::ostringstream out; + NinjaCBinaryTargetWriter writer(&target, out); + writer.Run(); + + const char expected[] = + "defines =\n" + "include_dirs =\n" + "cflags =\n" + "cflags_cc =\n" + "root_out_dir = .\n" + "target_gen_dir = gen/foo\n" + "target_out_dir = obj/foo\n" + "target_output_name = bar\n" + "\n" + "build obj/foo/bar.bar.o: cxx ../../foo/bar.cc | " + "obj/foo/bar.bar.pcm\n" + " source_file_part = bar.cc\n" + " source_name_part = bar\n" + "build obj/foo/bar.bar.pcm: cxx_module ../../foo/bar.modulemap\n" + " source_file_part = bar.modulemap\n" + " source_name_part = bar\n" + "\n" + "build phony/foo/bar: phony obj/foo/bar.bar.o\n"; + std::string out_str = out.str(); + EXPECT_EQ(expected, out_str) << expected << "\n" << out_str; +} + // Test linking of targets containing Swift modules. TEST_F(NinjaCBinaryTargetWriterTest, SwiftModule) { Err err;