forked from sq/JSIL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_runner.html
157 lines (126 loc) · 4.38 KB
/
test_runner.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html>
<head>
<title>JSIL Test Runner</title>
<style>
body, button, input {
font-family: Calibri, Tahoma, Verdana, sans-serif;
font-size: 14pt;
}
label {
font-weight: bold;
display: inline-block;
width: 10em;
}
input[type="text"] {
width: 20em;
}
button {
width: 10em;
}
</style>
</head>
<body onload="onLoadFixture();">
<script>
var jsilConfig = {
libraryRoot: "Libraries/"
};
</script>
<script src="Libraries/JSIL.js" type="text/javascript"></script>
<label for="scriptname">Test Script To Run:</label> <input type="text" name="scriptname" id="scriptname" value="Tests/SimpleTestCases/If.cs.out"></input><br>
<button id="runscript" name="runscript">Run</button>
<hr>
<h3>Log</h3>
<div id="log">
</div>
<script type="text/javascript">
var _started = Date.now();
var scriptAlreadyRan = false;
function print (text) {
console.log(text);
}
function timeout (t) {
// no-op
}
function elapsed (t) {
return Date.now() - _started;
}
function runScript () {
if (scriptAlreadyRan) {
setTimeout(function () {
var newHash = "#" + document.getElementById("scriptname").value;
var newUrl = window.location.protocol +
"//" +
window.location.host +
window.location.pathname +
"?autoRun" +
newHash;
if (window.location.href === newUrl)
window.location.reload(true);
else
window.location.replace(newUrl);
}, 1);
return;
}
scriptAlreadyRan = true;
document.getElementById("runscript").disabled = true;
var scriptname = document.getElementById("scriptname").value;
window.location.hash = "#" + scriptname;
setTimeout(function () {
contentManifest["TestRunner"] = [
["Script", scriptname]
];
onLoad();
document.getElementById("runscript").disabled = false;
}, 25);
}
function runMain () {
JSIL.Host.logWriteLine("// Test output begins here //");
var elapsed = runTestCase(function () { }, Date.now);
JSIL.Host.logWriteLine("// Test output ends here //");
JSIL.Host.logWriteLine("// Test completed in " + (elapsed / 1000) + " second(s)");
}
var lastHash = null;
function checkHash () {
var currentHash = null;
if ((typeof (window.location.hash) === "string") && (window.location.hash.length > 1)) {
currentHash = window.location.hash.substr(1);
}
if (currentHash !== lastHash) {
lastHash = currentHash;
document.getElementById("scriptname").value = currentHash;
}
}
function onLoadFixture () {
var button = document.getElementById("runscript");
checkHash();
setInterval(checkHash, 100);
button.removeAttribute("disabled");
button.addEventListener("click", runScript, true);
if (window.location.search.indexOf("autoRun") >= 0) {
window.setTimeout(runScript, 25);
}
}
// UGH
JSIL.Shell = {};
JSIL.Shell.TestPrologue = function (timeoutDuration, assemblyName, typeName, methodName, args, throwOnUnimplementedExternals) {
return function runTestCase () {
JSIL.ThrowOnUnimplementedExternals = throwOnUnimplementedExternals;
var started = Date.now();
var testAssembly = JSIL.GetAssembly(assemblyName, true);
if (!testAssembly)
throw new Error("No assembly named '" + assemblyName + "'");
var parsedTypeName = JSIL.ParseTypeName(typeName);
var testType = JSIL.GetTypeInternal(parsedTypeName, testAssembly, true);
var testTypePublicInterface = testType.__PublicInterface__;
var testMethod = testTypePublicInterface[methodName];
if (!testMethod)
throw new Error("No method named '" + methodName + "'");
testMethod.call(testTypePublicInterface, args);
var ended = Date.now();
return (ended - started);
};
};
</script>
</body>
</html>