JS: in tests add verifier that checks whether no expression statements with only null expression exist

This commit is contained in:
Alexey Andreev
2016-07-18 11:52:46 +03:00
parent a27f5c8fee
commit df05b20bc6
2 changed files with 39 additions and 0 deletions
@@ -49,6 +49,7 @@ import org.jetbrains.kotlin.js.facade.TranslationResult;
import org.jetbrains.kotlin.js.test.rhino.RhinoResultChecker;
import org.jetbrains.kotlin.js.test.utils.DirectiveTestUtils;
import org.jetbrains.kotlin.js.test.utils.JsTestUtils;
import org.jetbrains.kotlin.js.test.utils.JsVerificationKt;
import org.jetbrains.kotlin.js.translate.context.Namer;
import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.psi.KtPsiFactory;
@@ -249,6 +250,7 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
String text = file.getText();
DirectiveTestUtils.processDirectives(program, text);
}
JsVerificationKt.verifyAst(program);
}
protected void runRhinoTests(
@@ -0,0 +1,37 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.js.test.utils
import com.google.dart.compiler.backend.js.ast.JsExpressionStatement
import com.google.dart.compiler.backend.js.ast.JsNullLiteral
import com.google.dart.compiler.backend.js.ast.JsProgram
import com.google.dart.compiler.backend.js.ast.RecursiveJsVisitor
import org.junit.Assert
fun JsProgram.verifyAst() {
accept(object : RecursiveJsVisitor() {
override fun visitExpressionStatement(x: JsExpressionStatement) {
val expression = x.expression
if (expression is JsNullLiteral) {
Assert.fail("Expression statement contains `null` literal")
}
else {
super.visitExpressionStatement(x)
}
}
})
}