Raven
Raven

Reputation: 3526

Why does this warning testCase return an error?

I have written the following validation Rule:

 @Check
 def checkDeclarationIsNotReferenceToItself(Declaration dec) {
    if(dec.decCon.singleContent.reference == null &&    !dec.decCon.nextCon.isEmpty) {
        //only proceed if it is a reference
        return
    }

    var name = dec.name

    if(dec.decCon.singleContent.reference.name == name) {
        //only if the declaration is a self-reference without further actions
        var warningMsg = "The declaration '" + name + "' is a reference to itself"
        warning(warningMsg, 
            SQFPackage.eINSTANCE.declaration_DecCon,
            SELFREFERENCE)
    }
 }

And then I have written an test case for it looking as following:

@Test
def void checkDeclarationIsNotReferenceToItselfTest() {
    '''
        test = 3;
        test = test;
    '''.parse.assertWarning(SQFPackage.eINSTANCE.decContent,
        SQFValidator.SELFREFERENCE,
        "The declaration 'test' is a reference to itself")
}

But when I run JUnit it reports an error:

Expected WARNING 'raven.sqf.SelfReference' on DecContent at [-1:-1] but got
WARNING (raven.sqf.SelfReference) 'The declaration 'test' is a reference     to itself' on Declaration, offset 18, length 4

I don't understand this because it actually expects exactly that error message (As far as I see it)

Anyone has an idea why it doesn't work?

Greetings Krzmbrzl

Upvotes: 0

Views: 29

Answers (1)

Christian Dietrich
Christian Dietrich

Reputation: 11868

looks like the way you create the warning and test the validation do not match together

warning(warningMsg, 
        SQFPackage.eINSTANCE.declaration_DecCon,
        SELFREFERENCE)

creates the warning on a Declaration

.assertWarning(SQFPackage.eINSTANCE.decContent,
    SQFValidator.SELFREFERENCE,
    "The declaration 'test' is a reference to itself")

tests for a DecContent

Upvotes: 1

Related Questions