JS: removed AstConsumer from tests

This commit is contained in:
Alexey Tsvetkov
2015-02-20 12:03:12 +03:00
parent fabcfc7b7f
commit 802a512899
7 changed files with 76 additions and 138 deletions
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.js.test;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.dart.compiler.backend.js.ast.JsNode; import com.google.dart.compiler.backend.js.ast.JsNode;
import com.google.dart.compiler.backend.js.ast.JsProgram;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.StandardFileSystems; import com.intellij.openapi.vfs.StandardFileSystems;
@@ -181,7 +182,7 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
if (!(translationResult instanceof TranslationResult.Success)) return; if (!(translationResult instanceof TranslationResult.Success)) return;
TranslationResult.Success successResult = (TranslationResult.Success) translationResult; TranslationResult.Success successResult = (TranslationResult.Success) translationResult;
getConsumer().consume(successResult.getProgram()); processJsProgram(successResult.getProgram());
OutputFileCollection outputFiles = successResult.getOutputFiles(outputFile, getOutputPrefixFile(), getOutputPostfixFile()); OutputFileCollection outputFiles = successResult.getOutputFiles(outputFile, getOutputPrefixFile(), getOutputPostfixFile());
File outputDir = outputFile.getParentFile(); File outputDir = outputFile.getParentFile();
@@ -205,10 +206,7 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
return false; return false;
} }
protected Consumer<JsNode> getConsumer() { protected void processJsProgram(@NotNull JsProgram program) throws Exception { }
//noinspection unchecked
return Consumer.EMPTY_CONSUMER;
}
protected void runRhinoTests( protected void runRhinoTests(
@NotNull String testName, @NotNull String testName,
@@ -16,16 +16,12 @@
package org.jetbrains.kotlin.js.test; package org.jetbrains.kotlin.js.test;
import com.google.dart.compiler.backend.js.ast.JsNode; import com.google.dart.compiler.backend.js.ast.JsProgram;
import com.intellij.util.Consumer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.js.test.utils.DirectiveTestUtils; import org.jetbrains.kotlin.js.test.utils.DirectiveTestUtils;
import org.jetbrains.kotlin.js.test.utils.JsTestUtils; import org.jetbrains.kotlin.js.test.utils.JsTestUtils;
import org.jetbrains.kotlin.js.test.utils.MemoizeConsumer;
public abstract class SingleFileTranslationWithDirectivesTest extends SingleFileTranslationTest { public abstract class SingleFileTranslationWithDirectivesTest extends SingleFileTranslationTest {
private final MemoizeConsumer<JsNode> nodeConsumer = new MemoizeConsumer<JsNode>();
public SingleFileTranslationWithDirectivesTest(@NotNull String main) { public SingleFileTranslationWithDirectivesTest(@NotNull String main) {
super(main); super(main);
} }
@@ -33,26 +29,12 @@ public abstract class SingleFileTranslationWithDirectivesTest extends SingleFile
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
nodeConsumer.consume(null);
}
protected void checkFooBoxIsOkWithDirectives() throws Exception {
checkFooBoxIsOk();
processDirectives();
}
protected void processDirectives() throws Exception {
String fileName = getInputFilePath(getTestName(true) + ".kt");
String fileText = JsTestUtils.readFile(fileName);
JsNode lastJsNode = nodeConsumer.getLastValue();
assert lastJsNode != null;
DirectiveTestUtils.processDirectives(lastJsNode, fileText);
} }
@Override @Override
protected Consumer<JsNode> getConsumer() { protected void processJsProgram(@NotNull JsProgram program) throws Exception {
return nodeConsumer; String fileName = getInputFilePath(getTestName(true) + ".kt");
String fileText = JsTestUtils.readFile(fileName);
DirectiveTestUtils.processDirectives(program, fileText);
} }
} }
@@ -16,20 +16,17 @@
package org.jetbrains.kotlin.js.test.semantics; package org.jetbrains.kotlin.js.test.semantics;
import com.google.dart.compiler.backend.js.ast.JsNode; import com.google.dart.compiler.backend.js.ast.JsProgram;
import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.js.test.MultipleFilesTranslationTest; import org.jetbrains.kotlin.js.test.MultipleFilesTranslationTest;
import org.jetbrains.kotlin.js.test.utils.DirectiveTestUtils; import org.jetbrains.kotlin.js.test.utils.DirectiveTestUtils;
import org.jetbrains.kotlin.js.test.utils.JsTestUtils; import org.jetbrains.kotlin.js.test.utils.JsTestUtils;
import org.jetbrains.kotlin.js.test.utils.MemoizeConsumer;
import java.util.List; import java.util.List;
import static org.jetbrains.kotlin.js.test.utils.JsTestUtils.getAllFilesInDir; import static org.jetbrains.kotlin.js.test.utils.JsTestUtils.getAllFilesInDir;
public final class InlineMultiFileTest extends MultipleFilesTranslationTest { public final class InlineMultiFileTest extends MultipleFilesTranslationTest {
private final MemoizeConsumer<JsNode> nodeConsumer = new MemoizeConsumer<JsNode>();
public InlineMultiFileTest() { public InlineMultiFileTest() {
super("inlineMultiFile/"); super("inlineMultiFile/");
} }
@@ -37,12 +34,10 @@ public final class InlineMultiFileTest extends MultipleFilesTranslationTest {
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
nodeConsumer.consume(null);
} }
public void testInlineMultiFileSimple() throws Exception { public void testInlineMultiFileSimple() throws Exception {
checkFooBoxIsOk(); checkFooBoxIsOk();
processInlineDirectives();
} }
public void testBuilders() throws Exception { public void testBuilders() throws Exception {
@@ -71,7 +66,6 @@ public final class InlineMultiFileTest extends MultipleFilesTranslationTest {
public void testTrait() throws Exception { public void testTrait() throws Exception {
checkFooBoxIsOk(); checkFooBoxIsOk();
processInlineDirectives();
} }
public void testUse() throws Exception { public void testUse() throws Exception {
@@ -154,23 +148,14 @@ public final class InlineMultiFileTest extends MultipleFilesTranslationTest {
checkFooBoxIsOk(); checkFooBoxIsOk();
} }
private void processInlineDirectives() throws Exception { @Override
protected void processJsProgram(@NotNull JsProgram program) throws Exception {
String dir = getTestName(true); String dir = getTestName(true);
List<String> fileNames = getAllFilesInDir(getInputFilePath(dir)); List<String> fileNames = getAllFilesInDir(getInputFilePath(dir));
for (String fileName : fileNames) { for (String fileName : fileNames) {
String fileText = JsTestUtils.readFile(fileName); String fileText = JsTestUtils.readFile(fileName);
DirectiveTestUtils.processDirectives(program, fileText);
JsNode lastJsNode = nodeConsumer.getLastValue();
assert lastJsNode != null;
DirectiveTestUtils.processDirectives(lastJsNode, fileText);
} }
} }
@Override
protected Consumer<JsNode> getConsumer() {
return nodeConsumer;
}
} }
@@ -25,140 +25,140 @@ public final class InlineTest extends SingleFileTranslationWithDirectivesTest {
} }
public void testInlineSimpleAssignment() throws Exception { public void testInlineSimpleAssignment() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testInlineGenericSimple() throws Exception { public void testInlineGenericSimple() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testInlineIntSimple() throws Exception { public void testInlineIntSimple() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testInlineInc() throws Exception { public void testInlineInc() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testInlineCallNoInline() throws Exception { public void testInlineCallNoInline() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testInlineFunctionInLambda() throws Exception { public void testInlineFunctionInLambda() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testInlineLambdaNoCapture() throws Exception { public void testInlineLambdaNoCapture() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testInlineLambdaWithCapture() throws Exception { public void testInlineLambdaWithCapture() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testInlineChain() throws Exception { public void testInlineChain() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testInlineChainWithFewStatements() throws Exception { public void testInlineChainWithFewStatements() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testCallInlineFunctionOnTopLevelSimple() throws Exception { public void testCallInlineFunctionOnTopLevelSimple() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testCallInlineFunctionOnTopLevel() throws Exception { public void testCallInlineFunctionOnTopLevel() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testInlineIf() throws Exception { public void testInlineIf() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testInlineNoReturn() throws Exception { public void testInlineNoReturn() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testStatementsAfterReturn() throws Exception { public void testStatementsAfterReturn() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testLambdaReassignment() throws Exception { public void testLambdaReassignment() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testLambdaReassignmentWithCapture() throws Exception { public void testLambdaReassignmentWithCapture() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testInlineMethod() throws Exception { public void testInlineMethod() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testThisImplicitlyCaptured() throws Exception { public void testThisImplicitlyCaptured() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testAstCopy() throws Exception { public void testAstCopy() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testNoInlineLambda() throws Exception { public void testNoInlineLambda() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testlambdaInLambda() throws Exception { public void testlambdaInLambda() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testInlineDefaultArgument() throws Exception { public void testInlineDefaultArgument() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testLocalInlineFunction() throws Exception { public void testLocalInlineFunction() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testLocalInlineFunctionDeclaredInLambda() throws Exception { public void testLocalInlineFunctionDeclaredInLambda() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testLocalInlineExtensionFunction() throws Exception { public void testLocalInlineExtensionFunction() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testLocalInlineFunctionNameClash() throws Exception { public void testLocalInlineFunctionNameClash() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testLocalInlineFunctionComplex() throws Exception { public void testLocalInlineFunctionComplex() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testArrayLiteralAliasing() throws Exception { public void testArrayLiteralAliasing() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testLocalInlineFunctionReference() throws Exception { public void testLocalInlineFunctionReference() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testThisLiteralAliasing() throws Exception { public void testThisLiteralAliasing() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testIdentityEquals() throws Exception { public void testIdentityEquals() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testVararg() throws Exception { public void testVararg() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testMutualRecursion() throws Exception { public void testMutualRecursion() throws Exception {
try { try {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} catch (InlineRecursionException e) { } catch (InlineRecursionException e) {
return; return;
} }
@@ -167,74 +167,74 @@ public final class InlineTest extends SingleFileTranslationWithDirectivesTest {
} }
public void testInlineOrder() throws Exception { public void testInlineOrder() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testCallableReference() throws Exception { public void testCallableReference() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testCallableReferenceOfLocalInline() throws Exception { public void testCallableReferenceOfLocalInline() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testAnonymousObjectInlineMethod() throws Exception { public void testAnonymousObjectInlineMethod() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testClassObject() throws Exception { public void testClassObject() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testExtension() throws Exception { public void testExtension() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testExtensionWithManyArguments() throws Exception { public void testExtensionWithManyArguments() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testParams() throws Exception { public void testParams() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testRootConstructor() throws Exception { public void testRootConstructor() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testSeveralClosures() throws Exception { public void testSeveralClosures() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testSeveralUsage() throws Exception { public void testSeveralUsage() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testSimpleDouble() throws Exception { public void testSimpleDouble() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testSimpleInt() throws Exception { public void testSimpleInt() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testSimpleEnum() throws Exception { public void testSimpleEnum() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testSimpleLambda() throws Exception { public void testSimpleLambda() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testSimpleObject() throws Exception { public void testSimpleObject() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testIncrementProperty() throws Exception { public void testIncrementProperty() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testSimpleReturnFunctionWithResultUnused() throws Exception { public void testSimpleReturnFunctionWithResultUnused() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
} }
@@ -85,11 +85,11 @@ public final class JsCodeTest extends SingleFileTranslationWithDirectivesTest {
} }
public void testLabelSiblingClash() throws Exception { public void testLabelSiblingClash() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testLabelNestedClash() throws Exception { public void testLabelNestedClash() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testTryCatchFinally() throws Exception { public void testTryCatchFinally() throws Exception {
@@ -24,38 +24,38 @@ public class LabelTest extends SingleFileTranslationWithDirectivesTest {
} }
public void testSimpleLabel() throws Exception { public void testSimpleLabel() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testSiblingLabels() throws Exception { public void testSiblingLabels() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testNestedLabels() throws Exception { public void testNestedLabels() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testSimpleLabelInlined() throws Exception { public void testSimpleLabelInlined() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testSiblingLabelsInlined() throws Exception { public void testSiblingLabelsInlined() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testSiblingLabelsInlinedClashing() throws Exception { public void testSiblingLabelsInlinedClashing() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testNestedLabelsInlinedClashing() throws Exception { public void testNestedLabelsInlinedClashing() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testLabelWithVariableClashing() throws Exception { public void testLabelWithVariableClashing() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
public void testNestedLabelsInlinedClashingAtFunctionsWithClosure() throws Exception { public void testNestedLabelsInlinedClashingAtFunctionsWithClosure() throws Exception {
checkFooBoxIsOkWithDirectives(); checkFooBoxIsOk();
} }
} }
@@ -1,27 +0,0 @@
/*
* Copyright 2010-2015 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.intellij.util.Consumer
class MemoizeConsumer<T : Any> : Consumer<T> {
var lastValue: T? = null
override fun consume(value: T?) {
lastValue = value
}
}