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

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

Issue 2936923002: Add not_needed function (Closed)
Patch Set: Rebase Created 3 years, 5 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/functions.cc ('k') | tools/gn/scope.h » ('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/scheduler.h" 6 #include "tools/gn/scheduler.h"
7 #include "tools/gn/scope.h" 7 #include "tools/gn/scope.h"
8 #include "tools/gn/test_with_scope.h" 8 #include "tools/gn/test_with_scope.h"
9 9
10 10
(...skipping 19 matching lines...) Expand all
30 TestParseInput source_set_input( 30 TestParseInput source_set_input(
31 "source_set(\"foo\") {\n" 31 "source_set(\"foo\") {\n"
32 " unused = 5\n" 32 " unused = 5\n"
33 "}\n"); 33 "}\n");
34 ASSERT_FALSE(source_set_input.has_error()); 34 ASSERT_FALSE(source_set_input.has_error());
35 err = Err(); 35 err = Err();
36 source_set_input.parsed()->Execute(setup.scope(), &err); 36 source_set_input.parsed()->Execute(setup.scope(), &err);
37 ASSERT_TRUE(err.has_error()); 37 ASSERT_TRUE(err.has_error());
38 } 38 }
39 39
40 // Checks that we find uses of identifiers marked as not needed.
41 TEST(FunctionsTarget, CheckNotNeeded) {
42 Scheduler scheduler;
43 TestWithScope setup;
44
45 // The target generator needs a place to put the targets or it will fail.
46 Scope::ItemVector item_collector;
47 setup.scope()->set_item_collector(&item_collector);
48
49 TestParseInput nonscoped_input(
50 "source_set(\"foo\") {\n"
51 " a = 1\n"
52 " not_needed([ \"a\" ])\n"
53 "}\n");
54 ASSERT_FALSE(nonscoped_input.has_error());
55 Err err;
56 nonscoped_input.parsed()->Execute(setup.scope(), &err);
57 ASSERT_FALSE(err.has_error()) << err.message();
58
59 TestParseInput scoped_input(
60 "source_set(\"foo\") {\n"
61 " a = {x = 1 y = 2}\n"
62 " not_needed(a, \"*\")\n"
63 "}\n");
64 ASSERT_FALSE(scoped_input.has_error());
65 err = Err();
66 scoped_input.parsed()->Execute(setup.scope(), &err);
67 ASSERT_FALSE(err.has_error()) << err.message();
68
69 TestParseInput exclusion_input(
70 "source_set(\"foo\") {\n"
71 " x = 1\n"
72 " y = 2\n"
73 " not_needed(\"*\", [ \"y\" ])\n"
74 "}\n");
75 ASSERT_FALSE(exclusion_input.has_error());
76 err = Err();
77 exclusion_input.parsed()->Execute(setup.scope(), &err);
78 ASSERT_TRUE(err.has_error()) << err.message();
79 EXPECT_EQ("Assignment had no effect.", err.message());
80
81 TestParseInput error_input(
82 "source_set(\"foo\") {\n"
83 " a = {x = 1 y = 2}\n"
84 " not_needed(a, [ \"x \"], [ \"y\" ])\n"
85 "}\n");
86 ASSERT_FALSE(error_input.has_error());
87 err = Err();
88 error_input.parsed()->Execute(setup.scope(), &err);
89 ASSERT_TRUE(err.has_error());
90 EXPECT_EQ("Not supported with a variable list.", err.message());
91 }
92
40 // Checks that the defaults applied to a template invoked by target() use 93 // Checks that the defaults applied to a template invoked by target() use
41 // the name of the template, rather than the string "target" (which is the 94 // the name of the template, rather than the string "target" (which is the
42 // name of the actual function being called). 95 // name of the actual function being called).
43 TEST(FunctionsTarget, TemplateDefaults) { 96 TEST(FunctionsTarget, TemplateDefaults) {
44 Scheduler scheduler; 97 Scheduler scheduler;
45 TestWithScope setup; 98 TestWithScope setup;
46 99
47 // The target generator needs a place to put the targets or it will fail. 100 // The target generator needs a place to put the targets or it will fail.
48 Scope::ItemVector item_collector; 101 Scope::ItemVector item_collector;
49 setup.scope()->set_item_collector(&item_collector); 102 setup.scope()->set_item_collector(&item_collector);
(...skipping 13 matching lines...) Expand all
63 # Invoke the template with target(). This will fail to execute if the 116 # Invoke the template with target(). This will fail to execute if the
64 # defaults were not set properly, because "default_value" won't exist. 117 # defaults were not set properly, because "default_value" won't exist.
65 target("my_templ", "foo") { 118 target("my_templ", "foo") {
66 print(default_value) 119 print(default_value)
67 })"); 120 })");
68 ASSERT_FALSE(good_input.has_error()); 121 ASSERT_FALSE(good_input.has_error());
69 Err err; 122 Err err;
70 good_input.parsed()->Execute(setup.scope(), &err); 123 good_input.parsed()->Execute(setup.scope(), &err);
71 ASSERT_FALSE(err.has_error()) << err.message(); 124 ASSERT_FALSE(err.has_error()) << err.message();
72 } 125 }
OLDNEW
« no previous file with comments | « tools/gn/functions.cc ('k') | tools/gn/scope.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698