OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 #include "tools/gn/functions.h" | 7 #include "tools/gn/functions.h" |
8 #include "tools/gn/parse_tree.h" | 8 #include "tools/gn/parse_tree.h" |
9 #include "tools/gn/test_with_scope.h" | 9 #include "tools/gn/test_with_scope.h" |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 std::string RebaseOne(Scope* scope, | 13 std::string RebaseOne(Scope* scope, |
14 const char* input, | 14 const char* input, |
15 const char* to_dir, | 15 const char* to_dir, |
16 const char* from_dir, | 16 const char* from_dir) { |
17 const char* sep = NULL) { | |
18 std::vector<Value> args; | 17 std::vector<Value> args; |
19 args.push_back(Value(NULL, input)); | 18 args.push_back(Value(NULL, input)); |
20 args.push_back(Value(NULL, to_dir)); | 19 args.push_back(Value(NULL, to_dir)); |
21 args.push_back(Value(NULL, from_dir)); | 20 args.push_back(Value(NULL, from_dir)); |
22 if (sep) | |
23 args.push_back(Value(NULL, sep)); | |
24 | 21 |
25 Err err; | 22 Err err; |
26 FunctionCallNode function; | 23 FunctionCallNode function; |
27 Value result = functions::RunRebasePath(scope, &function, args, &err); | 24 Value result = functions::RunRebasePath(scope, &function, args, &err); |
28 bool is_string = result.type() == Value::STRING; | 25 bool is_string = result.type() == Value::STRING; |
29 EXPECT_TRUE(is_string); | 26 EXPECT_TRUE(is_string); |
30 | 27 |
31 return result.string_value(); | 28 return result.string_value(); |
32 } | 29 } |
33 | 30 |
(...skipping 19 matching lines...) Expand all Loading... |
53 EXPECT_EQ("./", RebaseOne(scope, "//", "//", "//")); | 50 EXPECT_EQ("./", RebaseOne(scope, "//", "//", "//")); |
54 EXPECT_EQ("foo", RebaseOne(scope, "//foo", "//", "//")); | 51 EXPECT_EQ("foo", RebaseOne(scope, "//foo", "//", "//")); |
55 EXPECT_EQ("foo/", RebaseOne(scope, "//foo/", "//", "//")); | 52 EXPECT_EQ("foo/", RebaseOne(scope, "//foo/", "//", "//")); |
56 EXPECT_EQ("../../foo/bar", RebaseOne(scope, "//foo/bar", "//out/Debug", ".")); | 53 EXPECT_EQ("../../foo/bar", RebaseOne(scope, "//foo/bar", "//out/Debug", ".")); |
57 EXPECT_EQ("./", RebaseOne(scope, "//foo/", "//foo/", "//")); | 54 EXPECT_EQ("./", RebaseOne(scope, "//foo/", "//foo/", "//")); |
58 // Thie one is technically correct but could be simplified to "." if | 55 // Thie one is technically correct but could be simplified to "." if |
59 // necessary. | 56 // necessary. |
60 EXPECT_EQ("../foo", RebaseOne(scope, "//foo", "//foo", "//")); | 57 EXPECT_EQ("../foo", RebaseOne(scope, "//foo", "//foo", "//")); |
61 | 58 |
62 // Test slash conversion. | 59 // Test slash conversion. |
63 EXPECT_EQ("foo/bar", RebaseOne(scope, "foo/bar", ".", ".", "to_slash")); | 60 EXPECT_EQ("foo/bar", RebaseOne(scope, "foo/bar", ".", ".")); |
64 EXPECT_EQ("foo/bar", RebaseOne(scope, "foo\\bar", ".", ".", "to_slash")); | 61 EXPECT_EQ("foo/bar", RebaseOne(scope, "foo\\bar", ".", ".")); |
65 #if defined(OS_WIN) | |
66 EXPECT_EQ("foo\\bar", RebaseOne(scope, "foo/bar", ".", ".", "to_system")); | |
67 EXPECT_EQ("foo\\bar", RebaseOne(scope, "foo\\bar", ".", ".", "to_system")); | |
68 #endif | |
69 | 62 |
70 // Test system path output. | 63 // Test system path output. |
71 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
72 setup.build_settings()->SetRootPath(base::FilePath(L"C:\\source")); | 65 setup.build_settings()->SetRootPath(base::FilePath(L"C:/source")); |
73 EXPECT_EQ("C:\\source", RebaseOne(scope, ".", "", "//")); | 66 EXPECT_EQ("C:/source", RebaseOne(scope, ".", "", "//")); |
74 EXPECT_EQ("C:\\source\\", RebaseOne(scope, "//", "", "//")); | 67 EXPECT_EQ("C:/source/", RebaseOne(scope, "//", "", "//")); |
75 EXPECT_EQ("C:\\source\\foo", RebaseOne(scope, "foo", "", "//")); | 68 EXPECT_EQ("C:/source/foo", RebaseOne(scope, "foo", "", "//")); |
76 EXPECT_EQ("C:\\source\\foo\\", RebaseOne(scope, "foo/", "", "//")); | 69 EXPECT_EQ("C:/source/foo/", RebaseOne(scope, "foo/", "", "//")); |
77 EXPECT_EQ("C:\\source\\tools\\gn\\foo", RebaseOne(scope, "foo", "", ".")); | 70 EXPECT_EQ("C:/source/tools/gn/foo", RebaseOne(scope, "foo", "", ".")); |
78 #else | 71 #else |
79 setup.build_settings()->SetRootPath(base::FilePath("/source")); | 72 setup.build_settings()->SetRootPath(base::FilePath("/source")); |
80 EXPECT_EQ("/source", RebaseOne(scope, ".", "", "//")); | 73 EXPECT_EQ("/source", RebaseOne(scope, ".", "", "//")); |
81 EXPECT_EQ("/source/", RebaseOne(scope, "//", "", "//")); | 74 EXPECT_EQ("/source/", RebaseOne(scope, "//", "", "//")); |
82 EXPECT_EQ("/source/foo", RebaseOne(scope, "foo", "", "//")); | 75 EXPECT_EQ("/source/foo", RebaseOne(scope, "foo", "", "//")); |
83 EXPECT_EQ("/source/foo/", RebaseOne(scope, "foo/", "", "//")); | 76 EXPECT_EQ("/source/foo/", RebaseOne(scope, "foo/", "", "//")); |
84 EXPECT_EQ("/source/tools/gn/foo", RebaseOne(scope, "foo", "", ".")); | 77 EXPECT_EQ("/source/tools/gn/foo", RebaseOne(scope, "foo", "", ".")); |
85 #endif | 78 #endif |
86 } | 79 } |
87 | 80 |
(...skipping 26 matching lines...) Expand all Loading... |
114 TestWithScope setup; | 107 TestWithScope setup; |
115 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); | 108 setup.build_settings()->SetBuildDir(SourceDir("//out/Debug/")); |
116 | 109 |
117 // No arg input should issue an error. | 110 // No arg input should issue an error. |
118 Err err; | 111 Err err; |
119 std::vector<Value> args; | 112 std::vector<Value> args; |
120 FunctionCallNode function; | 113 FunctionCallNode function; |
121 Value ret = functions::RunRebasePath(setup.scope(), &function, args, &err); | 114 Value ret = functions::RunRebasePath(setup.scope(), &function, args, &err); |
122 EXPECT_TRUE(err.has_error()); | 115 EXPECT_TRUE(err.has_error()); |
123 } | 116 } |
OLD | NEW |