Make test create and delete out directories.
This commit is contained in:
@@ -55,7 +55,7 @@ public final class KotlinLibTest extends TranslationTest {
|
||||
final Map<String, Class<? extends Scriptable>> propertyToType
|
||||
= new HashMap<String, Class<? extends Scriptable>>();
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("trait.js")),
|
||||
new RhinoPropertyTypesChecker("foo", propertyToType));
|
||||
new RhinoPropertyTypesChecker("foo", propertyToType));
|
||||
}
|
||||
|
||||
|
||||
@@ -63,56 +63,61 @@ public final class KotlinLibTest extends TranslationTest {
|
||||
final Map<String, Class<? extends Scriptable>> propertyToType
|
||||
= new HashMap<String, Class<? extends Scriptable>>();
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("namespace.js")),
|
||||
new RhinoPropertyTypesChecker("foo", propertyToType));
|
||||
new RhinoPropertyTypesChecker("foo", propertyToType));
|
||||
}
|
||||
|
||||
//
|
||||
// TODO:Refactor calls to function result checker with test
|
||||
public void testNamespaceHasDeclaredFunction() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("namespace.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testNamespaceHasDeclaredClasses() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("namespaceWithClasses.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testIsSameType() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("isSameType.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testIsAncestorType() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("isAncestorType.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testIsComplexTest() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("isComplexTest.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testCommaExpression() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("commaExpression.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testArray() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("array.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
|
||||
public void testHashMap() throws Exception {
|
||||
runRhinoTest(Arrays.asList(kotlinLibraryPath(), cases("hashMap.js")),
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
new RhinoFunctionResultChecker("test", true));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldCreateOut() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,10 +46,15 @@ public final class Suite extends TranslationTest {
|
||||
});
|
||||
}
|
||||
|
||||
// //NOTE: just to avoid warning
|
||||
//NOTE: just to avoid warning
|
||||
public void testNothing() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldCreateOut() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String mainDirectory() {
|
||||
return testMain;
|
||||
|
||||
@@ -42,7 +42,8 @@ import static org.jetbrains.k2js.utils.JetFileUtils.createPsiFileList;
|
||||
*/
|
||||
public abstract class TranslationTest extends BaseTest {
|
||||
|
||||
public final static String TEST_FILES = "js.translator/testFiles/";
|
||||
private static final boolean DELETE_OUT = true;
|
||||
public static final String TEST_FILES = "js.translator/testFiles/";
|
||||
private static final String CASES = "cases/";
|
||||
private static final String OUT = "out/";
|
||||
private static final String KOTLIN_JS_LIB = TEST_FILES + "kotlin_lib.js";
|
||||
@@ -61,6 +62,33 @@ public abstract class TranslationTest extends BaseTest {
|
||||
K2JSTranslator.saveProgramToFile(outputFile, program);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
//noinspection PointlessBooleanExpression
|
||||
if (!shouldCreateOut() || !DELETE_OUT) {
|
||||
return;
|
||||
}
|
||||
File outDir = new File(getOutputPath());
|
||||
assert (!outDir.exists() || outDir.isDirectory()) : "If out already exists it should be a directory.";
|
||||
if (!outDir.exists()) {
|
||||
boolean success = outDir.mkdir();
|
||||
assert success;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
if (!shouldCreateOut()) {
|
||||
return;
|
||||
}
|
||||
File outDir = new File(getOutputPath());
|
||||
assert outDir.exists();
|
||||
boolean success = FileUtil.delete(outDir);
|
||||
assert success;
|
||||
}
|
||||
|
||||
protected static String kotlinLibraryPath() {
|
||||
return KOTLIN_JS_LIB;
|
||||
}
|
||||
@@ -114,6 +142,10 @@ public abstract class TranslationTest extends BaseTest {
|
||||
new RhinoFunctionResultChecker(namespaceName, functionName, expectedResult));
|
||||
}
|
||||
|
||||
protected boolean shouldCreateOut() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void translateFile(String filename) throws Exception {
|
||||
translateFile(getInputFilePath(filename),
|
||||
getOutputFilePath(filename));
|
||||
@@ -124,7 +156,7 @@ public abstract class TranslationTest extends BaseTest {
|
||||
File dir = new File(dirPath);
|
||||
List<String> fullFilePaths = new ArrayList<String>();
|
||||
for (String fileName : dir.list()) {
|
||||
fullFilePaths.add(getInputFilePath(dirName) + "\\" + fileName);
|
||||
fullFilePaths.add(getInputFilePath(dirName) + "/" + fileName);
|
||||
}
|
||||
assert dir.isDirectory();
|
||||
traslateFiles(fullFilePaths,
|
||||
|
||||
Reference in New Issue
Block a user