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

Unified Diff: tools/gn/label_pattern_unittest.cc

Issue 500423003: Enhance GN diagnostic tools (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use patterns for gn check Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/label_pattern.cc ('k') | tools/gn/pattern.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/label_pattern_unittest.cc
diff --git a/tools/gn/label_pattern_unittest.cc b/tools/gn/label_pattern_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..21d6a9b12149f39cea41864b06e8ec1f697f1b74
--- /dev/null
+++ b/tools/gn/label_pattern_unittest.cc
@@ -0,0 +1,73 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "tools/gn/err.h"
+#include "tools/gn/label_pattern.h"
+#include "tools/gn/value.h"
+
+namespace {
+
+struct PatternCase {
+ const char* input;
+ bool success;
+
+ LabelPattern::Type type;
+ const char* dir;
+ const char* name;
+ const char* toolchain;
+};
+
+} // namespace
+
+TEST(LabelPattern, PatternParse) {
+ SourceDir current_dir("//foo/");
+ PatternCase cases[] = {
+ // Missing stuff.
+ { "", false, LabelPattern::MATCH, "", "", "" },
+ { ":", false, LabelPattern::MATCH, "", "", "" },
+ // Normal things.
+ { ":bar", true, LabelPattern::MATCH, "//foo/", "bar", "" },
+ { "//la:bar", true, LabelPattern::MATCH, "//la/", "bar", "" },
+ { "*", true, LabelPattern::RECURSIVE_DIRECTORY, "", "", "" },
+ { ":*", true, LabelPattern::DIRECTORY, "//foo/", "", "" },
+ { "la:*", true, LabelPattern::DIRECTORY, "//foo/la/", "", "" },
+ { "la/*:*", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/la/", "", "" },
+ { "//la:*", true, LabelPattern::DIRECTORY, "//la/", "", "" },
+ { "./*", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/", "", "" },
+ { "foo/*", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/foo/", "", "" },
+ { "//l/*", true, LabelPattern::RECURSIVE_DIRECTORY, "//l/", "", "" },
+ // Toolchains.
+ { "//foo()", true, LabelPattern::MATCH, "//foo/", "foo", "" },
+ { "//foo(//bar)", true, LabelPattern::MATCH, "//foo/", "foo", "//bar:bar" },
+ { "//foo:*(//bar)", true, LabelPattern::DIRECTORY, "//foo/", "",
+ "//bar:bar" },
+ { "//foo/*(//bar)", true, LabelPattern::RECURSIVE_DIRECTORY, "//foo/", "",
+ "//bar:bar" },
+ // Wildcards in invalid places.
+ { "*foo*:bar", false, LabelPattern::MATCH, "", "", "" },
+ { "foo*:*bar", false, LabelPattern::MATCH, "", "", "" },
+ { "*foo:bar", false, LabelPattern::MATCH, "", "", "" },
+ { "foo:bar*", false, LabelPattern::MATCH, "", "", "" },
+ { "*:*", true, LabelPattern::RECURSIVE_DIRECTORY, "", "", "" },
+ // Invalid toolchain stuff.
+ { "//foo(//foo/bar:*)", false, LabelPattern::MATCH, "", "", "" },
+ { "//foo/*(*)", false, LabelPattern::MATCH, "", "", "" },
+ { "//foo(//bar", false, LabelPattern::MATCH, "", "", "" },
+ };
+
+ for (size_t i = 0; i < arraysize(cases); i++) {
+ const PatternCase& cur = cases[i];
+ Err err;
+ LabelPattern result =
+ LabelPattern::GetPattern(current_dir, Value(NULL, cur.input), &err);
+
+ EXPECT_EQ(cur.success, !err.has_error()) << i << " " << cur.input;
+ EXPECT_EQ(cur.type, result.type()) << i << " " << cur.input;
+ EXPECT_EQ(cur.dir, result.dir().value()) << i << " " << cur.input;
+ EXPECT_EQ(cur.name, result.name()) << i << " " << cur.input;
+ EXPECT_EQ(cur.toolchain, result.toolchain().GetUserVisibleName(false))
+ << i << " " << cur.input;
+ }
+}
« no previous file with comments | « tools/gn/label_pattern.cc ('k') | tools/gn/pattern.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698