1313#include " swift/AST/DiagnosticEngine.h"
1414#include " swift/AST/DiagnosticGroups.h"
1515#include " swift/AST/DiagnosticsFrontend.h"
16+ #include " swift/AST/DiagnosticsModuleDiffer.h"
17+ #include " swift/AST/DiagnosticsSema.h"
1618#include " swift/Basic/SourceManager.h"
1719#include " gtest/gtest.h"
1820
@@ -142,7 +144,7 @@ TEST(DiagnosticInfo, PrintDiagnosticNamesMode_Group) {
142144 },
143145 [](DiagnosticEngine &, const DiagnosticInfo &info) {
144146 EXPECT_FALSE (info.FormatString .ends_with (" [DeprecatedDeclaration]" ));
145- EXPECT_TRUE (info.Category == " DeprecatedDeclaration" );
147+ EXPECT_EQ (info.Category , " DeprecatedDeclaration" );
146148 },
147149 /* expectedNumCallbackCalls=*/ 1 );
148150}
@@ -162,9 +164,64 @@ TEST(DiagnosticInfo, PrintDiagnosticNamesMode_Group_WrappedDiag) {
162164 [](DiagnosticEngine &, const DiagnosticInfo &info) {
163165 EXPECT_EQ (info.ID , diag::error_in_a_future_swift_lang_mode.ID );
164166 EXPECT_FALSE (info.FormatString .ends_with (" [DeprecatedDeclaration]" ));
165- EXPECT_TRUE (info.Category == " DeprecatedDeclaration" );
167+ EXPECT_EQ (info.Category , " DeprecatedDeclaration" );
166168 },
167169 /* expectedNumCallbackCalls=*/ 1 );
168170}
169171
172+ // Test that the category is appropriately set in these cases, and that the
173+ // category of a wrapped diagnostic is favored.
174+ TEST (DiagnosticInfo, CategoryDeprecation) {
175+ testCase (
176+ [](DiagnosticEngine &diags) {
177+ diags.setLanguageVersion (version::Version ({5 }));
178+
179+ const auto diag = diag::iuo_deprecated_here;
180+ EXPECT_TRUE (diags.isDeprecationDiagnostic (diag.ID ));
181+
182+ diags.diagnose (SourceLoc (), diag);
183+ diags.diagnose (SourceLoc (), diag).warnUntilSwiftVersion (6 );
184+ diags.diagnose (SourceLoc (), diag).warnUntilSwiftVersion (99 );
185+ },
186+ [](DiagnosticEngine &, const DiagnosticInfo &info) {
187+ EXPECT_EQ (info.Category , " deprecation" );
188+ },
189+ /* expectedNumCallbackCalls=*/ 3 );
190+ }
191+ TEST (DiagnosticInfo, CategoryNoUsage) {
192+ testCase (
193+ [](DiagnosticEngine &diags) {
194+ diags.setLanguageVersion (version::Version ({5 }));
195+
196+ const auto diag = diag::expression_unused_function;
197+ EXPECT_TRUE (diags.isNoUsageDiagnostic (diag.ID ));
198+
199+ diags.diagnose (SourceLoc (), diag);
200+ diags.diagnose (SourceLoc (), diag).warnUntilSwiftVersion (6 );
201+ diags.diagnose (SourceLoc (), diag).warnUntilSwiftVersion (99 );
202+ },
203+ [](DiagnosticEngine &, const DiagnosticInfo &info) {
204+ EXPECT_EQ (info.Category , " no-usage" );
205+ },
206+ /* expectedNumCallbackCalls=*/ 3 );
207+ }
208+ TEST (DiagnosticInfo, CategoryAPIDigesterBreakage) {
209+ testCase (
210+ [](DiagnosticEngine &diags) {
211+ diags.setLanguageVersion (version::Version ({5 }));
212+
213+ const auto diag = diag::enum_case_added;
214+ EXPECT_TRUE (diags.isAPIDigesterBreakageDiagnostic (diag.ID ));
215+
216+ diags.diagnose (SourceLoc (), diag, StringRef ());
217+ diags.diagnose (SourceLoc (), diag, StringRef ()).warnUntilSwiftVersion (6 );
218+ diags.diagnose (SourceLoc (), diag, StringRef ())
219+ .warnUntilSwiftVersion (99 );
220+ },
221+ [](DiagnosticEngine &, const DiagnosticInfo &info) {
222+ EXPECT_EQ (info.Category , " api-digester-breaking-change" );
223+ },
224+ /* expectedNumCallbackCalls=*/ 3 );
225+ }
226+
170227} // end anonymous namespace
0 commit comments