ninja_copy_target_writer_unittest.cc revision 5f1c94371a64b3196d4be9466099bb892df9b88e
1d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// found in the LICENSE file. 4d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)#include <algorithm> 6d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include <sstream> 7d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 8d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 9d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "tools/gn/ninja_copy_target_writer.h" 10d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "tools/gn/test_with_scope.h" 11d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 12116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch// Tests mutliple files with an output pattern and no toolchain dependency. 13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)TEST(NinjaCopyTargetWriter, Run) { 14d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) TestWithScope setup; 15116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch setup.settings()->set_target_os(Settings::LINUX); 16d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 17d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 18d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) target.set_output_type(Target::COPY_FILES); 19d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 20d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) target.sources().push_back(SourceFile("//foo/input1.txt")); 21d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) target.sources().push_back(SourceFile("//foo/input2.txt")); 22d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) target.action_values().outputs() = 245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SubstitutionList::MakeForTest("//out/Debug/{{source_name_part}}.out"); 25d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 26116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch std::ostringstream out; 27116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); 28116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch writer.Run(); 29d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 30116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const char expected_linux[] = 31116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch "build input1.out: copy ../../foo/input1.txt\n" 32116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch "build input2.out: copy ../../foo/input2.txt\n" 33116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch "\n" 34116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch "build obj/foo/bar.stamp: stamp input1.out input2.out\n"; 35116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch std::string out_str = out.str(); 36116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_EQ(expected_linux, out_str); 37116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch} 38116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Tests a single file with no output pattern. 40116680a4aac90f2aa7413d9095a592090648e557Ben MurdochTEST(NinjaCopyTargetWriter, ToolchainDeps) { 41116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch TestWithScope setup; 42116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch setup.settings()->set_target_os(Settings::LINUX); 43116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); 44116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch Target target(setup.settings(), Label(SourceDir("//foo/"), "bar")); 45116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch target.set_output_type(Target::COPY_FILES); 46d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 47116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch target.sources().push_back(SourceFile("//foo/input1.txt")); 48d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) target.action_values().outputs() = 505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) SubstitutionList::MakeForTest("//out/Debug/output.out"); 51d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 52116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch std::ostringstream out; 53116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch NinjaCopyTargetWriter writer(&target, setup.toolchain(), out); 54116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch writer.Run(); 55d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 56116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const char expected_linux[] = 575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) "build output.out: copy ../../foo/input1.txt\n" 58116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch "\n" 59116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch "build obj/foo/bar.stamp: stamp output.out\n"; 60116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch std::string out_str = out.str(); 61116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch EXPECT_EQ(expected_linux, out_str); 62d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 63