为什么这个警告 testCase return 出错了?

Why does this warning testCase return an error?

我编写了以下验证规则:

 @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)
    }
 }

然后我为它编写了一个测试用例,如下所示:

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

但是当我 运行 JUnit 它报告错误:

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

我不明白这一点,因为它实际上期待的正是该错误消息(据我所知)

有人知道为什么它不起作用吗?

你好 Krzmbrzl

看起来您创建警告和测试验证的方式不匹配

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

在声明中创建警告

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

测试 DecContent