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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 #include "tools/gn/source_dir.h" | 6 #include "tools/gn/source_dir.h" |
7 #include "tools/gn/source_file.h" | 7 #include "tools/gn/source_file.h" |
8 | 8 |
9 // Fails on windows. http://crbug.com/458939 | 9 TEST(SourceDir, ResolveRelativeFile) { |
10 #if defined(OS_WIN) | |
11 #define MAYBE_ResolveRelativeFile DISABLED_ResolveRelativeFile | |
12 #else | |
13 #define MAYBE_ResolveRelativeFile ResolveRelativeFile | |
14 #endif | |
15 TEST(SourceDir, MAYBE_ResolveRelativeFile) { | |
16 SourceDir base("//base/"); | 10 SourceDir base("//base/"); |
17 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
18 base::StringPiece source_root("C:/source/root"); | 12 base::StringPiece source_root("C:/source/root"); |
19 #else | 13 #else |
20 base::StringPiece source_root("/source/root"); | 14 base::StringPiece source_root("/source/root"); |
21 #endif | 15 #endif |
22 | 16 |
23 // Empty input is an error. | 17 // Empty input is an error. |
24 EXPECT_TRUE(base.ResolveRelativeFile("", source_root) == SourceFile()); | 18 EXPECT_TRUE(base.ResolveRelativeFile("", source_root) == SourceFile()); |
25 | 19 |
(...skipping 14 matching lines...) Expand all Loading... |
40 SourceFile("//base/foo")); | 34 SourceFile("//base/foo")); |
41 EXPECT_TRUE(base.ResolveRelativeFile("./foo", source_root) == | 35 EXPECT_TRUE(base.ResolveRelativeFile("./foo", source_root) == |
42 SourceFile("//base/foo")); | 36 SourceFile("//base/foo")); |
43 EXPECT_TRUE(base.ResolveRelativeFile("../foo", source_root) == | 37 EXPECT_TRUE(base.ResolveRelativeFile("../foo", source_root) == |
44 SourceFile("//foo")); | 38 SourceFile("//foo")); |
45 | 39 |
46 // If the given relative path points outside the source root, we | 40 // If the given relative path points outside the source root, we |
47 // expect an absolute path. | 41 // expect an absolute path. |
48 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
49 EXPECT_TRUE(base.ResolveRelativeFile("../../foo", source_root) == | 43 EXPECT_TRUE(base.ResolveRelativeFile("../../foo", source_root) == |
50 SourceFile("C:/source/foo")); | 44 SourceFile("/C:/source/foo")); |
51 #else | 45 #else |
52 EXPECT_TRUE(base.ResolveRelativeFile("../../foo", source_root) == | 46 EXPECT_TRUE(base.ResolveRelativeFile("../../foo", source_root) == |
53 SourceFile("/source/foo")); | 47 SourceFile("/source/foo")); |
54 #endif | 48 #endif |
55 | 49 |
56 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
57 // Note that we don't canonicalize the backslashes to forward slashes. | 51 // Note that we don't canonicalize the backslashes to forward slashes. |
58 // This could potentially be changed in the future which would mean we should | 52 // This could potentially be changed in the future which would mean we should |
59 // just change the expected result. | 53 // just change the expected result. |
60 EXPECT_TRUE(base.ResolveRelativeFile("C:\\foo\\bar.txt", source_root) == | 54 EXPECT_TRUE(base.ResolveRelativeFile("C:\\foo\\bar.txt", source_root) == |
61 SourceFile("/C:/foo/bar.txt")); | 55 SourceFile("/C:/foo/bar.txt")); |
62 #endif | 56 #endif |
63 } | 57 } |
64 | 58 |
65 // Fails on windows. http://crbug.com/458939 | 59 TEST(SourceDir, ResolveRelativeDir) { |
66 #if defined(OS_WIN) | |
67 #define MAYBE_ResolveRelativeDir DISABLED_ResolveRelativeDir | |
68 #else | |
69 #define MAYBE_ResolveRelativeDir ResolveRelativeDir | |
70 #endif | |
71 TEST(SourceDir, MAYBE_ResolveRelativeDir) { | |
72 SourceDir base("//base/"); | 60 SourceDir base("//base/"); |
73 #if defined(OS_WIN) | 61 #if defined(OS_WIN) |
74 base::StringPiece source_root("C:/source/root"); | 62 base::StringPiece source_root("C:/source/root"); |
75 #else | 63 #else |
76 base::StringPiece source_root("/source/root"); | 64 base::StringPiece source_root("/source/root"); |
77 #endif | 65 #endif |
78 | 66 |
79 // Empty input is an error. | 67 // Empty input is an error. |
80 EXPECT_TRUE(base.ResolveRelativeDir("", source_root) == SourceDir()); | 68 EXPECT_TRUE(base.ResolveRelativeDir("", source_root) == SourceDir()); |
81 | 69 |
82 // Absolute paths should be passed unchanged. | 70 // Absolute paths should be passed unchanged. |
83 EXPECT_TRUE(base.ResolveRelativeDir("//foo", source_root) == | 71 EXPECT_TRUE(base.ResolveRelativeDir("//foo", source_root) == |
84 SourceDir("//foo/")); | 72 SourceDir("//foo/")); |
85 EXPECT_TRUE(base.ResolveRelativeDir("/foo", source_root) == | 73 EXPECT_TRUE(base.ResolveRelativeDir("/foo", source_root) == |
86 SourceDir("/foo/")); | 74 SourceDir("/foo/")); |
87 | 75 |
88 // Basic relative stuff. | 76 // Basic relative stuff. |
89 EXPECT_TRUE(base.ResolveRelativeDir("foo", source_root) == | 77 EXPECT_TRUE(base.ResolveRelativeDir("foo", source_root) == |
90 SourceDir("//base/foo/")); | 78 SourceDir("//base/foo/")); |
91 EXPECT_TRUE(base.ResolveRelativeDir("./foo", source_root) == | 79 EXPECT_TRUE(base.ResolveRelativeDir("./foo", source_root) == |
92 SourceDir("//base/foo/")); | 80 SourceDir("//base/foo/")); |
93 EXPECT_TRUE(base.ResolveRelativeDir("../foo", source_root) == | 81 EXPECT_TRUE(base.ResolveRelativeDir("../foo", source_root) == |
94 SourceDir("//foo/")); | 82 SourceDir("//foo/")); |
95 | 83 |
96 // If the given relative path points outside the source root, we | 84 // If the given relative path points outside the source root, we |
97 // expect an absolute path. | 85 // expect an absolute path. |
98 #if defined(OS_WIN) | 86 #if defined(OS_WIN) |
99 EXPECT_TRUE(base.ResolveRelativeDir("../../foo", source_root) == | 87 EXPECT_TRUE(base.ResolveRelativeDir("../../foo", source_root) == |
100 SourceDir("C:/source/foo/")); | 88 SourceDir("/C:/source/foo/")); |
101 #else | 89 #else |
102 EXPECT_TRUE(base.ResolveRelativeDir("../../foo", source_root) == | 90 EXPECT_TRUE(base.ResolveRelativeDir("../../foo", source_root) == |
103 SourceDir("/source/foo/")); | 91 SourceDir("/source/foo/")); |
104 #endif | 92 #endif |
105 | 93 |
106 #if defined(OS_WIN) | 94 #if defined(OS_WIN) |
107 // Note that we don't canonicalize the existing backslashes to forward | 95 // Canonicalize the existing backslashes to forward slashes and add a |
108 // slashes. This could potentially be changed in the future which would mean | 96 // leading slash if necessary. |
109 // we should just change the expected result. | 97 EXPECT_TRUE(base.ResolveRelativeDir("\\C:\\foo") == SourceDir("/C:/foo/")); |
110 EXPECT_TRUE(base.ResolveRelativeDir("C:\\foo") == SourceDir("/C:/foo/")); | 98 EXPECT_TRUE(base.ResolveRelativeDir("C:\\foo") == SourceDir("/C:/foo/")); |
111 #endif | 99 #endif |
112 } | 100 } |
OLD | NEW |