Skip to content

Commit

Permalink
Test suites: Preparing for proper support of Triq-like tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Søe Sørensen committed Jan 15, 2011
1 parent 0f5c7f2 commit 08fa26c
Show file tree
Hide file tree
Showing 32 changed files with 110 additions and 94 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@ classes
target
*.beam
src/main/java/erjang/beam/interpreter/Interpreter.java
src/test/java/erjang/*_TEST.java
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
83 changes: 0 additions & 83 deletions src/test/java/erjang/AbstractErjangTestCase.java
Expand Up @@ -14,9 +14,6 @@ public abstract class AbstractErjangTestCase extends TestCase {

protected File file;

public AbstractErjangTestCase() {
}

public AbstractErjangTestCase(File file) {
super(file.getName());
this.file = file;
Expand All @@ -31,84 +28,4 @@ public void setFile(File file) {
this.file = file;
this.setName(file.getName());
}

protected static String getClassContent(Class<? extends AbstractErjangTestCase> clazz, File file) {
StringBuffer s = new StringBuffer();
String name = getClassName(file);
String path = getPath(file);

s.append(getPackage());
s.append(getImports());
s.append(getClassStart(clazz, name));
s.append(getConstructor(name, path));
s.append(getSuite(name));
s.append(getClassEnd());

return s.toString();
}

protected static String getPackage() {
return "package erjang;\n\n";
}

protected static String getImports() {
StringBuffer s = new StringBuffer();

s.append("import junit.framework.TestSuite;\n");
s.append("import junit.framework.Test;\n\n");

return s.toString();
}

public static String getClassName(File file) {
String name = file.getName();
name = name.replace('.', '_');
name = name.replace('-', '_');

return name + "_TEST";
}

protected static String getPath(File file) {
String path = file.getAbsolutePath();

//Windows backslash hack...
path = path.replace("\\", "\\\\");

return path;
}

protected static String getClassStart(Class<? extends AbstractErjangTestCase> clazz, String name) {
return "public class " + name + " extends " + clazz.getName() + " {\n\n";
}

protected static String getConstructor(String name, String path) {
StringBuffer s = new StringBuffer();

s.append("\tpublic " + name + "() {\n");
s.append("\t\tsuper(\"" + path + "\");\n");
s.append("\t}\n\n");

return s.toString();
}

protected static String getSuite(String name) {
StringBuffer s = new StringBuffer();

//backup: generate as suite: will we need to group the tests somehow?
/*s.append("\tpublic static Test suite() {\n");
s.append("\t\tTestSuite ts = new TestSuite();\n");
s.append("\\ttts.addTest(new " + name + "());\n");
s.append("\t\treturn ts;\n");
s.append("\t}\n");*/

s.append("\tpublic static Test suite() {\n");
s.append("\t\treturn new " + name + "();\n");
s.append("\t}\n");

return s.toString();
}

