forked from trifork/erjang
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test suites: Preparing for proper support of Triq-like tests
- Loading branch information
Erik Søe Sørensen
committed
Jan 15, 2011
1 parent
0f5c7f2
commit 08fa26c
Showing
32 changed files
with
110 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters