Skip to content
Permalink
Browse files

SpdxExpression: Set only our own error listener also for the parser

To suppress bogus console output like

    line 1:8 no viable alternative at input 'licensea'

when running e.g. PackageCurationTest. This also results in more telling
error messages.

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@here.com>
  • Loading branch information...
sschuberth committed May 2, 2019
1 parent 5108c69 commit 6fc8af6cf43ab9fb4a6c7d8d2fcb3b7f6cf4e8a7
@@ -79,7 +79,10 @@ sealed class SpdxExpression {
}

val tokenStream = CommonTokenStream(lexer)
val parser = SpdxExpressionParser(tokenStream)
val parser = SpdxExpressionParser(tokenStream).apply {
removeErrorListeners()
addErrorListener(SpdxErrorListener())
}

return SpdxExpressionDefaultVisitor(strictness).visit(parser.licenseExpression())
}
@@ -181,15 +181,15 @@ class SpdxExpressionParserTest : WordSpec() {
SpdxExpression.parse("license WITH exception+")
}

exception.message shouldBe "SpdxExpression has invalid amount of children: '3'"
exception.message shouldBe "extraneous input '+' expecting <EOF>"
}

"fail if a compound expression is used before WITH" {
val exception = shouldThrow<SpdxException> {
SpdxExpression.parse("(license1 AND license2) WITH exception")
}

exception.message shouldBe "SpdxExpression has invalid amount of children: '3'"
exception.message shouldBe "mismatched input 'WITH' expecting {AND, OR, ')', '+'}"
}

"fail on an invalid symbol" {
@@ -205,7 +205,7 @@ class SpdxExpressionParserTest : WordSpec() {
SpdxExpression.parse("((")
}

exception.message shouldBe "Illegal operator '(' in expression '((<missing ')'>'."
exception.message shouldBe "mismatched input '<EOF>' expecting {'(', LICENSEREFERENCE, IDSTRING}"
}
}
}

0 comments on commit 6fc8af6

Please sign in to comment.
You can’t perform that action at this time.