From ee27415bf7777c0317a1cb6029e6c7c6a529fa96 Mon Sep 17 00:00:00 2001 From: pTalanov Date: Wed, 29 Feb 2012 17:08:09 +0400 Subject: [PATCH] Make test create and delete out directories. --- .../jetbrains/k2js/test/KotlinLibTest.java | 25 +++++++------ .../test/org/jetbrains/k2js/test/Suite.java | 7 +++- .../jetbrains/k2js/test/TranslationTest.java | 36 +++++++++++++++++-- 3 files changed, 55 insertions(+), 13 deletions(-) diff --git a/js/js.tests/test/org/jetbrains/k2js/test/KotlinLibTest.java b/js/js.tests/test/org/jetbrains/k2js/test/KotlinLibTest.java index ea94e687ba9..2fb1afd4e19 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/KotlinLibTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/KotlinLibTest.java @@ -55,7 +55,7 @@ public final class KotlinLibTest extends TranslationTest { final Map> propertyToType = new HashMap>(); 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> propertyToType = new HashMap>(); 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; } } diff --git a/js/js.tests/test/org/jetbrains/k2js/test/Suite.java b/js/js.tests/test/org/jetbrains/k2js/test/Suite.java index 75ff01988a0..23ba6f2a5aa 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/Suite.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/Suite.java @@ -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; diff --git a/js/js.tests/test/org/jetbrains/k2js/test/TranslationTest.java b/js/js.tests/test/org/jetbrains/k2js/test/TranslationTest.java index cd3a6d72a54..07d7e13e7a1 100644 --- a/js/js.tests/test/org/jetbrains/k2js/test/TranslationTest.java +++ b/js/js.tests/test/org/jetbrains/k2js/test/TranslationTest.java @@ -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 fullFilePaths = new ArrayList(); for (String fileName : dir.list()) { - fullFilePaths.add(getInputFilePath(dirName) + "\\" + fileName); + fullFilePaths.add(getInputFilePath(dirName) + "/" + fileName); } assert dir.isDirectory(); traslateFiles(fullFilePaths,