protected static String getClassEnd() {
return "}";
}
}
12 changes: 5 additions & 7 deletions src/test/java/erjang/AllTests.java
Expand Up @@ -44,16 +44,14 @@ public static Test suite() {

TestSuite otpCompileSuite = new TestSuite("Compiling OTP");
//$JUnit-BEGIN$
Map<File, List<File>> testsOTP = new HashMap<File, List<File>>();
find_files(testsOTP, new File(OTP_HOME), ".beam");
buildTestHiearchie(testsOTP, otpCompileSuite, TestCompileFile.class);
//find_beam_files(otpCompileSuite, new File(OTP_HOME));
//$JUnit-END$
suite.addTest(otpCompileSuite);

TestSuite coverageRunSuite = new TestSuite("Coverage run tests");
//$JUnit-BEGIN$
Map<File, List<File>> testsErl = new HashMap<File, List<File>>();
find_files(testsErl, new File("src/test/erl"), ".erl");
find_files(testsErl, new File("src/test/erl/deterministic"), ".erl");
buildTestHiearchie(testsErl, coverageRunSuite, TestRunFile.class);
//$JUnit-END$
suite.addTest(coverageRunSuite);
Expand Down Expand Up @@ -109,16 +107,16 @@ public static void main(String[] args) {
generateTestClasses(args[0], testsOTP, TestCompileFile.class);

Map<File, List<File>> testsErl = new HashMap<File, List<File>>();
find_files(testsErl, new File("src/test/erl"), ".erl");
find_files(testsErl, new File("src/test/erl/deterministic"), ".erl");
generateTestClasses(args[0], testsErl, TestRunFile.class);
}

protected static void generateTestClasses(String path, Map<File, List<File>> tests,
Class<? extends AbstractErjangTestCase> clazz) {
for (File key : tests.keySet()) {
for (File sub : tests.get(key)) {
String name = AbstractErjangTestCase.getClassName(sub);
String content = AbstractErjangTestCase.getClassContent(clazz, sub);
String name = TestClassGenerator.classNameFor(sub);
String content = TestClassGenerator.generateClassSource(clazz, sub);
try {
File file = new File(path + "/" + name + ".java");

Expand Down
104 changes: 104 additions & 0 deletions src/test/java/erjang/TestClassGenerator.java
@@ -0,0 +1,104 @@
/**
* This file is part of Erjang - A JVM-based Erlang VM
*
* Copyright (c) 2009 by Trifork
*
* 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 erjang;

import java.io.File;

public abstract class TestClassGenerator {

protected static String generateClassSource(Class<? extends AbstractErjangTestCase> clazz, File file) {
StringBuffer s = new StringBuffer();
String name = classNameFor(file);
String path = getPath(file);

s.append(getPackage());
s.append(getImports());
s.append(getClassStart(clazz, name));
s.append(getConstructor(name, path));
s.append(getSuite(name));
s.append(getClassEnd());

return s.toString();
}

protected static String getPackage() {
return "package erjang;\n\n";
}

protected static String getImports() {
StringBuffer s = new StringBuffer();

s.append("import junit.framework.TestSuite;\n");
s.append("import junit.framework.Test;\n\n");

return s.toString();
}

public static String classNameFor(File file) {
String name = file.getName();
name = name.replace('.', '_');
name = name.replace('-', '_');

return name + "_TEST";
}

protected static String getPath(File file) {
String path = file.getAbsolutePath();

//Windows backslash hack...
path = path.replace("\\", "\\\\");

return path;
}

protected static String getClassStart(Class<? extends AbstractErjangTestCase> clazz, String name) {
return "public class " + name + " extends " + clazz.getName() + " {\n\n";
}

protected static String getConstructor(String name, String path) {
StringBuffer s = new StringBuffer();

s.append("\tpublic " + name + "() {\n");
s.append("\t\tsuper(\"" + path + "\");\n");
s.append("\t}\n\n");

return s.toString();
}

protected static String getSuite(String name) {
StringBuffer s = new StringBuffer();

//backup: generate as suite: will we need to group the tests somehow?
/*s.append("\tpublic static Test suite() {\n");
s.append("\t\tTestSuite ts = new TestSuite();\n");
s.append("\\ttts.addTest(new " + name + "());\n");
s.append("\t\treturn ts;\n");
s.append("\t}\n");*/

s.append("\tpublic static Test suite() {\n");
s.append("\t\treturn new " + name + "();\n");
s.append("\t}\n");

return s.toString();
}

protected static String getClassEnd() {
return "}";
}
}
4 changes: 0 additions & 4 deletions src/test/java/erjang/TestRunFile.java
Expand Up @@ -47,10 +47,6 @@ public class TestRunFile extends AbstractErjangTestCase {
static final String RUN_WRAPPER_HOME = "src/test/erl";
static final String BEAM_DIR = "target/test-beam";

public TestRunFile() {
super();
}

public TestRunFile(String name) {
super(name);
}
Expand Down

0 comments on commit 08fa26c

Please sign in to comment.