• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gn/ninja_bundle_data_target_writer.h"
6 
7 #include <algorithm>
8 #include <sstream>
9 
10 #include "gn/target.h"
11 #include "gn/test_with_scope.h"
12 #include "util/test/test.h"
13 
TEST(NinjaBundleDataTargetWriter,Run)14 TEST(NinjaBundleDataTargetWriter, Run) {
15   Err err;
16   TestWithScope setup;
17 
18   Target bundle_data(setup.settings(), Label(SourceDir("//foo/"), "data"));
19   bundle_data.set_output_type(Target::BUNDLE_DATA);
20   bundle_data.sources().push_back(SourceFile("//foo/input1.txt"));
21   bundle_data.sources().push_back(SourceFile("//foo/input2.txt"));
22   bundle_data.sources().push_back(
23       SourceFile("//foo/Foo.xcassets/Contents.json"));
24   bundle_data.sources().push_back(
25       SourceFile("//foo/Foo.xcassets/foo.colorset/Contents.json"));
26   bundle_data.sources().push_back(
27       SourceFile("//foo/Foo.xcassets/foo.imageset/Contents.json"));
28   bundle_data.sources().push_back(
29       SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29.png"));
30   bundle_data.sources().push_back(
31       SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png"));
32   bundle_data.sources().push_back(
33       SourceFile("//foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png"));
34   bundle_data.sources().push_back(
35       SourceFile("//foo/Foo.xcassets/file/with/no/known/pattern"));
36   bundle_data.sources().push_back(
37       SourceFile("//foo/Foo.xcassets/nested/bar.xcassets/my/file"));
38   bundle_data.action_values().outputs() = SubstitutionList::MakeForTest(
39       "{{bundle_resources_dir}}/{{source_file_part}}");
40   bundle_data.SetToolchain(setup.toolchain());
41   bundle_data.visibility().SetPublic();
42   ASSERT_TRUE(bundle_data.OnResolved(&err));
43 
44   std::ostringstream out;
45   NinjaBundleDataTargetWriter writer(&bundle_data, out);
46   writer.Run();
47 
48   const char expected[] =
49       "build obj/foo/data.stamp: stamp "
50       "../../foo/input1.txt "
51       "../../foo/input2.txt "
52       "../../foo/Foo.xcassets/Contents.json "
53       "../../foo/Foo.xcassets/foo.colorset/Contents.json "
54       "../../foo/Foo.xcassets/foo.imageset/Contents.json "
55       "../../foo/Foo.xcassets/foo.imageset/FooIcon-29.png "
56       "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@2x.png "
57       "../../foo/Foo.xcassets/foo.imageset/FooIcon-29@3x.png "
58       "../../foo/Foo.xcassets/file/with/no/known/pattern "
59       "../../foo/Foo.xcassets/nested/bar.xcassets/my/file\n";
60   std::string out_str = out.str();
61   EXPECT_EQ(expected, out_str);
62 }
63