Index: tools/gn/gyp_script_target_writer_unittest.cc |
diff --git a/tools/gn/gyp_script_target_writer_unittest.cc b/tools/gn/gyp_script_target_writer_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..597998317b91c1118792da3f218867c3c59a0d52 |
--- /dev/null |
+++ b/tools/gn/gyp_script_target_writer_unittest.cc |
@@ -0,0 +1,57 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "tools/gn/builder_record.h" |
+#include "tools/gn/gyp_script_target_writer.h" |
+#include "tools/gn/test_with_scope.h" |
+ |
+TEST(GypScriptTargetWriter, Run) { |
+ TestWithScope setup; |
+ setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
+ scoped_ptr<Target> target( |
+ new Target(setup.settings(), Label(SourceDir("//foo/"), "bar"))); |
+ target->set_output_type(Target::CUSTOM); |
+ |
+ target->sources().push_back(SourceFile("//foo/input1.txt")); |
+ target->sources().push_back(SourceFile("//foo/input2.txt")); |
+ |
+ target->script_values().outputs().push_back( |
+ SourceFile("//out/Debug/{{source_file_part}}.out")); |
+ |
+ BuilderRecord record(BuilderRecord::ITEM_TARGET, target->label()); |
+ record.set_item(target.PassAs<Item>()); |
+ GypTargetWriter::TargetGroup group; |
+ group.debug = &record; |
+ |
+ setup.settings()->set_target_os(Settings::WIN); |
+ |
+ std::ostringstream out; |
+ GypScriptTargetWriter writer(group, SourceDir("//out/gn_gyp/"), out); |
+ writer.Run(); |
+ |
+ const char expected[] = |
+ " {\n" |
+ " 'target_name': 'bar',\n" |
+ " 'type': 'none',\n" |
+ " 'actions': [{\n" |
+ " 'action_name': 'bar action',\n" |
+ " 'action': [\n" |
+ " 'ninja',\n" |
+ " '-C', '../../out/Debug/obj/foo/bar_ninja',\n" |
+ " 'bar',\n" |
+ " ],\n" |
+ " 'inputs': [\n" |
+ " '../../foo/input1.txt',\n" |
+ " '../../foo/input2.txt',\n" |
+ " ],\n" |
+ " 'outputs': [\n" |
+ " '../../out/Debug/input1.txt.out',\n" |
+ " '../../out/Debug/input2.txt.out',\n" |
+ " ],\n" |
+ " }],\n" |
+ " },\n"; |
+ std::string out_str = out.str(); |
+ EXPECT_EQ(expected, out_str); |
+} |