KJS: remove unnecessary test runners (mostly for stdlib)

Stdlib tests run separately via gradle.
This commit is contained in:
Zalim Bashorov
2017-03-16 23:06:17 +03:00
parent 5ef75e6e2b
commit c112542935
20 changed files with 0 additions and 964 deletions
@@ -1,62 +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;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.js.config.EcmaVersion;
import org.jetbrains.kotlin.js.facade.MainCallParameters;
import org.jetbrains.kotlin.js.test.rhino.RhinoFunctionResultChecker;
import java.util.List;
import static org.jetbrains.kotlin.js.test.utils.JsTestUtils.getAllFilesInDir;
public abstract class MultipleFilesTranslationTest extends BasicTest {
public MultipleFilesTranslationTest(@NotNull String main) {
super(main);
}
@Override
protected void checkFooBoxIsOkByPath(String filePath) throws Exception {
runMultiFileTest(getTestName(true), TEST_PACKAGE, TEST_FUNCTION, "OK");
}
private void generateJsFromDir(@NotNull String dirName, @NotNull Iterable<EcmaVersion> ecmaVersions) throws Exception {
List<String> fullFilePaths = getAllFilesInDir(getInputFilePath(dirName));
generateJavaScriptFiles(fullFilePaths, dirName, MainCallParameters.noCall(), ecmaVersions);
}
private void runMultiFileTest(
@NotNull String dirName, @NotNull String packageName,
@NotNull String functionName, @NotNull Object expectedResult
) throws Exception {
runMultiFileTests(DEFAULT_ECMA_VERSIONS, dirName, packageName, functionName, expectedResult);
}
private void runMultiFileTests(
@NotNull Iterable<EcmaVersion> ecmaVersions,
@NotNull String dirName,
@NotNull String packageName,
@NotNull String functionName,
@NotNull Object expectedResult
) throws Exception {
generateJsFromDir(dirName, ecmaVersions);
runRhinoTests(dirName + ".kt", ecmaVersions, new RhinoFunctionResultChecker(TEST_MODULE, packageName, functionName, expectedResult));
}
}
@@ -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.semantics;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.js.test.SingleFileTranslationTest;
public abstract class AbstractExpressionTest extends SingleFileTranslationTest {
public AbstractExpressionTest(@NotNull String main) {
super("expression/" + main);
}
}
@@ -1,125 +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.semantics;
import com.google.common.collect.Lists;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.cli.common.ExitCode;
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
import org.jetbrains.kotlin.js.config.EcmaVersion;
import org.jetbrains.kotlin.js.test.SingleFileTranslationTest;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Lets test compiling all the JS code thats used by the library-js-library from the maven build
*
* This test case isn't run by default but can only be ran after the maven build
* has completed so that there are various kotlin files to be compiled
*/
public class CompileMavenGeneratedJSLibrary extends SingleFileTranslationTest {
private static final String generatedJsDir = "libraries/tools/kotlin-js-library/target/";
private static final String generatedJsDefinitionsDir = generatedJsDir + "generated-js-definitions";
private final File generatedJsLibraryDir = new File(generatedJsDir + "generated-js-library");
public CompileMavenGeneratedJSLibrary() {
super("kotlin-js-library/");
}
public static void main(String[] args) throws Exception {
CompileMavenGeneratedJSLibrary test = new CompileMavenGeneratedJSLibrary();
test.DISABLED_testGenerateTestCase();
}
public void testDummy() {
}
public void DISABLED_testGenerateTestCase() throws Exception {
if (generatedJsLibraryDir.exists() && generatedJsLibraryDir.isDirectory()) {
generateJavaScriptFiles(DEFAULT_ECMA_VERSIONS,
"libraries/stdlib/test",
"collections/ArraysTest.kt",
"dom/DomTest.kt",
"js/MapTest.kt",
"js/JsDomTest.kt",
"collections/FunctionIteratorTest.kt",
"collections/IteratorsTest.kt",
"GetOrElseTest.kt",
"collections/ListTest.kt",
"collections/SetTest.kt",
"text/StringTest.kt");
}
else {
System.out.println("Warning " + generatedJsLibraryDir + " does not exist - I guess you've not run the maven build in library/ yet?");
}
}
private void generateJavaScriptFiles(
@NotNull Iterable<EcmaVersion> ecmaVersions,
@NotNull String sourceDir,
@NotNull String... stdLibFiles
) throws Exception {
List<String> files = Lists.newArrayList();
// now lets add all the files from the definitions and library
//addAllSourceFiles(files, generatedJsDefinitionsDir);
addAllSourceFiles(files, generatedJsLibraryDir);
File stdlibDir = new File(sourceDir);
assertTrue("Cannot find stdlib test source: " + stdlibDir, stdlibDir.exists());
for (String file : stdLibFiles) {
files.add(new File(stdlibDir, file).getPath());
}
// now lets try invoke the compiler
for (EcmaVersion version : ecmaVersions) {
String outputFile = getOutputFilePath(getTestName(false) + ".compiler.kt", version);
System.out.println("Compiling with version: " + version + " to: " + outputFile);
List<String> args = new ArrayList<>(Arrays.asList(
"-output", outputFile,
"-libraries", generatedJsDefinitionsDir,
"-verbose"
));
args.addAll(files);
ExitCode answer = new K2JSCompiler().exec(System.out, ArrayUtil.toStringArray(args));
assertEquals("Compile failed", ExitCode.OK, answer);
}
}
private static void addAllSourceFiles(List<String> files, File dir) {
File[] children = dir.listFiles();
if (children != null && children.length > 0) {
for (File child : children) {
if (child.isDirectory()) {
addAllSourceFiles(files, child);
}
else {
String name = child.getName();
if (name.toLowerCase().endsWith(".kt")) {
files.add(child.getPath());
}
}
}
}
}
}
@@ -1,109 +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.semantics;
import com.google.common.collect.Lists;
import junit.framework.Test;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.js.config.EcmaVersion;
import org.jetbrains.kotlin.js.facade.MainCallParameters;
import org.jetbrains.kotlin.js.test.MultipleFilesTranslationTest;
import org.jetbrains.kotlin.js.test.rhino.RhinoSystemOutputChecker;
import org.jetbrains.kotlin.js.test.rhino.RhinoUtils;
import org.jetbrains.kotlin.js.test.utils.JsUnitTestReporter;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public abstract class JsUnitTestBase extends MultipleFilesTranslationTest {
@NotNull
private static final String JS_TESTS = TEST_DATA_DIR_PATH + "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";
//NOTE: we use this object to communicate test result from Rhino, it is not necessary to use global objects there
// we can inject those objects in JavaScript every time but this kind of solution will complicate logic a bit
@NotNull
private static final JsUnitTestReporter JS_UNIT_TEST_REPORTER = new JsUnitTestReporter();
public JsUnitTestBase() {
super("jsUnitTests/");
}
@NotNull
@Override
protected List<String> additionalJsFiles(@NotNull EcmaVersion ecmaVersion) {
List<String> result = Lists.newArrayList(super.additionalJsFiles(ecmaVersion));
result.add(JS_TESTS_JS);
return result;
}
@NotNull
@Override
protected List<String> additionalKotlinFiles() {
List<String> result = StdLibTestBase.removeAdHocAssertions(super.additionalKotlinFiles());
result.add(JS_TESTS_KT);
result.add("libraries/stdlib/test/testUtils.kt");
return result;
}
@Override
protected boolean shouldBeTranslateAsUnitTestClass() {
return true;
}
public void runTestFile(@NotNull String pathToTestFile) throws Exception {
Iterable<EcmaVersion> versions = DEFAULT_ECMA_VERSIONS;
String testName = pathToTestFile.substring(pathToTestFile.lastIndexOf("/"));
generateJavaScriptFiles(Collections.singletonList(pathToTestFile), testName, MainCallParameters.noCall(), versions);
runRhinoTests(testName, versions, new RhinoSystemOutputChecker(""));
}
@NotNull
public static Test createTestSuiteForFile(@NotNull String file, @NotNull String... ignoreFailedTestCases) throws Exception {
performTests(file);
JS_UNIT_TEST_REPORTER.ignoreTests(ignoreFailedTestCases);
return JS_UNIT_TEST_REPORTER.createTestSuiteAndFlush();
}
private static void performTests(@NotNull String testFile) throws Exception {
//NOTE: well it doesn't
@SuppressWarnings("JUnitTestCaseWithNoTests") JsUnitTestBase runner = new JsUnitTestBase() {
};
try {
runner.setUp();
runner.runTestFile(testFile);
}
finally {
runner.tearDown();
}
}
@Override
protected Map<String, Object> getRhinoTestVariables() throws Exception {
Map<String, Object> testVariables = new HashMap<>();
testVariables.put(RhinoUtils.OPTIMIZATION_LEVEL_TEST_VARIABLE, RhinoUtils.OPTIMIZATION_OFF);
testVariables.put("jsTestReporter", JS_UNIT_TEST_REPORTER);
return testVariables;
}
}
@@ -1,27 +0,0 @@
/*
* 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.semantics;
import junit.framework.Test;
//NOTE: well, it has tests
@SuppressWarnings("JUnitTestCaseWithNoTests")
public final class StdLibBitwiseOperationsTest extends JsUnitTestBase {
public static Test suite() throws Exception {
return createTestSuiteForFile("libraries/stdlib/test/numbers/BitwiseOperationsTest.kt");
}
}
@@ -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.semantics;
import junit.framework.Test;
@SuppressWarnings("JUnitTestCaseWithNoTests")
public final class StdLibIterableTest extends JsUnitTestBase {
public static Test suite() throws Exception {
return createTestSuiteForFile("libraries/stdlib/test/collections/IterableTests.kt");
}
}
@@ -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.semantics;
import junit.framework.Test;
//NOTE: well, it has tests
@SuppressWarnings("JUnitTestCaseWithNoTests")
public final class StdLibIteratorsTest extends JsUnitTestBase {
public static Test suite() throws Exception {
return createTestSuiteForFile("libraries/stdlib/test/collections/IteratorsTest.kt");
}
}
@@ -1,37 +0,0 @@
/*
* 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.semantics;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.js.test.rhino.CompositeRhinoResultsChecker;
import org.jetbrains.kotlin.js.test.rhino.RhinoFunctionResultChecker;
import org.jetbrains.kotlin.js.test.rhino.RhinoResultChecker;
public class StdLibJsArrayScriptTest extends StdLibTestBase {
public void testArrayScriptTest() throws Exception {
performStdLibTest(DEFAULT_ECMA_VERSIONS, "libraries/stdlib/test", "js/JsArrayScript.kt");
}
@NotNull
@Override
protected RhinoResultChecker getResultChecker() {
return new CompositeRhinoResultsChecker(
new RhinoFunctionResultChecker(TEST_MODULE, "test.collections.js", "testSize", 3.0),
new RhinoFunctionResultChecker(TEST_MODULE, "test.collections.js", "testToListToString", "[]-[foo]-[foo, bar]")
);
}
}
@@ -1,26 +0,0 @@
/*
* 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.semantics;
import junit.framework.Test;
@SuppressWarnings("JUnitTestCaseWithNoTests")
public final class StdLibJsCollectionsTest extends JsUnitTestBase {
public static Test suite() throws Exception {
return createTestSuiteForFile("libraries/stdlib/test/js/JsCollectionsTest.kt");
}
}
@@ -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.semantics;
import junit.framework.Test;
//NOTE: well, it has tests
@SuppressWarnings("JUnitTestCaseWithNoTests")
public final class StdLibListTest extends JsUnitTestBase {
public static Test suite() throws Exception {
return createTestSuiteForFile("libraries/stdlib/test/collections/ListSpecificTest.kt");
}
}
@@ -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.semantics;
import junit.framework.Test;
@SuppressWarnings("JUnitTestCaseWithNoTests")
public final class StdLibMapTest extends JsUnitTestBase {
public static Test suite() throws Exception {
return createTestSuiteForFile("libraries/stdlib/test/collections/MapTest.kt");
}
}
@@ -1,47 +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.semantics;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.js.config.EcmaVersion;
import org.jetbrains.kotlin.js.test.rhino.RhinoQUnitResultChecker;
import org.jetbrains.kotlin.js.test.rhino.RhinoResultChecker;
import java.util.List;
/**
* A base class for any JS compile test cases which should run the generated JS file as a QUnit test case
*/
public abstract class StdLibQUnitTestSupport extends StdLibTestBase {
@Nullable
@Override
protected RhinoResultChecker getResultChecker() {
return new RhinoQUnitResultChecker();
}
@NotNull
@Override
protected List<String> additionalJsFiles(@NotNull EcmaVersion ecmaVersion) {
List<String> files = Lists.newArrayList(super.additionalJsFiles(ecmaVersion));
files.add("js/js.translator/qunit/qunit.js");
files.add("js/js.translator/qunit/headless.js");
return files;
}
}
@@ -1,26 +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.semantics;
import junit.framework.Test;
@SuppressWarnings("JUnitTestCaseWithNoTests")
public final class StdLibStringBuilderTest extends JsUnitTestBase {
public static Test suite() throws Exception {
return createTestSuiteForFile("libraries/stdlib/test/text/StringBuilderTest.kt");
}
}
@@ -1,26 +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.semantics;
import junit.framework.Test;
@SuppressWarnings("JUnitTestCaseWithNoTests")
public final class StdLibStringTest extends JsUnitTestBase {
public static Test suite() throws Exception {
return createTestSuiteForFile("libraries/stdlib/test/text/StringTest.kt");
}
}
@@ -1,84 +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.semantics;
import com.google.common.collect.Lists;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.js.config.EcmaVersion;
import org.jetbrains.kotlin.js.facade.MainCallParameters;
import org.jetbrains.kotlin.js.test.SingleFileTranslationTest;
import org.jetbrains.kotlin.js.test.rhino.RhinoResultChecker;
import java.io.File;
import java.util.Iterator;
import java.util.List;
// TODO: should be dropped with derived classes?
abstract class StdLibTestBase extends SingleFileTranslationTest {
protected StdLibTestBase() {
super("stdlib/");
}
@Nullable
protected abstract RhinoResultChecker getResultChecker();
protected void performStdLibTest(
@NotNull Iterable<EcmaVersion> ecmaVersions,
@NotNull String sourceDir,
@NotNull String... stdLibFiles
) throws Exception {
List<String> files = filesFromDir(sourceDir, stdLibFiles);
String testFileName = getTestName(true) + ".kt";
generateJavaScriptFiles(files, testFileName, MainCallParameters.noCall(), ecmaVersions);
RhinoResultChecker checker = getResultChecker();
if (checker != null) {
runRhinoTests(testFileName, ecmaVersions, checker);
}
}
@NotNull
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());
}
return files;
}
@NotNull
@Override
protected List<String> additionalKotlinFiles() {
return removeAdHocAssertions(super.additionalKotlinFiles());
}
@NotNull
public static List<String> removeAdHocAssertions(List<String> additionalKotlinFiles) {
List<String> kotlinFiles = Lists.newArrayList(additionalKotlinFiles);
Iterator<String> iterator = kotlinFiles.iterator();
while (iterator.hasNext()) {
if (new File(iterator.next()).getName().equals("asserts.kt"))
iterator.remove();
}
return kotlinFiles;
}
}
@@ -1,52 +0,0 @@
/*
* 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.semantics;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.js.test.rhino.RhinoResultChecker;
/**
*/
public class StdLibTestToJSTest extends StdLibQUnitTestSupport {
public void testGenerateTestCase() throws Exception {
performStdLibTest(DEFAULT_ECMA_VERSIONS,
"libraries/stdlib/test",
"js/JsArrayTest.kt",
"js/MapJsTest.kt",
"collections/ListSpecificTest.kt",
"collections/IteratorsTest.kt",
"collections/CollectionBehaviors.kt",
"collections/ComparisonDSL.kt",
"testUtils.kt",
"../../../js/js.libraries/test/core/testUtils.kt",
"text/StringTest.kt",
"OrderingTest.kt",
"collections/SequenceTest.kt",
"collections/IterableTests.kt",
"collections/ArraysTest.kt",
"ranges/RangeTest.kt",
"ranges/RangeIterationTest.kt"
);
}
@Nullable
@Override
protected RhinoResultChecker getResultChecker() {
// don't run, it's just smoke test this tests should be run in maven build.
return null;
}
}
@@ -1,142 +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.containers.ContainerUtil;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public class JsUnitTestReporter {
@NotNull
private final Map<String, Boolean> finishedTests = ContainerUtil.newHashMap();
@NotNull
private final Map<String, List<String>> errors = ContainerUtil.newHashMap();
@NotNull
private final List<String> processedTests = ContainerUtil.newArrayList();
@Nullable
private String currentTestName;
//NOTE: usable from Rhino
@SuppressWarnings("UnusedDeclaration")
public void testStart(@NotNull String testName) {
assert currentTestName == null;
currentTestName = testName;
}
//NOTE: usable from Rhino
@SuppressWarnings("UnusedDeclaration")
public void testFail(@NotNull String testName) {
assert currentTestName != null;
finishedTests.put(testName, false);
currentTestName = null;
}
//NOTE: usable from Rhino
@SuppressWarnings("UnusedDeclaration")
public void testSuccess(@NotNull String testName) {
assert currentTestName != null;
finishedTests.put(testName, true);
currentTestName = null;
}
//NOTE: usable from Rhino
@SuppressWarnings("UnusedDeclaration")
public void reportError(@NotNull String message) {
List<String> errorList = errors.get(currentTestName);
if (errorList == null) {
errors.put(currentTestName, ContainerUtil.newArrayList(message));
}
else {
errorList.add(message);
}
}
@NotNull
private Collection<String> getNewFinishedTests() {
List<String> finishedTests = ContainerUtil.newArrayList(this.finishedTests.keySet());
finishedTests.removeAll(processedTests);
return finishedTests;
}
@NotNull
public Collection<String> getErrors(@NotNull String testName) {
List<String> errorList = errors.get(testName);
assert errorList != null;
assert !errorList.isEmpty();
return errorList;
}
@NotNull
public Boolean getResult(@NotNull String testName) {
Boolean result = finishedTests.get(testName);
assert result != null;
return result;
}
@NotNull
public TestSuite createTestSuiteAndFlush() {
TestSuite suite = new TestSuite("!");
Collection<String> newFinishedTests = getNewFinishedTests();
for (String test : newFinishedTests) {
//NOTE: well, it is a test
//noinspection JUnitTestCaseWithNoTests
suite.addTest(new TestCase(test) {
@Override
protected void runTest() throws Throwable {
Boolean result = getResult(getName());
if (!result) {
Collection<String> errorMessages = getErrors(getName());
StringBuilder sb = new StringBuilder();
for (String error : errorMessages) {
sb.append(error);
}
eraseTestInfo(getName());
Assert.fail(sb.toString());
}
eraseTestInfo(getName());
}
});
}
processedTests.addAll(newFinishedTests);
return suite;
}
private void eraseTestInfo(@NotNull String testName) {
errors.remove(testName);
Boolean removed = finishedTests.remove(testName);
assert removed != null;
}
public void ignoreTests(@NotNull String... testNames) {
for (String testName : testNames) {
if (getResult(testName)) {
//TODO: make test fail?
System.out.println("Test " + testName + " has passed. And we ignored it! Turn it on?");
}
eraseTestInfo(testName);
}
}
}
-52
View File
@@ -1,52 +0,0 @@
/*
* Copyright 2010-2013 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.
*/
/*Asserter*/
var JsTests = (function () {
var reporter = jsTestReporter;
var failedTest = {};
var assert = function (isTrue, message) {
if (!isTrue) {
fail(message);
}
};
var fail = function (message) {
reporter.reportError(message);
throw failedTest;
};
var test = function (testName, testFun) {
reporter.testStart(testName);
try {
testFun();
}
catch (fail) {
if (fail != failedTest) {
reporter.reportError("Unexpected exception " + fail + "\n" + fail.stack);
}
reporter.testFail(testName);
return;
}
reporter.testSuccess(testName);
};
return {
test: test,
assert: assert,
fail: fail
}
})();
-13
View File
@@ -1,13 +0,0 @@
package kotlin.test
val init = run {
_asserter = JsTestsAsserter()
}
public class JsTestsAsserter() : Asserter {
public override fun fail(message: String?): Nothing = failWithMessage(message)
}
public inline fun assert(value: Boolean, message: String?): Unit = js("JsTests").assert(value, message)
private inline fun failWithMessage(message: String?): Nothing = js("JsTests").fail(message)
@@ -1,4 +1,3 @@
// this package referenced from testArrayScriptTest
package test.collections.js
fun testSize(): Int {