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.
5 #include "testing/gtest/include/gtest/gtest.h"
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"
16 class HelperSetterUpper
{
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
);
26 // Output going to "out/Debug".
27 build_settings
.SetBuildDir(SourceDir("/out/Debug/"));
29 // Our source target is in "tools/gn".
30 target
.set_output_type(Target::EXECUTABLE
);
33 BuildSettings build_settings
;
41 TEST(NinjaHelper
, GetNinjaFileForTarget
) {
42 HelperSetterUpper setup
;
43 NinjaHelper
helper(&setup
.build_settings
);
46 EXPECT_EQ(OutputFile("obj/tools/gn/name.ninja").value(),
47 helper
.GetNinjaFileForTarget(&setup
.target
).value());
50 TEST(NinjaHelper
, GetOutputFileForSource
) {
51 HelperSetterUpper setup
;
52 NinjaHelper
helper(&setup
.build_settings
);
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"),
61 TEST(NinjaHelper
, GetTargetOutputFile
) {
62 HelperSetterUpper setup
;
63 NinjaHelper
helper(&setup
.build_settings
);
64 EXPECT_EQ(OutputFile("name.exe"),
65 helper
.GetTargetOutputFile(&setup
.target
));
67 // Static library on Windows goes alongside the object files.
68 setup
.target
.set_output_type(Target::STATIC_LIBRARY
);
69 EXPECT_EQ(OutputFile("obj/tools/gn/name.lib"),
70 helper
.GetTargetOutputFile(&setup
.target
));
72 // TODO(brettw) test output to library and other OS types.