13
13
#include " swift/AST/DiagnosticEngine.h"
14
14
#include " swift/AST/DiagnosticGroups.h"
15
15
#include " swift/AST/DiagnosticsFrontend.h"
16
+ #include " swift/AST/DiagnosticsModuleDiffer.h"
17
+ #include " swift/AST/DiagnosticsSema.h"
16
18
#include " swift/Basic/SourceManager.h"
17
19
#include " gtest/gtest.h"
18
20
@@ -142,7 +144,7 @@ TEST(DiagnosticInfo, PrintDiagnosticNamesMode_Group) {
142
144
},
143
145
[](DiagnosticEngine &, const DiagnosticInfo &info) {
144
146
EXPECT_FALSE (info.FormatString .ends_with (" [DeprecatedDeclaration]" ));
145
- EXPECT_TRUE (info.Category == " DeprecatedDeclaration" );
147
+ EXPECT_EQ (info.Category , " DeprecatedDeclaration" );
146
148
},
147
149
/* expectedNumCallbackCalls=*/ 1 );
148
150
}
@@ -162,9 +164,64 @@ TEST(DiagnosticInfo, PrintDiagnosticNamesMode_Group_WrappedDiag) {
162
164
[](DiagnosticEngine &, const DiagnosticInfo &info) {
163
165
EXPECT_EQ (info.ID , diag::error_in_a_future_swift_lang_mode.ID );
164
166
EXPECT_FALSE (info.FormatString .ends_with (" [DeprecatedDeclaration]" ));
165
- EXPECT_TRUE (info.Category == " DeprecatedDeclaration" );
167
+ EXPECT_EQ (info.Category , " DeprecatedDeclaration" );
166
168
},
167
169
/* expectedNumCallbackCalls=*/ 1 );
168
170
}
169
171
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
+
170
227
} // end anonymous namespace
0 commit comments