From df05b20bc697790080b225c17f7c02832ee7d7ac Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 18 Jul 2016 11:52:46 +0300 Subject: [PATCH] JS: in tests add verifier that checks whether no expression statements with only `null` expression exist --- .../jetbrains/kotlin/js/test/BasicTest.java | 2 + .../kotlin/js/test/utils/jsVerification.kt | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 js/js.tests/test/org/jetbrains/kotlin/js/test/utils/jsVerification.kt diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicTest.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicTest.java index d2ff8a0f078..9df99ee3d2d 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicTest.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicTest.java @@ -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( diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/utils/jsVerification.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/utils/jsVerification.kt new file mode 100644 index 00000000000..e19439c04c7 --- /dev/null +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/utils/jsVerification.kt @@ -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) + } + } + }) +} \ No newline at end of file