OLD | NEW |
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/build_settings.h" | 6 #include "tools/gn/build_settings.h" |
7 #include "tools/gn/config.h" | 7 #include "tools/gn/config.h" |
8 #include "tools/gn/settings.h" | 8 #include "tools/gn/settings.h" |
9 #include "tools/gn/target.h" | 9 #include "tools/gn/target.h" |
10 #include "tools/gn/test_with_scope.h" | 10 #include "tools/gn/test_with_scope.h" |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 // it as user-set so we check visibility. This check should fail. | 366 // it as user-set so we check visibility. This check should fail. |
367 Target a(setup.settings(), Label(SourceDir("//app/"), "a")); | 367 Target a(setup.settings(), Label(SourceDir("//app/"), "a")); |
368 a.set_output_type(Target::EXECUTABLE); | 368 a.set_output_type(Target::EXECUTABLE); |
369 a.deps().push_back(LabelTargetPair(&b)); | 369 a.deps().push_back(LabelTargetPair(&b)); |
370 IdentifierNode origin; // Dummy origin. | 370 IdentifierNode origin; // Dummy origin. |
371 a.deps()[0].origin = &origin; | 371 a.deps()[0].origin = &origin; |
372 a.SetToolchain(setup.toolchain()); | 372 a.SetToolchain(setup.toolchain()); |
373 ASSERT_FALSE(a.OnResolved(&err)); | 373 ASSERT_FALSE(a.OnResolved(&err)); |
374 } | 374 } |
375 | 375 |
| 376 // Test visibility with a single datadep. |
| 377 TEST(Target, VisibilityDatadeps) { |
| 378 TestWithScope setup; |
| 379 Err err; |
| 380 |
| 381 Target b(setup.settings(), Label(SourceDir("//public/"), "b")); |
| 382 b.set_output_type(Target::STATIC_LIBRARY); |
| 383 b.SetToolchain(setup.toolchain()); |
| 384 b.visibility().SetPublic(); |
| 385 ASSERT_TRUE(b.OnResolved(&err)); |
| 386 |
| 387 // Make a target depending on "b". The dependency must have an origin to mark |
| 388 // it as user-set so we check visibility. This check should fail. |
| 389 Target a(setup.settings(), Label(SourceDir("//app/"), "a")); |
| 390 a.set_output_type(Target::EXECUTABLE); |
| 391 a.datadeps().push_back(LabelTargetPair(&b)); |
| 392 IdentifierNode origin; // Dummy origin. |
| 393 a.datadeps()[0].origin = &origin; |
| 394 a.SetToolchain(setup.toolchain()); |
| 395 ASSERT_TRUE(a.OnResolved(&err)) << err.help_text(); |
| 396 } |
| 397 |
376 // Tests that A -> Group -> B where the group is visible from A but B isn't, | 398 // Tests that A -> Group -> B where the group is visible from A but B isn't, |
377 // passes visibility even though the group's deps get expanded into A. | 399 // passes visibility even though the group's deps get expanded into A. |
378 TEST(Target, VisibilityGroup) { | 400 TEST(Target, VisibilityGroup) { |
379 TestWithScope setup; | 401 TestWithScope setup; |
380 Err err; | 402 Err err; |
381 | 403 |
382 IdentifierNode origin; // Dummy origin. | 404 IdentifierNode origin; // Dummy origin. |
383 | 405 |
384 // B has private visibility. This lets the group see it since the group is in | 406 // B has private visibility. This lets the group see it since the group is in |
385 // the same directory. | 407 // the same directory. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 ASSERT_TRUE(test.OnResolved(&err)); | 452 ASSERT_TRUE(test.OnResolved(&err)); |
431 | 453 |
432 // "product" is a non-test depending on testlib. This should fail. | 454 // "product" is a non-test depending on testlib. This should fail. |
433 Target product(setup.settings(), Label(SourceDir("//app/"), "product")); | 455 Target product(setup.settings(), Label(SourceDir("//app/"), "product")); |
434 product.set_testonly(false); | 456 product.set_testonly(false); |
435 product.set_output_type(Target::EXECUTABLE); | 457 product.set_output_type(Target::EXECUTABLE); |
436 product.deps().push_back(LabelTargetPair(&testlib)); | 458 product.deps().push_back(LabelTargetPair(&testlib)); |
437 product.SetToolchain(setup.toolchain()); | 459 product.SetToolchain(setup.toolchain()); |
438 ASSERT_FALSE(product.OnResolved(&err)); | 460 ASSERT_FALSE(product.OnResolved(&err)); |
439 } | 461 } |
OLD | NEW |