Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: tools/gn/source_dir_unittest.cc

Issue 711113004: original (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: win compile fix Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/source_dir.cc ('k') | tools/gn/substitution_writer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 TEST(SourceDir, ResolveRelativeFile) { 9 TEST(SourceDir, ResolveRelativeFile) {
10 SourceDir base("//base/"); 10 SourceDir base("//base/");
11 base::StringPiece source_root("/source/root");
11 12
12 // Empty input is an error. 13 // Empty input is an error.
13 EXPECT_TRUE(base.ResolveRelativeFile("") == SourceFile()); 14 EXPECT_TRUE(base.ResolveRelativeFile("", source_root) == SourceFile());
14 15
15 // These things are directories, so should be an error. 16 // These things are directories, so should be an error.
16 EXPECT_TRUE(base.ResolveRelativeFile("//foo/bar/") == SourceFile()); 17 EXPECT_TRUE(base.ResolveRelativeFile("//foo/bar/", source_root) ==
17 EXPECT_TRUE(base.ResolveRelativeFile("bar/") == SourceFile()); 18 SourceFile());
19 EXPECT_TRUE(base.ResolveRelativeFile("bar/", source_root) ==
20 SourceFile());
18 21
19 // Absolute paths should be passed unchanged. 22 // Absolute paths should be passed unchanged.
20 EXPECT_TRUE(base.ResolveRelativeFile("//foo") == SourceFile("//foo")); 23 EXPECT_TRUE(base.ResolveRelativeFile("//foo",source_root) ==
21 EXPECT_TRUE(base.ResolveRelativeFile("/foo") == SourceFile("/foo")); 24 SourceFile("//foo"));
25 EXPECT_TRUE(base.ResolveRelativeFile("/foo", source_root) ==
26 SourceFile("/foo"));
22 27
23 // Basic relative stuff. 28 // Basic relative stuff.
24 EXPECT_TRUE(base.ResolveRelativeFile("foo") == SourceFile("//base/foo")); 29 EXPECT_TRUE(base.ResolveRelativeFile("foo", source_root) ==
25 EXPECT_TRUE(base.ResolveRelativeFile("./foo") == SourceFile("//base/foo")); 30 SourceFile("//base/foo"));
26 EXPECT_TRUE(base.ResolveRelativeFile("../foo") == SourceFile("//foo")); 31 EXPECT_TRUE(base.ResolveRelativeFile("./foo", source_root) ==
27 EXPECT_TRUE(base.ResolveRelativeFile("../../foo") == SourceFile("//foo")); 32 SourceFile("//base/foo"));
33 EXPECT_TRUE(base.ResolveRelativeFile("../foo", source_root) ==
34 SourceFile("//foo"));
35
36 // If the given relative path points outside the source root, we
37 // expect an absolute path.
38 EXPECT_TRUE(base.ResolveRelativeFile("../../foo", source_root) ==
39 SourceFile("/source/foo"));
28 40
29 #if defined(OS_WIN) 41 #if defined(OS_WIN)
30 // Note that we don't canonicalize the backslashes to forward slashes. 42 // Note that we don't canonicalize the backslashes to forward slashes.
31 // This could potentially be changed in the future which would mean we should 43 // This could potentially be changed in the future which would mean we should
32 // just change the expected result. 44 // just change the expected result.
33 EXPECT_TRUE(base.ResolveRelativeFile("C:\\foo\\bar.txt") == 45 EXPECT_TRUE(base.ResolveRelativeFile("C:\\foo\\bar.txt", source_root) ==
34 SourceFile("/C:/foo/bar.txt")); 46 SourceFile("/C:/foo/bar.txt"));
35 #endif 47 #endif
36 } 48 }
37 49
38 TEST(SourceDir, ResolveRelativeDir) { 50 TEST(SourceDir, ResolveRelativeDir) {
39 SourceDir base("//base/"); 51 SourceDir base("//base/");
52 base::StringPiece source_root("/source/root");
40 53
41 // Empty input is an error. 54 // Empty input is an error.
42 EXPECT_TRUE(base.ResolveRelativeDir("") == SourceDir()); 55 EXPECT_TRUE(base.ResolveRelativeDir("", source_root) == SourceDir());
43 56
44 // Absolute paths should be passed unchanged. 57 // Absolute paths should be passed unchanged.
45 EXPECT_TRUE(base.ResolveRelativeDir("//foo") == SourceDir("//foo/")); 58 EXPECT_TRUE(base.ResolveRelativeDir("//foo", source_root) ==
46 EXPECT_TRUE(base.ResolveRelativeDir("/foo") == SourceDir("/foo/")); 59 SourceDir("//foo/"));
60 EXPECT_TRUE(base.ResolveRelativeDir("/foo", source_root) ==
61 SourceDir("/foo/"));
47 62
48 // Basic relative stuff. 63 // Basic relative stuff.
49 EXPECT_TRUE(base.ResolveRelativeDir("foo") == SourceDir("//base/foo/")); 64 EXPECT_TRUE(base.ResolveRelativeDir("foo", source_root) ==
50 EXPECT_TRUE(base.ResolveRelativeDir("./foo") == SourceDir("//base/foo/")); 65 SourceDir("//base/foo/"));
51 EXPECT_TRUE(base.ResolveRelativeDir("../foo") == SourceDir("//foo/")); 66 EXPECT_TRUE(base.ResolveRelativeDir("./foo", source_root) ==
52 EXPECT_TRUE(base.ResolveRelativeDir("../../foo/") == SourceDir("//foo/")); 67 SourceDir("//base/foo/"));
68 EXPECT_TRUE(base.ResolveRelativeDir("../foo", source_root) ==
69 SourceDir("//foo/"));
70
71 // If the given relative path points outside the source root, we
72 // expect an absolute path.
73 EXPECT_TRUE(base.ResolveRelativeDir("../../foo", source_root) ==
74 SourceDir("/source/foo/"));
53 75
54 #if defined(OS_WIN) 76 #if defined(OS_WIN)
55 // Note that we don't canonicalize the existing backslashes to forward 77 // Note that we don't canonicalize the existing backslashes to forward
56 // slashes. This could potentially be changed in the future which would mean 78 // slashes. This could potentially be changed in the future which would mean
57 // we should just change the expected result. 79 // we should just change the expected result.
58 EXPECT_TRUE(base.ResolveRelativeDir("C:\\foo") == SourceDir("/C:/foo/")); 80 EXPECT_TRUE(base.ResolveRelativeDir("C:\\foo") == SourceDir("/C:/foo/"));
59 #endif 81 #endif
60 } 82 }
OLDNEW
« no previous file with comments | « tools/gn/source_dir.cc ('k') | tools/gn/substitution_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698