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

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

Issue 1621053002: Add an assert_no_deps variable to GN. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment fix Created 4 years, 10 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/target_generator.cc ('k') | tools/gn/value_extractors.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 "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
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 on B and disallows depending on A. This should fail.
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 }
OLDNEW
« no previous file with comments | « tools/gn/target_generator.cc ('k') | tools/gn/value_extractors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698