Release the Settings API.
[chromium-blink-merge.git] / tools / gn / ninja_copy_target_writer_unittest.cc
blobb86508b91dc57f9d95fa77085a7ff21dc2ec67cb
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 <algorithm>
6 #include <sstream>
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "tools/gn/file_template.h"
10 #include "tools/gn/ninja_copy_target_writer.h"
11 #include "tools/gn/test_with_scope.h"
13 TEST(NinjaCopyTargetWriter, Run) {
14 TestWithScope setup;
15 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/"));
16 Target target(setup.settings(), Label(SourceDir("//foo/"), "bar"));
17 target.set_output_type(Target::COPY_FILES);
19 target.sources().push_back(SourceFile("//foo/input1.txt"));
20 target.sources().push_back(SourceFile("//foo/input2.txt"));
22 target.action_values().outputs().push_back(
23 SourceFile("//out/Debug/{{source_name_part}}.out"));
25 // Posix.
27 setup.settings()->set_target_os(Settings::LINUX);
29 std::ostringstream out;
30 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out);
31 writer.Run();
33 const char expected_linux[] =
34 "build input1.out: copy ../../foo/input1.txt\n"
35 "build input2.out: copy ../../foo/input2.txt\n"
36 "\n"
37 "build obj/foo/bar.stamp: stamp input1.out input2.out\n";
38 std::string out_str = out.str();
39 #if defined(OS_WIN)
40 std::replace(out_str.begin(), out_str.end(), '\\', '/');
41 #endif
42 EXPECT_EQ(expected_linux, out_str);
45 // Windows.
47 setup.settings()->set_target_os(Settings::WIN);
49 std::ostringstream out;
50 NinjaCopyTargetWriter writer(&target, setup.toolchain(), out);
51 writer.Run();
53 // TODO(brettw) I think we'll need to worry about backslashes here
54 // depending if we're on actual Windows or Linux pretending to be Windows.
55 const char expected_win[] =
56 "build input1.out: copy ../../foo/input1.txt\n"
57 "build input2.out: copy ../../foo/input2.txt\n"
58 "\n"
59 "build obj/foo/bar.stamp: stamp input1.out input2.out\n";
60 std::string out_str = out.str();
61 #if defined(OS_WIN)
62 std::replace(out_str.begin(), out_str.end(), '\\', '/');
63 #endif
64 EXPECT_EQ(expected_win, out_str);