Trying to run stdlib unit tests as part or js.tests: step 3 - use TestConfigFactory to provide information about JsTester
This commit is contained in:
@@ -22,6 +22,8 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.k2js.config.EcmaVersion;
|
import org.jetbrains.k2js.config.EcmaVersion;
|
||||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
import org.jetbrains.k2js.facade.MainCallParameters;
|
||||||
|
import org.jetbrains.k2js.test.config.TestConfig;
|
||||||
|
import org.jetbrains.k2js.test.config.TestConfigFactory;
|
||||||
import org.jetbrains.k2js.test.rhino.RhinoResultChecker;
|
import org.jetbrains.k2js.test.rhino.RhinoResultChecker;
|
||||||
import org.jetbrains.k2js.test.utils.TranslationUtils;
|
import org.jetbrains.k2js.test.utils.TranslationUtils;
|
||||||
|
|
||||||
@@ -99,12 +101,25 @@ public abstract class BasicTest extends TestWithEnvironment {
|
|||||||
ecmaVersions);
|
ecmaVersions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void generateJavaScriptFiles(@NotNull List<String> files, @NotNull String testName,
|
||||||
|
@NotNull MainCallParameters mainCallParameters,
|
||||||
|
@NotNull Iterable<EcmaVersion> ecmaVersions,
|
||||||
|
@NotNull TestConfigFactory configFactory)
|
||||||
|
throws Exception {
|
||||||
|
for (EcmaVersion version : ecmaVersions) {
|
||||||
|
TranslationUtils.translateFiles(getProject(), withAdditionalFiles(files),
|
||||||
|
getOutputFilePath(testName, version), mainCallParameters,
|
||||||
|
version, configFactory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void generateJavaScriptFiles(@NotNull List<String> files, @NotNull String testName,
|
protected void generateJavaScriptFiles(@NotNull List<String> files, @NotNull String testName,
|
||||||
@NotNull MainCallParameters mainCallParameters, @NotNull Iterable<EcmaVersion> ecmaVersions)
|
@NotNull MainCallParameters mainCallParameters, @NotNull Iterable<EcmaVersion> ecmaVersions)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
for (EcmaVersion version : ecmaVersions) {
|
for (EcmaVersion version : ecmaVersions) {
|
||||||
TranslationUtils.translateFiles(getProject(), withAdditionalFiles(files),
|
TranslationUtils.translateFiles(getProject(), withAdditionalFiles(files),
|
||||||
getOutputFilePath(testName, version), mainCallParameters, version);
|
getOutputFilePath(testName, version), mainCallParameters,
|
||||||
|
version, TestConfig.FACTORY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,18 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author Pavel Talanov
|
* @author Pavel Talanov
|
||||||
*/
|
*/
|
||||||
public final class TestConfig extends Config {
|
public class TestConfig extends Config {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static TestConfigFactory FACTORY = new TestConfigFactory() {
|
||||||
|
@Override
|
||||||
|
public TestConfig create(@NotNull Project project,
|
||||||
|
@NotNull EcmaVersion version,
|
||||||
|
@NotNull List<JetFile> files,
|
||||||
|
@NotNull BindingContext context) {
|
||||||
|
return new TestConfig(project, version, files, context);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//NOTE: hard-coded in kotlin-lib files
|
//NOTE: hard-coded in kotlin-lib files
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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.k2js.test.config;
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
|
import org.jetbrains.k2js.config.EcmaVersion;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Pavel Talanov
|
||||||
|
*/
|
||||||
|
public interface TestConfigFactory {
|
||||||
|
TestConfig create(@NotNull Project project, @NotNull EcmaVersion version,
|
||||||
|
@NotNull List<JetFile> files, @NotNull BindingContext context);
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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.k2js.test.config;
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
|
import org.jetbrains.k2js.config.EcmaVersion;
|
||||||
|
import org.jetbrains.k2js.translate.test.JSRhinoUnitTester;
|
||||||
|
import org.jetbrains.k2js.translate.test.JSTester;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Pavel Talanov
|
||||||
|
*/
|
||||||
|
public class TestConfigWithUnitTests extends TestConfig {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static TestConfigFactory FACTORY = new TestConfigFactory() {
|
||||||
|
@Override
|
||||||
|
public TestConfig create(@NotNull Project project,
|
||||||
|
@NotNull EcmaVersion version,
|
||||||
|
@NotNull List<JetFile> files,
|
||||||
|
@NotNull BindingContext context) {
|
||||||
|
return new TestConfigWithUnitTests(project, version, files, context);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSTester getTester() {
|
||||||
|
return new JSRhinoUnitTester();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TestConfigWithUnitTests(@NotNull Project project,
|
||||||
|
@NotNull EcmaVersion version,
|
||||||
|
@NotNull List<JetFile> files,
|
||||||
|
@NotNull BindingContext context) {
|
||||||
|
super(project, version, files, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ import org.jetbrains.k2js.config.Config;
|
|||||||
import org.jetbrains.k2js.config.EcmaVersion;
|
import org.jetbrains.k2js.config.EcmaVersion;
|
||||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
import org.jetbrains.k2js.facade.MainCallParameters;
|
||||||
import org.jetbrains.k2js.test.MultipleFilesTranslationTest;
|
import org.jetbrains.k2js.test.MultipleFilesTranslationTest;
|
||||||
|
import org.jetbrains.k2js.test.config.TestConfigWithUnitTests;
|
||||||
import org.jetbrains.k2js.test.rhino.RhinoSystemOutputChecker;
|
import org.jetbrains.k2js.test.rhino.RhinoSystemOutputChecker;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -72,7 +73,8 @@ public class JsUnitTestBase extends MultipleFilesTranslationTest {
|
|||||||
|
|
||||||
private void performUnitTest(String... testFiles) throws Exception {
|
private void performUnitTest(String... testFiles) throws Exception {
|
||||||
Iterable<EcmaVersion> versions = Collections.singletonList(EcmaVersion.v3);
|
Iterable<EcmaVersion> versions = Collections.singletonList(EcmaVersion.v3);
|
||||||
generateJavaScriptFiles(Lists.newArrayList(testFiles), "myTest", MainCallParameters.noCall(), versions);
|
generateJavaScriptFiles(Lists.newArrayList(testFiles), "myTest", MainCallParameters.noCall(), versions,
|
||||||
|
TestConfigWithUnitTests.FACTORY);
|
||||||
runRhinoTests("myTest", versions, new RhinoSystemOutputChecker(""));
|
runRhinoTests("myTest", versions, new RhinoSystemOutputChecker(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.k2js.test.utils;
|
package org.jetbrains.k2js.test.utils;
|
||||||
|
|
||||||
import closurecompiler.internal.com.google.common.collect.Maps;
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.dart.compiler.backend.js.ast.JsProgram;
|
import com.google.dart.compiler.backend.js.ast.JsProgram;
|
||||||
@@ -34,26 +33,23 @@ import org.jetbrains.k2js.config.EcmaVersion;
|
|||||||
import org.jetbrains.k2js.facade.K2JSTranslator;
|
import org.jetbrains.k2js.facade.K2JSTranslator;
|
||||||
import org.jetbrains.k2js.facade.MainCallParameters;
|
import org.jetbrains.k2js.facade.MainCallParameters;
|
||||||
import org.jetbrains.k2js.generate.CodeGenerator;
|
import org.jetbrains.k2js.generate.CodeGenerator;
|
||||||
import org.jetbrains.k2js.test.config.TestConfig;
|
import org.jetbrains.k2js.test.config.TestConfigFactory;
|
||||||
import org.jetbrains.k2js.utils.JetFileUtils;
|
import org.jetbrains.k2js.utils.JetFileUtils;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.jetbrains.k2js.utils.JetFileUtils.createPsiFileList;
|
import static org.jetbrains.k2js.utils.JetFileUtils.createPsiFileList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pavel Talanov
|
* @author Pavel Talanov
|
||||||
*/
|
*/
|
||||||
|
//TODO: use method object
|
||||||
public final class TranslationUtils {
|
public final class TranslationUtils {
|
||||||
|
|
||||||
private TranslationUtils() {
|
private TranslationUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static final Map<EcmaVersion, Config> testConfigs = Maps.newHashMap();
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static BindingContext libraryContext = null;
|
private static BindingContext libraryContext = null;
|
||||||
|
|
||||||
@@ -96,22 +92,17 @@ public final class TranslationUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Config getConfig(@NotNull Project project, @NotNull EcmaVersion version) {
|
public static Config getConfig(@NotNull Project project, @NotNull EcmaVersion version, @NotNull TestConfigFactory configFactory) {
|
||||||
Config config = testConfigs.get(version);
|
BindingContext preanalyzedContext = getLibraryContext(project);
|
||||||
if (config == null) {
|
return configFactory.create(project, version, getLibFilesWithCode(getAllLibFiles(project)), preanalyzedContext);
|
||||||
BindingContext preanalyzedContext = getLibraryContext(project);
|
|
||||||
config = new TestConfig(project, version, getLibFilesWithCode(getAllLibFiles(project)), preanalyzedContext);
|
|
||||||
testConfigs.put(version, config);
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void translateFiles(@NotNull Project project, @NotNull List<String> inputFiles,
|
public static void translateFiles(@NotNull Project project, @NotNull List<String> inputFiles,
|
||||||
@NotNull String outputFile,
|
@NotNull String outputFile,
|
||||||
@NotNull MainCallParameters mainCallParameters,
|
@NotNull MainCallParameters mainCallParameters,
|
||||||
@NotNull EcmaVersion version) throws Exception {
|
@NotNull EcmaVersion version, TestConfigFactory configFactory) throws Exception {
|
||||||
List<JetFile> psiFiles = createPsiFileList(inputFiles, project);
|
List<JetFile> psiFiles = createPsiFileList(inputFiles, project);
|
||||||
JsProgram program = getTranslator(project, version).generateProgram(psiFiles, mainCallParameters);
|
JsProgram program = new K2JSTranslator(getConfig(project, version, configFactory)).generateProgram(psiFiles, mainCallParameters);
|
||||||
FileWriter writer = new FileWriter(new File(outputFile));
|
FileWriter writer = new FileWriter(new File(outputFile));
|
||||||
try {
|
try {
|
||||||
writer.write(CodeGenerator.generateProgramToString(program));
|
writer.write(CodeGenerator.generateProgramToString(program));
|
||||||
@@ -121,11 +112,6 @@ public final class TranslationUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static K2JSTranslator getTranslator(@NotNull Project project, @NotNull EcmaVersion version) {
|
|
||||||
return new K2JSTranslator(getConfig(project, version));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static List<JetFile> initLibFiles(@NotNull Project project) {
|
private static List<JetFile> initLibFiles(@NotNull Project project) {
|
||||||
return getLibFiles(project, Config.LIB_FILE_NAMES);
|
return getLibFiles(project, Config.LIB_FILE_NAMES);
|
||||||
|
|||||||
Reference in New Issue
Block a user