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