Permalink
Browse files

redesigned AllTests to enable execution of single tests

  • Loading branch information...
1 parent c17c0da commit 9cee1352386eef5ec748e8dcdf262acd89ae2402 @pavlobaron pavlobaron committed Dec 29, 2010
View
2 erjang_cfg.properties
@@ -5,3 +5,5 @@ erjang.otp.version = R14B
# erjang.debug.port=true
# erjang.debug.inet=true
# erjang.dump_on_exit = true
+
+erjang.triq.root = c:/Users/pb/code/ex/triq
View
58 src/test/java/erjang/AllTests.java
@@ -20,6 +20,10 @@
package erjang;
import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -36,60 +40,76 @@ public static Test suite() {
TestSuite otpCompileSuite = new TestSuite("Compiling OTP");
//$JUnit-BEGIN$
- find_beam_files(otpCompileSuite, new File(OTP_HOME));
+ Map<File, List<File>> testsOTP = new HashMap<File, List<File>>();
+ find_beam_files(testsOTP, new File(OTP_HOME));
+ buildTestHiearchie(testsOTP, otpCompileSuite, TestCompileFile.class);
//$JUnit-END$
suite.addTest(otpCompileSuite);
TestSuite coverageRunSuite = new TestSuite("Coverage run tests");
//$JUnit-BEGIN$
- find_erl_files(coverageRunSuite, new File("src/test/erl"));
+ Map<File, List<File>> testsErl = new HashMap<File, List<File>>();
+ find_erl_files(testsErl, new File("src/test/erl"));
+ buildTestHiearchie(testsErl, coverageRunSuite, TestRunFile.class);
//$JUnit-END$
suite.addTest(coverageRunSuite);
return suite;
}
-
- static void find_beam_files(TestSuite suite, File dir) {
- if (! dir.isDirectory()) throw new IllegalArgumentException("not a directory: "+dir);
+ protected static void buildTestHiearchie(Map<File, List<File>> tests, TestSuite suite, Class<? extends AbstractErjangTestCase> clazz) {
TestSuite ts = null;
+ for (File key : tests.keySet()) {
+ ts = new TestSuite(key.getPath());
+ for (File sub : tests.get(key)) {
+ try {
+ AbstractErjangTestCase tc = clazz.newInstance();
+ tc.setFile(sub);
+ ts.addTest(tc);
+ }
+ catch(Exception e) {
+ throw new IllegalArgumentException("cannot create object of: " + clazz);
+ }
+ }
+ }
+ }
+ static void find_beam_files(Map<File, List<File>> tests, File dir) {
+ List<File> ts = null;
+ if (! dir.isDirectory()) throw new IllegalArgumentException("not a directory: "+dir);
for (File file : dir.listFiles()) {
if (file.isDirectory()) {
- find_beam_files(suite, file);
+ find_beam_files(tests, file);
} else if (file.getName().endsWith(".beam")) {
if (ts == null) {
System.err.println("added.. " + dir);
-
- ts = new TestSuite(dir.getPath());
- suite.addTest(ts);
+
+ ts = new ArrayList<File>();
+ tests.put(dir, ts);
}
- ts.addTest(new TestCompileFile(file));
-
- // System.out.println("added: "+file);
+ ts.add(file);
}
}
}
- static void find_erl_files(TestSuite suite, File dir) {
+ static void find_erl_files(Map<File, List<File>> tests, File dir) {
if (! dir.isDirectory()) throw new IllegalArgumentException("not a directory: "+dir);
- TestSuite ts = null;
+ List<File> ts = null;
for (File file : dir.listFiles()) {
if (file.isDirectory()) {
- find_erl_files(suite, file);
+ find_erl_files(tests, file);
} else if (file.getName().endsWith(".erl")) {
if (ts == null) {
System.err.println("added.. " + dir);
- ts = new TestSuite(dir.getPath());
- suite.addTest(ts);
+ ts = new ArrayList<File>();
+ tests.put(dir, ts);
}
- ts.addTest(new TestRunFile(file));
+ ts.add(file);
}
}
}
-
}
View
16 src/test/java/erjang/TestCompileFile.java
@@ -21,25 +21,13 @@
import java.io.File;
-import erjang.beam.Compiler;
-
-import junit.framework.TestCase;
import junit.framework.TestResult;
+import erjang.beam.Compiler;
/**
*
*/
-public class TestCompileFile extends TestCase {
-
- private final File file;
-
- /**
- * @param file
- */
- public TestCompileFile(File file) {
- super(file.getName());
- this.file = file;
- }
+public class TestCompileFile extends AbstractErjangTestCase {
/* (non-Javadoc)
* @see java.lang.Object#toString()
View
7 src/test/java/erjang/TestRunFile.java
@@ -46,7 +46,7 @@
/**
*
*/
-public class TestRunFile extends TestCase {
+public class TestRunFile extends AbstractErjangTestCase {
static final String OTP_HOME = ErjangConfig.getString("erjang.otp.root");
static final String ERTS_VSN = ErjangConfig.getString("erjang.erts.version");
@@ -59,8 +59,6 @@
static final String RUN_WRAPPER_HOME = "src/test/erl";
static final String BEAM_DIR = "target/test-beam";
- private final File file;
-
final static File repoDir = new File("target/compiled");
final static DirClassRepo repo = new DirClassRepo(repoDir);
@@ -70,8 +68,7 @@
* @param file
*/
public TestRunFile(File file) {
- super(file.getName());
- this.file = file;
+ super(file);
String path1 = OTP_HOME + File.separator + "erts" + File.separator
+ "preloaded" + File.separator + "ebin";

0 comments on commit 9cee135

Please sign in to comment.