Convert acceptance tests to kotlin
This commit is contained in:
parent
c2e4d76700
commit
053ca4852c
|
@ -1,10 +0,0 @@
|
||||||
package acceptance;
|
|
||||||
|
|
||||||
import fitnesse.junit.FitNesseRunner;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
@RunWith(FitNesseRunner.class)
|
|
||||||
@FitNesseRunner.Suite("TranscendentalLisp")
|
|
||||||
@FitNesseRunner.FitnesseDir("fitnesse")
|
|
||||||
@FitNesseRunner.OutputDir("fitnesse/fitnesse-results")
|
|
||||||
public class AcceptanceTest {}
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package acceptance
|
||||||
|
|
||||||
|
import fitnesse.junit.FitNesseRunner
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
@RunWith(FitNesseRunner::class)
|
||||||
|
@FitNesseRunner.Suite("TranscendentalLisp")
|
||||||
|
@FitNesseRunner.FitnesseDir("fitnesse")
|
||||||
|
@FitNesseRunner.OutputDir("fitnesse/fitnesse-results")
|
||||||
|
class AcceptanceTest
|
|
@ -1,76 +0,0 @@
|
||||||
package acceptance.fixture;
|
|
||||||
|
|
||||||
import application.LispMain;
|
|
||||||
import environment.RuntimeEnvironment;
|
|
||||||
import interpreter.LispInterpreter;
|
|
||||||
import interpreter.LispInterpreterBuilder;
|
|
||||||
import table.ExecutionContext;
|
|
||||||
import table.FunctionTable;
|
|
||||||
import util.Path;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
|
|
||||||
public class LispInterpreterFixture {
|
|
||||||
|
|
||||||
private static ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
||||||
private static ExecutionContext executionContext = ExecutionContext.INSTANCE;
|
|
||||||
private static RuntimeEnvironment environment = RuntimeEnvironment.INSTANCE;
|
|
||||||
private static LispInterpreter interpreter = null;
|
|
||||||
|
|
||||||
public static void resetInterpreter() {
|
|
||||||
cleanUp();
|
|
||||||
buildInterpreter();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void cleanUp() {
|
|
||||||
LispInterpreterBuilder.INSTANCE.reset();
|
|
||||||
FunctionTable.INSTANCE.resetFunctionTable();
|
|
||||||
executionContext.clearContext();
|
|
||||||
environment.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void buildInterpreter() {
|
|
||||||
LispInterpreterBuilder.INSTANCE.setOutput(new PrintStream(outputStream));
|
|
||||||
LispInterpreterBuilder.INSTANCE.setErrorOutput(new PrintStream(outputStream));
|
|
||||||
LispInterpreterBuilder.INSTANCE.setNotInteractive();
|
|
||||||
LispInterpreterBuilder.INSTANCE.setLanguageFileNames(LispMain.Companion.getLANGUAGE_FILE_NAMES());
|
|
||||||
// LispInterpreterBuilder.INSTANCE.setTerminationFunction(LispInterpreterFixture::terminate);
|
|
||||||
// LispInterpreterBuilder.INSTANCE.setErrorTerminationFunction(LispInterpreterFixture::terminateFromError);
|
|
||||||
|
|
||||||
interpreter = LispInterpreterBuilder.INSTANCE.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void terminate() {}
|
|
||||||
|
|
||||||
public static void terminateFromError() {
|
|
||||||
throw new RuntimeException("Error Termination");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String evaluateText(String input) {
|
|
||||||
environment.setInputName("fitnesse");
|
|
||||||
environment.setInput(new ByteArrayInputStream(input.getBytes()));
|
|
||||||
environment.setPath("");
|
|
||||||
|
|
||||||
return evaluate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String evaluateFile(String inputFile) throws FileNotFoundException {
|
|
||||||
environment.setInputName(inputFile);
|
|
||||||
environment.setInput(new FileInputStream(inputFile));
|
|
||||||
environment.setPath(Path.INSTANCE.getPathPrefix(inputFile));
|
|
||||||
|
|
||||||
return evaluate();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String evaluate() {
|
|
||||||
interpreter.interpret();
|
|
||||||
String output = outputStream.toString();
|
|
||||||
outputStream.reset();
|
|
||||||
|
|
||||||
return output.trim();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
package acceptance.fixture
|
||||||
|
|
||||||
|
import application.LispMain
|
||||||
|
import environment.RuntimeEnvironment
|
||||||
|
import interpreter.LispInterpreter
|
||||||
|
import interpreter.LispInterpreterBuilder
|
||||||
|
import table.ExecutionContext
|
||||||
|
import table.FunctionTable
|
||||||
|
import util.Path
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream
|
||||||
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.io.FileNotFoundException
|
||||||
|
import java.io.PrintStream
|
||||||
|
|
||||||
|
class LispInterpreterFixture {
|
||||||
|
|
||||||
|
fun evaluateText(input: String): String {
|
||||||
|
RuntimeEnvironment.inputName = "fitnesse"
|
||||||
|
RuntimeEnvironment.input = ByteArrayInputStream(input.toByteArray())
|
||||||
|
RuntimeEnvironment.path = ""
|
||||||
|
|
||||||
|
return evaluate()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(FileNotFoundException::class)
|
||||||
|
fun evaluateFile(inputFile: String): String {
|
||||||
|
RuntimeEnvironment.inputName = inputFile
|
||||||
|
RuntimeEnvironment.input = FileInputStream(inputFile)
|
||||||
|
RuntimeEnvironment.path = Path.getPathPrefix(inputFile)
|
||||||
|
|
||||||
|
return evaluate()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun evaluate(): String {
|
||||||
|
interpreter.interpret()
|
||||||
|
val output = outputStream.toString()
|
||||||
|
outputStream.reset()
|
||||||
|
|
||||||
|
return output.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
private val outputStream = ByteArrayOutputStream()
|
||||||
|
private lateinit var interpreter: LispInterpreter
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun resetInterpreter() {
|
||||||
|
cleanUp()
|
||||||
|
buildInterpreter()
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun cleanUp() {
|
||||||
|
LispInterpreterBuilder.reset()
|
||||||
|
FunctionTable.resetFunctionTable()
|
||||||
|
ExecutionContext.clearContext()
|
||||||
|
RuntimeEnvironment.reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildInterpreter() {
|
||||||
|
LispInterpreterBuilder.setOutput(PrintStream(outputStream))
|
||||||
|
LispInterpreterBuilder.setErrorOutput(PrintStream(outputStream))
|
||||||
|
LispInterpreterBuilder.setNotInteractive()
|
||||||
|
LispInterpreterBuilder.setLanguageFileNames(*LispMain.LANGUAGE_FILE_NAMES)
|
||||||
|
LispInterpreterBuilder.setTerminationFunction { }
|
||||||
|
LispInterpreterBuilder.setErrorTerminationFunction { throw RuntimeException("Error Termination") }
|
||||||
|
|
||||||
|
interpreter = LispInterpreterBuilder.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue