OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "tools/gn/args.h" | 5 #include "tools/gn/args.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "tools/gn/scheduler.h" | 8 #include "tools/gn/scheduler.h" |
9 #include "tools/gn/test_with_scope.h" | 9 #include "tools/gn/test_with_scope.h" |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 EXPECT_TRUE(args.VerifyAllOverridesUsed(&err)); | 32 EXPECT_TRUE(args.VerifyAllOverridesUsed(&err)); |
33 | 33 |
34 // Override "a", & "b", shouldn't see any errors as both were defined. | 34 // Override "a", & "b", shouldn't see any errors as both were defined. |
35 args.AddArgOverride("b", Value(nullptr, true)); | 35 args.AddArgOverride("b", Value(nullptr, true)); |
36 EXPECT_TRUE(args.VerifyAllOverridesUsed(&err)); | 36 EXPECT_TRUE(args.VerifyAllOverridesUsed(&err)); |
37 | 37 |
38 // Override "a", "b" and "c", should fail as "c" was not defined. | 38 // Override "a", "b" and "c", should fail as "c" was not defined. |
39 args.AddArgOverride("c", Value(nullptr, true)); | 39 args.AddArgOverride("c", Value(nullptr, true)); |
40 EXPECT_FALSE(args.VerifyAllOverridesUsed(&err)); | 40 EXPECT_FALSE(args.VerifyAllOverridesUsed(&err)); |
41 } | 41 } |
| 42 |
| 43 // Ensure that arg overrides get only set after the they were declared. |
| 44 TEST(ArgsTest, VerifyOverrideScope) { |
| 45 TestWithScope setup; |
| 46 Args args; |
| 47 Err err; |
| 48 |
| 49 args.AddArgOverride("a", Value(nullptr, "avalue")); |
| 50 args.AddArgOverride("current_os", Value(nullptr, "theiros")); |
| 51 |
| 52 Scope::KeyValueMap toolchain_overrides; |
| 53 toolchain_overrides["b"] = Value(nullptr, "bvalue"); |
| 54 toolchain_overrides["current_os"] = Value(nullptr, "myos"); |
| 55 args.SetupRootScope(setup.scope(), toolchain_overrides); |
| 56 |
| 57 // Overrides of arguments not yet declared aren't applied yet. |
| 58 EXPECT_EQ(nullptr, setup.scope()->GetValue("a")); |
| 59 EXPECT_EQ(nullptr, setup.scope()->GetValue("b")); |
| 60 |
| 61 // |current_os| is a system var. and already declared. |
| 62 // Thus it should have our override value. |
| 63 ASSERT_NE(nullptr, setup.scope()->GetValue("current_os")); |
| 64 EXPECT_EQ(Value(nullptr, "myos"), *setup.scope()->GetValue("current_os")); |
| 65 |
| 66 Scope::KeyValueMap key_value_map1; |
| 67 key_value_map1["a"] = Value(nullptr, "avalue2"); |
| 68 key_value_map1["b"] = Value(nullptr, "bvalue2"); |
| 69 key_value_map1["c"] = Value(nullptr, "cvalue2"); |
| 70 EXPECT_TRUE(args.DeclareArgs(key_value_map1, setup.scope(), &err)); |
| 71 |
| 72 ASSERT_NE(nullptr, setup.scope()->GetValue("a")); |
| 73 EXPECT_EQ(Value(nullptr, "avalue"), *setup.scope()->GetValue("a")); |
| 74 |
| 75 ASSERT_NE(nullptr, setup.scope()->GetValue("b")); |
| 76 EXPECT_EQ(Value(nullptr, "bvalue"), *setup.scope()->GetValue("b")); |
| 77 |
| 78 // This wasn't overwritten, so it should have the default value. |
| 79 ASSERT_NE(nullptr, setup.scope()->GetValue("c")); |
| 80 EXPECT_EQ(Value(nullptr, "cvalue2"), *setup.scope()->GetValue("c")); |
| 81 } |
OLD | NEW |