def runParseExpectErrors()

in daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala [1133:1208]


  def runParseExpectErrors(
    dataToParse: InputStream,
    lengthLimitInBits: Long,
    optErrors: Option[Seq[ExpectedErrors]],
    optWarnings: Option[Seq[ExpectedWarnings]],
    optValidationErrors: Option[Seq[ExpectedValidationErrors]],
    validationMode: ValidationMode.Type,
    implString: Option[String],
    compileWarnings: Seq[Diagnostic]
  ): Unit = {

    try {
      processor = processor
        .withExternalDFDLVariables(externalVarBindings)
        .withValidationMode(validationMode)
    } catch {
      case e: Exception => throw TDMLException(e, implString)
    }

    val (parseResult, diagnostics, isError) = {
      val actual =
        try {
          processor.parse(dataToParse, lengthLimitInBits)
        } catch {
          case t: Throwable =>
            toss(t, implString)
        }

      // we should never need blobs if we're expecting an error even if we
      // don't get errors. So clean them up immediately
      actual.cleanUp()

      val isErr: Boolean =
        if (actual.isProcessingError) true
        else {
          //
          // didn't get an error.
          // If we're not at the end of data, synthesize an error for left-over-data
          //
          val loc: DataLocation = actual.currentLocation

          if (loc.bitPos1b >= 0 && loc.bitPos1b <= lengthLimitInBits) {
            val leftOverMsg =
              "Left over data. Consumed %s bit(s) with %s bit(s) remaining.".format(
                loc.bitPos1b - 1,
                lengthLimitInBits - (loc.bitPos1b - 1)
              )
            actual.addDiagnostic(new TDMLDiagnostic(leftOverMsg, implString))
            true
          } else {
            false
          }
        }

      val diagnostics = compileWarnings ++ actual.getDiagnostics
      (actual, diagnostics, isErr)
    }
    if (!isError) {
      toss(
        TDMLException(
          "Expected error. Didn't get one. Actual result was\n" +
            parseResult.getResult.toString,
          implString
        ),
        implString
      )
    }

    checkDiagnosticMessages(
      diagnostics,
      optErrors,
      optWarnings,
      optValidationErrors,
      implString
    )
  }