in daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala [1865:1947]
def verifyDiagnosticsFound(
actualDiagsFiltered: Seq[Diagnostic],
expectedDiags: Option[Seq[ErrorWarningBase]],
ignoreUnexpectedDiags: Boolean,
diagnosticType: DiagnosticType,
implString: Option[String]
): Unit = {
val expectedDiagMsgs = expectedDiags
.map { d =>
d.flatMap(_.messages)
}
.getOrElse(Nil)
val actualDiagsFilteredMessages = actualDiagsFiltered.map(_.toString())
// throw exception if we have no actualDiags, but have expected diagnostics
if (expectedDiags.isDefined && actualDiagsFiltered.isEmpty) {
throw TDMLException(
""""Diagnostic message(s) were expected but not found."""" +
"\n" +
"""Expected: """ + expectedDiagMsgs.mkString("\n") +
(if (actualDiagsFiltered.isEmpty)
s"\n No ${diagnosticType} diagnostic messages were issued."
else
"\n The actual diagnostics messages were: " + actualDiagsFilteredMessages.mkString(
"\n"
)),
implString
)
}
val hasUnexpectedDiags = expectedDiags.isEmpty && actualDiagsFiltered.nonEmpty
if (hasUnexpectedDiags && !ignoreUnexpectedDiags) {
val flagMessage = diagnosticType match {
case DiagnosticType.ValidationError => "ignoreUnexpectedValidationErrors = false and "
case DiagnosticType.Warning => "ignoreUnexpectedWarnings = false and "
case DiagnosticType.Error => ""
}
throw TDMLException(
s"${flagMessage}test does not expect ${diagnosticType} diagnostics, but created the following: " +
s"${actualDiagsFilteredMessages.mkString("\n")}",
implString
)
}
expectedDiags.map { diags =>
diags.map { diag =>
val matchAttr = diag.matchAttrib
val diagsFound = diag.messages.map { d =>
// make case insensitive
val wasFound =
actualDiagsFilteredMessages.exists(ad => ad.toLowerCase.contains(d.toLowerCase))
(d, wasFound)
}
matchAttr match {
case "all" => {
if (!diagsFound.forall(_._2)) {
throw TDMLException(
s"""Did not find diagnostic ${diag.diagnosticType} message """" +
diagsFound.find(_._2 == false).get._1 +
"""" in any of the actual diagnostic messages: """ + "\n" +
actualDiagsFilteredMessages.mkString("\n"),
implString
)
}
}
case "none" => {
if (diagsFound.exists(_._2)) {
throw TDMLException(
s"""Found one of diagnostic ${diag.diagnosticType} message """" +
diagsFound.find(_._2 == true).get._1 +
"""" in one of the actual diagnostic messages: """ + "\n" +
actualDiagsFilteredMessages.mkString("\n"),
implString
)
}
}
case _ => throw TDMLException("Only match=all or match=none supported", implString)
}
}
}
}