OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 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 "testing/gtest/include/gtest/gtest.h" | |
6 | |
7 #include "tools/gn/build_settings.h" | |
8 #include "tools/gn/filesystem_utils.h" | |
9 #include "tools/gn/ninja_helper.h" | |
10 #include "tools/gn/settings.h" | |
11 #include "tools/gn/target.h" | |
12 #include "tools/gn/toolchain.h" | |
13 | |
14 namespace { | |
15 | |
16 class HelperSetterUpper { | |
17 public: | |
18 HelperSetterUpper() | |
19 : build_settings(), | |
20 settings(&build_settings, std::string()), | |
21 toolchain(&settings, Label(SourceDir("//"), "tc")), | |
22 target(&settings, Label(SourceDir("//tools/gn/"), "name")) { | |
23 settings.set_toolchain_label(toolchain.label()); | |
24 settings.set_target_os(Settings::WIN); | |
25 | |
26 // Output going to "out/Debug". | |
27 build_settings.SetBuildDir(SourceDir("//out/Debug/")); | |
28 | |
29 // Our source target is in "tools/gn". | |
30 target.set_output_type(Target::EXECUTABLE); | |
31 } | |
32 | |
33 BuildSettings build_settings; | |
34 Settings settings; | |
35 Toolchain toolchain; | |
36 Target target; | |
37 }; | |
38 | |
39 } // namespace | |
40 | |
41 TEST(NinjaHelper, GetNinjaFileForTarget) { | |
42 HelperSetterUpper setup; | |
43 NinjaHelper helper(&setup.build_settings); | |
44 | |
45 // Default toolchain. | |
46 EXPECT_EQ(OutputFile("obj/tools/gn/name.ninja").value(), | |
47 helper.GetNinjaFileForTarget(&setup.target).value()); | |
48 } | |
49 | |
50 TEST(NinjaHelper, GetOutputFileForSource) { | |
51 HelperSetterUpper setup; | |
52 NinjaHelper helper(&setup.build_settings); | |
53 | |
54 // On Windows, expect ".obj" | |
55 EXPECT_EQ(OutputFile("obj/tools/gn/name.foo.obj").value(), | |
56 helper.GetOutputFileForSource(&setup.target, | |
57 SourceFile("//tools/gn/foo.cc"), | |
58 SOURCE_CC).value()); | |
59 } | |
60 | |
61 TEST(NinjaHelper, GetOutputFileForObject) { | |
62 HelperSetterUpper setup; | |
63 NinjaHelper helper(&setup.build_settings); | |
64 | |
65 EXPECT_EQ(OutputFile("../../tools/gn/foo.o").value(), | |
66 helper.GetOutputFileForSource(&setup.target, | |
67 SourceFile("//tools/gn/foo.o"), | |
68 SOURCE_O).value()); | |
69 | |
70 EXPECT_EQ(OutputFile("../../tools/gn/foo.obj").value(), | |
71 helper.GetOutputFileForSource(&setup.target, | |
72 SourceFile("//tools/gn/foo.obj"), | |
73 SOURCE_O).value()); | |
74 | |
75 EXPECT_EQ(OutputFile("nested/foo.o").value(), | |
76 helper.GetOutputFileForSource( | |
77 &setup.target, | |
78 SourceFile("//out/Debug/nested/foo.o"), | |
79 SOURCE_O).value()); | |
80 | |
81 EXPECT_EQ(OutputFile("/abs/rooted/foo.o").value(), | |
82 helper.GetOutputFileForSource(&setup.target, | |
83 SourceFile("/abs/rooted/foo.o"), | |
84 SOURCE_O).value()); | |
85 } | |
86 | |
87 TEST(NinjaHelper, GetTargetOutputFile) { | |
88 HelperSetterUpper setup; | |
89 NinjaHelper helper(&setup.build_settings); | |
90 EXPECT_EQ(OutputFile("name.exe"), | |
91 helper.GetTargetOutputFile(&setup.target)); | |
92 | |
93 // Static library on Windows goes alongside the object files. | |
94 setup.target.set_output_type(Target::STATIC_LIBRARY); | |
95 EXPECT_EQ(OutputFile("obj/tools/gn/name.lib"), | |
96 helper.GetTargetOutputFile(&setup.target)); | |
97 | |
98 // TODO(brettw) test output to library and other OS types. | |
99 } | |
OLD | NEW |