Trying to run stdlib unit tests as part or js.tests: first step

This commit is contained in:
Pavel V. Talanov
2012-07-05 20:15:25 +04:00
parent 5683ee456f
commit ec7b0a1d3a
13 changed files with 391 additions and 57 deletions
@@ -43,8 +43,8 @@ public abstract class BasicTest extends TestWithEnvironment {
private static final String CASES = "cases/";
private static final String OUT = "out/";
private static final String EXPECTED = "expected/";
public static final String JSLINT_LIB = pathToTestFilesRoot() + "jslint.js";
public static final String JSLINT_LIB = pathToTestFilesRoot() + "jslint.js";
@NotNull
private String mainDirectory = "";
@@ -103,21 +103,35 @@ public abstract class BasicTest extends TestWithEnvironment {
@NotNull MainCallParameters mainCallParameters, @NotNull Iterable<EcmaVersion> ecmaVersions)
throws Exception {
for (EcmaVersion version : ecmaVersions) {
TranslationUtils.translateFiles(getProject(), files, getOutputFilePath(testName, version), mainCallParameters, version);
TranslationUtils.translateFiles(getProject(), withAdditionalFiles(files),
getOutputFilePath(testName, version), mainCallParameters, version);
}
}
protected void runRhinoTests(@NotNull String filename, @NotNull Iterable<EcmaVersion> ecmaVersions, @NotNull RhinoResultChecker checker) throws Exception {
@NotNull
private List<String> withAdditionalFiles(@NotNull List<String> files) {
List<String> result = Lists.newArrayList(files);
result.addAll(additionalKotlinFiles());
return result;
}
protected void runRhinoTests(@NotNull String filename, @NotNull Iterable<EcmaVersion> ecmaVersions,
@NotNull RhinoResultChecker checker) throws Exception {
for (EcmaVersion ecmaVersion : ecmaVersions) {
runRhinoTest(withAdditionalFiles(getOutputFilePath(filename, ecmaVersion), ecmaVersion), checker, getRhinoTestVariables(),
ecmaVersion);
}
}
protected Map<String,Object> getRhinoTestVariables() throws Exception {
protected Map<String, Object> getRhinoTestVariables() throws Exception {
return null;
}
@NotNull
protected List<String> additionalKotlinFiles() {
return Lists.newArrayList();
}
protected static String casesDirectoryName() {
return CASES;
@@ -0,0 +1,70 @@
/*
* 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.semantics;
import closurecompiler.internal.com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.k2js.config.Config;
import org.jetbrains.k2js.config.EcmaVersion;
import org.jetbrains.k2js.test.MultipleFilesTranslationTest;
import java.util.ArrayList;
import java.util.List;
import static org.jetbrains.k2js.test.utils.LibraryFilePathsUtil.getAdditionalLibraryFiles;
/**
* @author Pavel Talanov
*/
public class JsUnitTestBase extends MultipleFilesTranslationTest {
@NotNull
private static final String JS_TESTS = pathToTestFilesRoot() + "jsTester/";
@NotNull
protected static final String JS_TESTS_KT = JS_TESTS + "jsTester.kt";
@NotNull
protected static final String JS_TESTS_JS = JS_TESTS + "jsTester.js";
public JsUnitTestBase() {
super("jsUnitTests/");
}
@NotNull
@Override
protected List<String> additionalJSFiles(@NotNull EcmaVersion ecmaVersion) {
ArrayList<String> result = Lists.newArrayList(super.additionalJSFiles(ecmaVersion));
result.add(JS_TESTS_JS);
return result;
}
@NotNull
@Override
protected List<String> additionalKotlinFiles() {
ArrayList<String> result = Lists.newArrayList();
List<String> additionalLibraryFiles = getAdditionalLibraryFiles();
additionalLibraryFiles.add(JS_TESTS_KT);
boolean removed = additionalLibraryFiles.remove(Config.LIBRARIES_LOCATION + "/stdlib/testCode.kt");
assert removed;
result.addAll(additionalLibraryFiles);
return result;
}
public void testDummy() throws Exception {
checkFooBoxIsTrue("test");
}
}
@@ -27,6 +27,7 @@ import org.jetbrains.jet.cli.js.K2JSCompilerArguments;
import org.jetbrains.k2js.config.Config;
import org.jetbrains.k2js.config.EcmaVersion;
import org.jetbrains.k2js.test.SingleFileTranslationTest;
import org.jetbrains.k2js.test.utils.LibraryFilePathsUtil;
import javax.annotation.Nullable;
import java.io.File;
@@ -47,7 +48,7 @@ abstract class StdLibTestBase extends SingleFileTranslationTest {
}
private void compileFiles(@NotNull EnumSet<EcmaVersion> ecmaVersions, @NotNull List<String> files) throws Exception {
List<String> libFiles = createLibFilesList();
List<String> libFiles = LibraryFilePathsUtil.getBasicLibraryFiles();
for (EcmaVersion version : ecmaVersions) {
String outputFilePath = getOutputFilePath(getTestName(false) + ".compiler.kt", version);
invokeCompiler(files, libFiles, version, outputFilePath);
@@ -84,37 +85,20 @@ abstract class StdLibTestBase extends SingleFileTranslationTest {
}
@NotNull
private static List<String> createLibFilesList() {
return Lists.transform(Config.LIB_FILE_NAMES, new Function<String, String>() {
@Override
public String apply(@Nullable String s) {
return Config.LIBRARIES_LOCATION + s;
}
});
private static List<String> constructFilesToCompileList(@NotNull String sourceDir, @NotNull String[] stdLibFiles) {
List<String> files = filesFromDir(sourceDir, stdLibFiles);
files.addAll(LibraryFilePathsUtil.getAdditionalLibraryFiles());
return files;
}
@NotNull
private static List<String> constructFilesToCompileList(@NotNull String sourceDir, @NotNull String[] stdLibFiles) {
private static List<String> filesFromDir(@NotNull String sourceDir, @NotNull String[] stdLibFiles) {
List<String> files = Lists.newArrayList();
File stdlibDir = new File(sourceDir);
assertTrue("Cannot find stdlib source: " + stdlibDir, stdlibDir.exists());
for (String file : stdLibFiles) {
files.add(new File(stdlibDir, file).getPath());
}
// lets add the standard JS library files
Iterable<String> names = Config.LIB_FILE_NAMES_DEPENDENT_ON_STDLIB;
for (String libFileName : names) {
System.out.println("Compiling " + libFileName);
files.add(Config.LIBRARIES_LOCATION + libFileName);
}
// lets add the standard Kotlin library files
for (String libFileName : Config.STDLIB_FILE_NAMES) {
System.out.println("Compiling " + libFileName);
files.add(Config.STDLIB_LOCATION + libFileName);
}
return files;
}
}
@@ -60,7 +60,7 @@ public final class JsTestUtils {
@NotNull
public static List<String> getAllFilesInDir(@NotNull String dirName) {
File dir = new File(dirName);
assert dir.isDirectory();
assert dir.isDirectory() : dir + " is not a directory.";
List<String> fullFilePaths = new ArrayList<String>();
for (String fileName : dir.list()) {
fullFilePaths.add(dirName + "/" + fileName);
@@ -0,0 +1,61 @@
/*
* 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.utils;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.k2js.config.Config;
import javax.annotation.Nullable;
import java.util.List;
/**
* @author Pavel Talanov
*/
public final class LibraryFilePathsUtil {
private LibraryFilePathsUtil() {
}
@NotNull
public static List<String> getBasicLibraryFiles() {
return Lists.transform(Config.LIB_FILE_NAMES, new Function<String, String>() {
@Override
public String apply(@Nullable String s) {
return Config.LIBRARIES_LOCATION + s;
}
});
}
@NotNull
public static List<String> getAdditionalLibraryFiles() {
List<String> additionalKotlinFiles = Lists.newArrayList();
// lets add the standard JS library files
Iterable<String> names = Config.LIB_FILE_NAMES_DEPENDENT_ON_STDLIB;
for (String libFileName : names) {
System.out.println("Compiling " + libFileName);
additionalKotlinFiles.add(Config.LIBRARIES_LOCATION + libFileName);
}
// lets add the standard Kotlin library files
for (String libFileName : Config.STDLIB_FILE_NAMES) {
System.out.println("Compiling " + libFileName);
additionalKotlinFiles.add(Config.STDLIB_LOCATION + libFileName);
}
return additionalKotlinFiles;
}
}