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

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

Issue 1742303002: Accept absolute Windows paths without leading slash in GN commands (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Format files with 'git cl format' to make presubmit script happy Created 4 years, 8 months 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/label_pattern.cc ('k') | tools/gn/label_unittest.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 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "tools/gn/err.h" 9 #include "tools/gn/err.h"
10 #include "tools/gn/label_pattern.h" 10 #include "tools/gn/label_pattern.h"
(...skipping 10 matching lines...) Expand all
21 const char* name; 21 const char* name;
22 const char* toolchain; 22 const char* toolchain;
23 }; 23 };
24 24
25 } // namespace 25 } // namespace
26 26
27 TEST(LabelPattern, PatternParse) { 27 TEST(LabelPattern, PatternParse) {
28 SourceDir current_dir("//foo/"); 28 SourceDir current_dir("//foo/");
29 PatternCase cases[] = { 29 PatternCase cases[] = {
30 // Missing stuff. 30 // Missing stuff.
31 { "", false, LabelPattern::MATCH, "", "", "" }, 31 {"", false, LabelPattern::MATCH, "", "", ""},
32 { ":", false, LabelPattern::MATCH, "", "", "" }, 32 {":", false, LabelPattern::MATCH, "", "", ""},
33 // Normal things. 33 // Normal things.
34 { ":bar", true, LabelPattern::MATCH, "//foo/", "bar", "" }, 34 {":bar", true, LabelPattern::MATCH, "//foo/", "bar", ""},
35 { "//la:bar", true, LabelPattern::MATCH, "//la/", "bar", "" }, 35 {"//la:bar", true, LabelPattern::MATCH, "//la/", "bar", ""},
36 { "*", true, LabelPattern::RECURSIVE_DIRECTORY, "", "", "" }, 36 {"*", true, LabelPattern::RECURSIVE_DIRECTORY, "", "", ""},
37 { ":*", true, LabelPattern::DIRECTORY, "//foo/", "", "" }, 37 {":*", true, LabelPattern::DIRECTORY, "//foo/", "", ""},
38 { "la:*", true, LabelPattern::DIRECTORY, "//foo/la/", "", "" }, 38 {"la:*", true, LabelPattern::DIRECTORY, "//foo/la/", "", ""},
39 { "la/*:*", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/la/", "", "" }, 39 {"la/*:*", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/la/", "", ""},
40 { "//la:*", true, LabelPattern::DIRECTORY, "//la/", "", "" }, 40 {"//la:*", true, LabelPattern::DIRECTORY, "//la/", "", ""},
41 { "./*", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/", "", "" }, 41 {"./*", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/", "", ""},
42 { "foo/*", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/foo/", "", "" }, 42 {"foo/*", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/foo/", "", ""},
43 { "//l/*", true, LabelPattern::RECURSIVE_DIRECTORY, "//l/", "", "" }, 43 {"//l/*", true, LabelPattern::RECURSIVE_DIRECTORY, "//l/", "", ""},
44 // Toolchains. 44 // Toolchains.
45 { "//foo()", true, LabelPattern::MATCH, "//foo/", "foo", "" }, 45 {"//foo()", true, LabelPattern::MATCH, "//foo/", "foo", ""},
46 { "//foo(//bar)", true, LabelPattern::MATCH, "//foo/", "foo", "//bar:bar" }, 46 {"//foo(//bar)", true, LabelPattern::MATCH, "//foo/", "foo", "//bar:bar"},
47 { "//foo:*(//bar)", true, LabelPattern::DIRECTORY, "//foo/", "", 47 {"//foo:*(//bar)", true, LabelPattern::DIRECTORY, "//foo/", "",
48 "//bar:bar" }, 48 "//bar:bar"},
49 { "//foo/*(//bar)", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/", "", 49 {"//foo/*(//bar)", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/", "",
50 "//bar:bar" }, 50 "//bar:bar"},
51 // Wildcards in invalid places. 51 // Wildcards in invalid places.
52 { "*foo*:bar", false, LabelPattern::MATCH, "", "", "" }, 52 {"*foo*:bar", false, LabelPattern::MATCH, "", "", ""},
53 { "foo*:*bar", false, LabelPattern::MATCH, "", "", "" }, 53 {"foo*:*bar", false, LabelPattern::MATCH, "", "", ""},
54 { "*foo:bar", false, LabelPattern::MATCH, "", "", "" }, 54 {"*foo:bar", false, LabelPattern::MATCH, "", "", ""},
55 { "foo:bar*", false, LabelPattern::MATCH, "", "", "" }, 55 {"foo:bar*", false, LabelPattern::MATCH, "", "", ""},
56 { "*:*", true, LabelPattern::RECURSIVE_DIRECTORY, "", "", "" }, 56 {"*:*", true, LabelPattern::RECURSIVE_DIRECTORY, "", "", ""},
57 // Invalid toolchain stuff. 57 // Invalid toolchain stuff.
58 { "//foo(//foo/bar:*)", false, LabelPattern::MATCH, "", "", "" }, 58 {"//foo(//foo/bar:*)", false, LabelPattern::MATCH, "", "", ""},
59 { "//foo/*(*)", false, LabelPattern::MATCH, "", "", "" }, 59 {"//foo/*(*)", false, LabelPattern::MATCH, "", "", ""},
60 { "//foo(//bar", false, LabelPattern::MATCH, "", "", "" }, 60 {"//foo(//bar", false, LabelPattern::MATCH, "", "", ""},
61 // Absolute paths.
62 {"/la/*", true, LabelPattern::RECURSIVE_DIRECTORY, "/la/", "", ""},
63 {"/la:bar", true, LabelPattern::MATCH, "/la/", "bar", ""},
64 #if defined(OS_WIN)
65 {"/C:/la/*", true, LabelPattern::RECURSIVE_DIRECTORY, "/C:/la/", "", ""},
66 {"C:/la/*", true, LabelPattern::RECURSIVE_DIRECTORY, "/C:/la/", "", ""},
67 {"/C:/la:bar", true, LabelPattern::MATCH, "/C:/la/", "bar", ""},
68 {"C:/la:bar", true, LabelPattern::MATCH, "/C:/la/", "bar", ""},
69 {"C:foo", true, LabelPattern::MATCH, "//foo/C/", "foo", ""},
70 #endif
61 }; 71 };
62 72
63 for (size_t i = 0; i < arraysize(cases); i++) { 73 for (size_t i = 0; i < arraysize(cases); i++) {
64 const PatternCase& cur = cases[i]; 74 const PatternCase& cur = cases[i];
65 Err err; 75 Err err;
66 LabelPattern result = 76 LabelPattern result =
67 LabelPattern::GetPattern(current_dir, Value(nullptr, cur.input), &err); 77 LabelPattern::GetPattern(current_dir, Value(nullptr, cur.input), &err);
68 78
69 EXPECT_EQ(cur.success, !err.has_error()) << i << " " << cur.input; 79 EXPECT_EQ(cur.success, !err.has_error()) << i << " " << cur.input;
70 EXPECT_EQ(cur.type, result.type()) << i << " " << cur.input; 80 EXPECT_EQ(cur.type, result.type()) << i << " " << cur.input;
71 EXPECT_EQ(cur.dir, result.dir().value()) << i << " " << cur.input; 81 EXPECT_EQ(cur.dir, result.dir().value()) << i << " " << cur.input;
72 EXPECT_EQ(cur.name, result.name()) << i << " " << cur.input; 82 EXPECT_EQ(cur.name, result.name()) << i << " " << cur.input;
73 EXPECT_EQ(cur.toolchain, result.toolchain().GetUserVisibleName(false)) 83 EXPECT_EQ(cur.toolchain, result.toolchain().GetUserVisibleName(false))
74 << i << " " << cur.input; 84 << i << " " << cur.input;
75 } 85 }
76 } 86 }
OLDNEW
« no previous file with comments | « tools/gn/label_pattern.cc ('k') | tools/gn/label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698