mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2025-01-03 05:44:10 -08:00
Refactoring JUnit emulation
This commit is contained in:
parent
18fd80be56
commit
231c5a43ee
|
@ -2,23 +2,64 @@ currentTestReportBody = null;
|
||||||
currentTimeSpent = 0;
|
currentTimeSpent = 0;
|
||||||
totalTimeSpent = 0;
|
totalTimeSpent = 0;
|
||||||
currentMethodCount = 0;
|
currentMethodCount = 0;
|
||||||
|
currentStatusCell = null;
|
||||||
|
currentExceptionCell = null;
|
||||||
|
currentTimeCell = null;
|
||||||
|
currentStartTime = 0;
|
||||||
|
currentExpectedExceptions = [];
|
||||||
|
currentFrame = null;
|
||||||
|
|
||||||
runTestCase = function(instance, methodName, realMethodName, expectedExceptions) {
|
window.addEventListener("message", function(event) {
|
||||||
|
endTime = new Date().getTime();
|
||||||
|
var message = JSON.parse(event.data);
|
||||||
|
if (message.status == "ok") {
|
||||||
|
if (currentExpectedExceptions.length > 0) {
|
||||||
|
currentStatusCell.appendChild(document.createTextNode("expected exception not thrown"));
|
||||||
|
currentStatusCell.style.color = 'yellow';
|
||||||
|
} else {
|
||||||
|
currentStatusCell.appendChild(document.createTextNode("ok"));
|
||||||
|
currentStatusCell.style.color = 'green';
|
||||||
|
}
|
||||||
|
} else if (message.status == "exception") {
|
||||||
|
if (isExpectedException(e)) {
|
||||||
|
currentStatusCell.appendChild(document.createTextNode("ok"));
|
||||||
|
currentStatusCell.style.color = 'green';
|
||||||
|
} else {
|
||||||
|
currentStatusCell.appendChild(document.createTextNode("unexpected exception"));
|
||||||
|
var exceptionText = document.createElement("pre");
|
||||||
|
exceptionText.appendChild(document.createTextNode(e.stack));
|
||||||
|
currentExceptionCell.appendChild(exceptionText);
|
||||||
|
currentStatusCell.style.color = 'red';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++currentMethodCount;
|
||||||
|
var timeSpent = (endTime - currentStartTime) / 1000;
|
||||||
|
currentTimeSpent += timeSpent;
|
||||||
|
currentTimeCell.appendChild(document.createTextNode(timeSpent.toFixed(3)));
|
||||||
|
document.body.removeChild(currentFrame);
|
||||||
|
}, false);
|
||||||
|
|
||||||
|
runTestCase = function(methodName, path, expectedExceptions) {
|
||||||
var row = document.createElement("tr");
|
var row = document.createElement("tr");
|
||||||
currentTestReportBody.appendChild(row);
|
currentTestReportBody.appendChild(row);
|
||||||
var nameCell = document.createElement("td");
|
var nameCell = document.createElement("td");
|
||||||
row.appendChild(nameCell);
|
row.appendChild(nameCell);
|
||||||
nameCell.appendChild(document.createTextNode(methodName));
|
nameCell.appendChild(document.createTextNode(methodName));
|
||||||
var statusCell = document.createElement("td");
|
currentStatusCell = document.createElement("td");
|
||||||
row.appendChild(statusCell);
|
row.appendChild(currentStatusCell);
|
||||||
var exceptionCell = document.createElement("td");
|
currentExceptionCell = document.createElement("td");
|
||||||
row.appendChild(exceptionCell);
|
row.appendChild(currentExceptionCell);
|
||||||
var timeCell = document.createElement("td");
|
currentTimeCell = document.createElement("td");
|
||||||
row.appendChild(timeCell);
|
row.appendChild(currentTimeCell);
|
||||||
var startTime = new Date().getTime();
|
currentStartTime = new Date().getTime();
|
||||||
var endTime;
|
currentExpectedExceptions = expectedExceptions;
|
||||||
try {
|
var frame = document.createElement("iframe");
|
||||||
instance[realMethodName]();
|
cirremtFrame = frame;
|
||||||
|
document.body.appendChild(frame);
|
||||||
|
var frameDoc = frame.contentWindow.document;
|
||||||
|
var frameScript = frameDoc.createElement("script");
|
||||||
|
frameScript.src = path;
|
||||||
|
frameDoc.body.appendChild(frameScript);
|
||||||
endTime = new Date().getTime();
|
endTime = new Date().getTime();
|
||||||
if (expectedExceptions.length > 0) {
|
if (expectedExceptions.length > 0) {
|
||||||
statusCell.appendChild(document.createTextNode("expected exception not thrown"));
|
statusCell.appendChild(document.createTextNode("expected exception not thrown"));
|
||||||
|
@ -46,10 +87,10 @@ runTestCase = function(instance, methodName, realMethodName, expectedExceptions)
|
||||||
timeCell.appendChild(document.createTextNode(timeSpent.toFixed(3)));
|
timeCell.appendChild(document.createTextNode(timeSpent.toFixed(3)));
|
||||||
}
|
}
|
||||||
|
|
||||||
isExpectedException = function(e, expectedExceptions) {
|
isExpectedException = function(e) {
|
||||||
if (e.$javaException !== undefined) {
|
if (e.javaException !== undefined) {
|
||||||
for (var i = 0; i < expectedExceptions.length; ++i) {
|
for (var i = 0; i < currentExpectedExceptions.length; ++i) {
|
||||||
if (expectedExceptions[i] === e.$javaException.$class) {
|
if (currentExpectedExceptions[i] === e.javaException) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
border: 2px solid black;
|
||||||
|
margin: 2em 1em 2em 1em;
|
||||||
|
}
|
||||||
|
table td, table th {
|
||||||
|
border: 1px solid gray;
|
||||||
|
padding: 0.1em 0.5em 0.2em 0.5em;
|
||||||
|
}
|
||||||
|
table thead, table tfoot {
|
||||||
|
border: 2px solid black;
|
||||||
|
}
|
||||||
|
iframe {
|
||||||
|
with: 1px;
|
||||||
|
height: 1px;
|
||||||
|
padding: 0px;
|
||||||
|
margin: 0px;
|
||||||
|
border-style: none;
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>TeaVM JUnit tests</title>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
|
||||||
|
<title>TeaVM JUnit tests</title>
|
||||||
|
<link rel="stylesheet" href="junit.css" type="text/css"/>
|
||||||
|
<script type="text/javascript" src="tests.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript">
|
||||||
|
function runTests() {
|
||||||
|
document.getElementById("start-button").style.display = "none";
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<button id="start-button" onclick="runTests()">Run tests</button>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user