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 "tools/gn/target.h" | 5 #include "tools/gn/target.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "tools/gn/build_settings.h" | 10 #include "tools/gn/build_settings.h" |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
661 "\n" | 661 "\n" |
662 "From //foo:bar\n" | 662 "From //foo:bar\n" |
663 " header: pch.h\n" | 663 " header: pch.h\n" |
664 " source: //pcs.cc\n" | 664 " source: //pcs.cc\n" |
665 "\n" | 665 "\n" |
666 "From //foo:c2\n" | 666 "From //foo:c2\n" |
667 " header: pch2.h\n" | 667 " header: pch2.h\n" |
668 " source: //pcs2.cc", | 668 " source: //pcs2.cc", |
669 err.help_text()); | 669 err.help_text()); |
670 } | 670 } |
671 | |
672 TEST(Target, AssertNoDeps) { | |
673 TestWithScope setup; | |
674 Err err; | |
675 | |
676 // A target. | |
677 TestTarget a(setup, "//a", Target::SHARED_LIBRARY); | |
678 ASSERT_TRUE(a.OnResolved(&err)); | |
679 | |
680 // B depends on A and has an assert_no_deps for a random dir. | |
681 TestTarget b(setup, "//b", Target::SHARED_LIBRARY); | |
682 b.private_deps().push_back(LabelTargetPair(&a)); | |
683 b.assert_no_deps().push_back(LabelPattern( | |
684 LabelPattern::RECURSIVE_DIRECTORY, SourceDir("//disallowed/"), | |
685 std::string(), Label())); | |
686 ASSERT_TRUE(b.OnResolved(&err)); | |
687 | |
688 LabelPattern disallow_a(LabelPattern::RECURSIVE_DIRECTORY, SourceDir("//a/"), | |
689 std::string(), Label()); | |
690 | |
691 // C depends in B and disallows depending on A. This should fail. | |
Dirk Pranke
2016/01/26 01:17:40
nit: "depends on"
| |
692 TestTarget c(setup, "//c", Target::EXECUTABLE); | |
693 c.private_deps().push_back(LabelTargetPair(&b)); | |
694 c.assert_no_deps().push_back(disallow_a); | |
695 ASSERT_FALSE(c.OnResolved(&err)); | |
696 | |
697 // Validate the error message has the proper path. | |
698 EXPECT_EQ( | |
699 "//c:c has an assert_no_deps entry:\n" | |
700 " //a/*\n" | |
701 "which fails for the dependency path:\n" | |
702 " //c:c ->\n" | |
703 " //b:b ->\n" | |
704 " //a:a", | |
705 err.help_text()); | |
706 err = Err(); | |
707 | |
708 // Add an intermediate executable with: exe -> b -> a | |
709 TestTarget exe(setup, "//exe", Target::EXECUTABLE); | |
710 exe.private_deps().push_back(LabelTargetPair(&b)); | |
711 ASSERT_TRUE(exe.OnResolved(&err)); | |
712 | |
713 // D depends on the executable and disallows depending on A. Since there is | |
714 // an intermediate executable, this should be OK. | |
715 TestTarget d(setup, "//d", Target::EXECUTABLE); | |
716 d.private_deps().push_back(LabelTargetPair(&exe)); | |
717 d.assert_no_deps().push_back(disallow_a); | |
718 ASSERT_TRUE(d.OnResolved(&err)); | |
719 | |
720 // A2 disallows depending on anything in its own directory, but the | |
721 // assertions should not match the target itself so this should be OK. | |
722 TestTarget a2(setup, "//a:a2", Target::EXECUTABLE); | |
723 a2.assert_no_deps().push_back(disallow_a); | |
724 ASSERT_TRUE(a2.OnResolved(&err)); | |
725 } | |
OLD | NEW |