@@ -233,7 +233,7 @@ struct NoteSpec {
233
233
234
234
/// An abstract data structure to describe how a diagnostic produced by the parser should look like.
235
235
struct DiagnosticSpec {
236
- /// The name of a maker (of the form `1️⃣`) in the source code that marks the location where the diagnostis should be produced.
236
+ /// The name of a marker (of the form `1️⃣`) in the source code that marks the location where the diagnostic should be produced.
237
237
let locationMarker : String
238
238
/// If not `nil`, assert that the diagnostic has the given ID.
239
239
let id : MessageID ?
@@ -549,8 +549,11 @@ extension ParserTestCase {
549
549
assertStringsEqualWithDiff (
550
550
" \( mutatedTree) " ,
551
551
mutatedSource,
552
- " A mutation of the original test case failed to round-trip " ,
552
+ " A mutation of the original test case failed to round-trip. " ,
553
553
additionalInfo: """
554
+ To debug the failure, add a new `assertParse` test with the following source as input:
555
+ \( mutatedSource)
556
+
554
557
Parsed syntax tree of mutation:
555
558
\( mutatedTree. debugDescription)
556
559
""" ,
@@ -560,23 +563,42 @@ extension ParserTestCase {
560
563
}
561
564
}
562
565
563
- /// Removes any test markers from `markedSource` (1) and parses the result
564
- /// using `parse`. By default it only checks if the parsed syntax tree is
565
- /// printable back to the origin source, ie. it round trips.
566
+ /// Verifies that parsing of `markedSource` produces expected results using a
567
+ /// combination of various testing techniques:
568
+ ///
569
+ /// 1. Asserts that parsing of `markedSource` round-trips, ie. that the printed
570
+ /// parsed tree is the same as the input.
571
+ /// 2. Checks that parsing produces the expected list of diagnostics. If no
572
+ /// diagnostics are passed, asserts that the input parses without any errors.
573
+ /// 3. Checks that applying all Fix-Its of the source code results in the
574
+ /// expected fixed source, effectively testing the Fix-Its.
575
+ /// 4. If a substructure is passed, asserts that the parsed tree contains a
576
+ /// subtree of that structure.
577
+ /// 5. Mutates the test input by flipping each token's presence (ie. for every
578
+ /// token, either remove it from the input if it is present in the parsed
579
+ /// tree or synthesize it if it was missing) and verifies that this
580
+ /// mutated input round-trips. This test is disabled if the
581
+ /// `SKIP_LONG_TESTS` environment variable is set.
582
+ /// 6. If swift-syntax is compiled with the
583
+ /// `SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION` environment variable
584
+ /// set, mutates the input based on tokens the parse is trying to parse.
585
+ /// See the *Test Case Mutation* section in CONTRIBUTING.md.
566
586
///
567
- /// (1) `markedSource` is source that can include markers of the form `1️⃣`,
568
- /// to be used as locations in the following parameters when they exist.
569
587
///
570
588
/// - Parameters:
571
- /// - substructure: Asserts the parsed syntax tree contains this structure.
589
+ /// - markedSource: source that can include markers of the form `1️⃣`,
590
+ /// to be used as locations in the following parameters.
591
+ /// - parse: The function with which the source code should be parsed.
592
+ /// Defaults to parsing as a source file.
593
+ /// - expectedSubstructure: Asserts the parsed syntax tree contains this structure.
572
594
/// - substructureAfterMarker: Changes the position to start the structure
573
595
/// assertion from, ie. allows matching a particular substructure rather
574
596
/// than the whole source.
575
- /// - diagnostics : Asserts the given diagnostics were output, by default it
597
+ /// - expectedDiagnostics : Asserts the given diagnostics were output, by default it
576
598
/// asserts the parse was successful (ie. it has no diagnostics). Note
577
599
/// that `DiagnosticsSpec` uses the location marked by `1️⃣` by default.
578
600
/// - applyFixIts: Applies only the fix-its with these messages.
579
- /// - fixedSource : Asserts that the source after applying fix-its matches
601
+ /// - expectedFixedSource : Asserts that the source after applying fix-its matches
580
602
/// this string.
581
603
/// - experimentalFeatures: A list of experimental features to enable, or
582
604
/// `nil` to enable the default set of features provided by the test case.
0 commit comments