Home | History | Annotate | Download | only in gn
      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 <algorithm>
      6 #include <sstream>
      7 
      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"
     12 
     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);
     18 
     19   target.sources().push_back(SourceFile("//foo/input1.txt"));
     20   target.sources().push_back(SourceFile("//foo/input2.txt"));
     21 
     22   target.action_values().outputs().push_back(
     23       SourceFile("//out/Debug/{{source_name_part}}.out"));
     24 
     25   // Posix.
     26   {
     27     setup.settings()->set_target_os(Settings::LINUX);
     28 
     29     std::ostringstream out;
     30     NinjaCopyTargetWriter writer(&target, setup.toolchain(), out);
     31     writer.Run();
     32 
     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);
     43   }
     44 
     45   // Windows.
     46   {
     47     setup.settings()->set_target_os(Settings::WIN);
     48 
     49     std::ostringstream out;
     50     NinjaCopyTargetWriter writer(&target, setup.toolchain(), out);
     51     writer.Run();
     52 
     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);
     65   }
     66 }
     67