@@ -39,12 +39,10 @@ class TestDiagnosticConsumer : public DiagnosticConsumer {
3939struct TestDiagnostic : public Diagnostic {
4040 TestDiagnostic (DiagID ID, DiagGroupID GroupID) : Diagnostic(ID, GroupID) {}
4141};
42- } // end anonymous namespace
4342
44- static void diagnosticGroupsTestCase (
45- llvm::function_ref<void (DiagnosticEngine &)> diagnose,
46- llvm::function_ref<void(const DiagnosticInfo &)> callback,
47- unsigned expectedNumCallbackCalls) {
43+ static void testCase (llvm::function_ref<void (DiagnosticEngine &)> diagnose,
44+ llvm::function_ref<void(const DiagnosticInfo &)> callback,
45+ unsigned expectedNumCallbackCalls) {
4846 SourceManager sourceMgr;
4947 DiagnosticEngine diags (sourceMgr);
5048
@@ -63,58 +61,10 @@ static void diagnosticGroupsTestCase(
6361 EXPECT_EQ (count, expectedNumCallbackCalls);
6462}
6563
66- TEST (DiagnosticGroups, PrintDiagnosticGroups) {
67- // Test that we append the correct group in the format string.
68- diagnosticGroupsTestCase (
69- [](DiagnosticEngine &diags) {
70- diags.setPrintDiagnosticNamesMode (PrintDiagnosticNamesMode::Group);
71-
72- TestDiagnostic diagnostic (diag::error_immediate_mode_missing_stdlib.ID ,
73- DiagGroupID::DeprecatedDeclaration);
74- diags.diagnose (SourceLoc (), diagnostic);
75- },
76- [](const DiagnosticInfo &info) {
77- EXPECT_TRUE (info.FormatString .ends_with (" [DeprecatedDeclaration]" ));
78- },
79- /* expectedNumCallbackCalls=*/ 1 );
80-
81- diagnosticGroupsTestCase (
82- [](DiagnosticEngine &diags) {
83- diags.setPrintDiagnosticNamesMode (PrintDiagnosticNamesMode::Group);
84-
85- TestDiagnostic diagnostic (diag::error_immediate_mode_missing_stdlib.ID ,
86- DiagGroupID::no_group);
87- diags.diagnose (SourceLoc (), diagnostic);
88- },
89- [](const DiagnosticInfo &info) {
90- EXPECT_FALSE (info.FormatString .ends_with (" ]" ));
91- },
92- /* expectedNumCallbackCalls=*/ 1 );
93- }
94-
95- TEST (DiagnosticGroups, DiagnosticsWrappersInheritGroups) {
96- // Test that we don't loose the group of a diagnostic when it gets wrapped in
97- // another one.
98- diagnosticGroupsTestCase (
99- [](DiagnosticEngine &diags) {
100- diags.setPrintDiagnosticNamesMode (PrintDiagnosticNamesMode::Group);
101-
102- TestDiagnostic diagnostic (diag::error_immediate_mode_missing_stdlib.ID ,
103- DiagGroupID::DeprecatedDeclaration);
104- diags.diagnose (SourceLoc (), diagnostic)
105- .limitBehaviorUntilSwiftVersion (DiagnosticBehavior::Warning, 99 );
106- },
107- [](const DiagnosticInfo &info) {
108- EXPECT_EQ (info.ID , diag::error_in_a_future_swift_lang_mode.ID );
109- EXPECT_TRUE (info.FormatString .ends_with (" [DeprecatedDeclaration]" ));
110- },
111- /* expectedNumCallbackCalls=*/ 1 );
112- }
113-
11464TEST (DiagnosticGroups, TargetAll) {
11565 // Test that uncategorized diagnostics are escalated when escalating all
11666 // warnings.
117- diagnosticGroupsTestCase (
67+ testCase (
11868 [](DiagnosticEngine &diags) {
11969 const std::vector rules = {
12070 WarningAsErrorRule (WarningAsErrorRule::Action::Enable)};
@@ -139,16 +89,16 @@ TEST(DiagnosticGroups, OverrideBehaviorLimitations) {
13989 DiagGroupID::DeprecatedDeclaration);
14090
14191 // Make sure ID actually is an error by default.
142- diagnosticGroupsTestCase (
92+ testCase (
14393 [&diagnostic](DiagnosticEngine &diags) {
14494 diags.diagnose (SourceLoc (), diagnostic);
14595 },
14696 [](const DiagnosticInfo &info) {
147- EXPECT_TRUE (info.Kind == DiagnosticKind::Error);
97+ EXPECT_EQ (info.Kind , DiagnosticKind::Error);
14898 },
14999 /* expectedNumCallbackCalls=*/ 1 );
150100
151- diagnosticGroupsTestCase (
101+ testCase (
152102 [&diagnostic](DiagnosticEngine &diags) {
153103 const std::vector rules = {WarningAsErrorRule (
154104 WarningAsErrorRule::Action::Enable, " DeprecatedDeclaration" )};
@@ -172,7 +122,7 @@ TEST(DiagnosticGroups, OverrideBehaviorLimitations) {
172122 DiagGroupID::DeprecatedDeclaration);
173123
174124 // Make sure ID actually is a warning by default.
175- diagnosticGroupsTestCase (
125+ testCase (
176126 [&diagnostic](DiagnosticEngine &diags) {
177127 diags.diagnose (SourceLoc (), diagnostic);
178128 },
@@ -181,7 +131,7 @@ TEST(DiagnosticGroups, OverrideBehaviorLimitations) {
181131 },
182132 /* expectedNumCallbackCalls=*/ 1 );
183133
184- diagnosticGroupsTestCase (
134+ testCase (
185135 [&diagnostic](DiagnosticEngine &diags) {
186136 const std::vector rules = {WarningAsErrorRule (
187137 WarningAsErrorRule::Action::Enable, " DeprecatedDeclaration" )};
@@ -196,3 +146,5 @@ TEST(DiagnosticGroups, OverrideBehaviorLimitations) {
196146 /* expectedNumCallbackCalls=*/ 1 );
197147 }
198148}
149+
150+ } // end anonymous namespace
0 commit comments