| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "tools/gn/err.h" | 8 #include "tools/gn/err.h" |
| 9 #include "tools/gn/escape.h" | 9 #include "tools/gn/escape.h" |
| 10 #include "tools/gn/substitution_list.h" | 10 #include "tools/gn/substitution_list.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 SubstitutionPattern pattern; | 52 SubstitutionPattern pattern; |
| 53 Err err; | 53 Err err; |
| 54 ASSERT_TRUE(pattern.Parse("{{source_gen_dir}}/{{source_name_part}}.tmp", | 54 ASSERT_TRUE(pattern.Parse("{{source_gen_dir}}/{{source_name_part}}.tmp", |
| 55 NULL, &err)); | 55 NULL, &err)); |
| 56 | 56 |
| 57 OutputFile result = SubstitutionWriter::ApplyPatternToSourceAsOutputFile( | 57 OutputFile result = SubstitutionWriter::ApplyPatternToSourceAsOutputFile( |
| 58 setup.settings(), pattern, SourceFile("//foo/bar/myfile.txt")); | 58 setup.settings(), pattern, SourceFile("//foo/bar/myfile.txt")); |
| 59 ASSERT_EQ("gen/foo/bar/myfile.tmp", result.value()); | 59 ASSERT_EQ("gen/foo/bar/myfile.tmp", result.value()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 TEST(SubstutitionWriter, WriteNinjaVariablesForSource) { | 62 TEST(SubstitutionWriter, WriteNinjaVariablesForSource) { |
| 63 TestWithScope setup; | 63 TestWithScope setup; |
| 64 | 64 |
| 65 std::vector<SubstitutionType> types; | 65 std::vector<SubstitutionType> types; |
| 66 types.push_back(SUBSTITUTION_SOURCE); | 66 types.push_back(SUBSTITUTION_SOURCE); |
| 67 types.push_back(SUBSTITUTION_SOURCE_NAME_PART); | 67 types.push_back(SUBSTITUTION_SOURCE_NAME_PART); |
| 68 types.push_back(SUBSTITUTION_SOURCE_DIR); | 68 types.push_back(SUBSTITUTION_SOURCE_DIR); |
| 69 | 69 |
| 70 EscapeOptions options; | 70 EscapeOptions options; |
| 71 options.mode = ESCAPE_NONE; | 71 options.mode = ESCAPE_NONE; |
| 72 | 72 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 94 options.mode = ESCAPE_NONE; | 94 options.mode = ESCAPE_NONE; |
| 95 | 95 |
| 96 std::ostringstream out; | 96 std::ostringstream out; |
| 97 SubstitutionWriter::WriteWithNinjaVariables(pattern, options, out); | 97 SubstitutionWriter::WriteWithNinjaVariables(pattern, options, out); |
| 98 | 98 |
| 99 EXPECT_EQ( | 99 EXPECT_EQ( |
| 100 "-i ${in} --out=bar\"${source_name_part}\".o", | 100 "-i ${in} --out=bar\"${source_name_part}\".o", |
| 101 out.str()); | 101 out.str()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 TEST(SubstutitionWriter, SourceSubstitutions) { | 104 TEST(SubstitutionWriter, SourceSubstitutions) { |
| 105 TestWithScope setup; | 105 TestWithScope setup; |
| 106 | 106 |
| 107 // Call to get substitutions relative to the build dir. | 107 // Call to get substitutions relative to the build dir. |
| 108 #define GetRelSubst(str, what) \ | 108 #define GetRelSubst(str, what) \ |
| 109 SubstitutionWriter::GetSourceSubstitution( \ | 109 SubstitutionWriter::GetSourceSubstitution( \ |
| 110 setup.settings(), \ | 110 setup.settings(), \ |
| 111 SourceFile(str), \ | 111 SourceFile(str), \ |
| 112 what, \ | 112 what, \ |
| 113 SubstitutionWriter::OUTPUT_RELATIVE, \ | 113 SubstitutionWriter::OUTPUT_RELATIVE, \ |
| 114 setup.settings()->build_settings()->build_dir()) | 114 setup.settings()->build_settings()->build_dir()) |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 // Test that we handle paths that end up in the root build dir properly | 250 // Test that we handle paths that end up in the root build dir properly |
| 251 // (no leading "./" or "/"). | 251 // (no leading "./" or "/"). |
| 252 SubstitutionPattern pattern; | 252 SubstitutionPattern pattern; |
| 253 ASSERT_TRUE( | 253 ASSERT_TRUE( |
| 254 pattern.Parse("{{root_out_dir}}/{{target_output_name}}.so", NULL, &err)); | 254 pattern.Parse("{{root_out_dir}}/{{target_output_name}}.so", NULL, &err)); |
| 255 | 255 |
| 256 OutputFile output = SubstitutionWriter::ApplyPatternToLinkerAsOutputFile( | 256 OutputFile output = SubstitutionWriter::ApplyPatternToLinkerAsOutputFile( |
| 257 &target, tool, pattern); | 257 &target, tool, pattern); |
| 258 EXPECT_EQ("./libbaz.so", output.value()); | 258 EXPECT_EQ("./libbaz.so", output.value()); |
| 259 } | 259 } |
| OLD | NEW |