Skip to content

Instantly share code, notes, and snippets.

@samwhitehall
Created April 19, 2012 14:29
Show Gist options
  • Save samwhitehall/eddd151c5d7dd9cea50b to your computer and use it in GitHub Desktop.
Save samwhitehall/eddd151c5d7dd9cea50b to your computer and use it in GitHub Desktop.
Test Case Convertor
package tests;
import java.io.*;
public class TestScriptGenerator {
public int testCount = 0;
public FileWriter currentTestScript;
public static void main(String[] args) {
TestScriptGenerator tester = new TestScriptGenerator();
tester.testCount = 0;
try {
tester.currentTestScript = new FileWriter("tests/unit_test.gunit");
tester.currentTestScript.write("gunit Niklaus;\n\nprog:");
tester.traverse( new File(args[0]) );
} catch (IOException e) {
e.printStackTrace();
}
}
public void traverse(File dir) throws IOException {
for (File child : dir.listFiles()) {
// Ignore the self and parent aliases.
if (".".equals(child.getName()) || "..".equals(child.getName()) || child.getName().equals(".DS_Store")) {
continue;
}
// If we find a directory, how about we create a new script and add its test cases
if (child.isDirectory()) {
traverse(child);
continue;
}
// must be a non-folder file, ie: test case, add to test script
addToTestScript(child);
}
}
public void addToTestScript(File testCase) throws IOException {
BufferedReader fileInput = new BufferedReader(new FileReader(testCase));
currentTestScript.append("\n\n");
currentTestScript.append("/* test" + ++testCount + "\t\t" + testCase.getName() + " */\n<<\n");
String line = null;
while ((line = fileInput.readLine()) != null){
currentTestScript.append(line + "\n");
}
if (testCase.getName().contains("FAIL")) {
currentTestScript.append(">> FAIL");
} else {
currentTestScript.append(">> OK");
}
currentTestScript.flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment