forked from sq/JSIL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_runner.html
209 lines (165 loc) · 5.95 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!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 search = "?autoRun";
if (window.location.search.length > 0) {
if (window.location.search.indexOf("autoRun") >= 0) {
search = window.location.search;
} else {
search = window.location.search + "&autoRun"
}
}
var newUrl = window.location.protocol +
"//" +
window.location.host +
window.location.pathname +
search +
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 () {
var scriptnames = scriptname.split(";");
contentManifest["TestRunner"] = [];
for (var i=0; i<scriptnames.length; i++)
contentManifest["TestRunner"].push(["Script", scriptnames[i]]);
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 loadDlls (shouldAutoRun) {
var regex = /dll=([^&]*)/g;
var dllsToLoad = 0;
var doneLoadingDlls = function () {
if (shouldAutoRun)
window.setTimeout(runScript, 25);
};
while (match = regex.exec(window.location.search)) {
var dllPath = match[1].trim();
if (dllPath.length) {
dllsToLoad += 1;
var elt = document.createElement("script");
elt.addEventListener("load", function dllLoaded () {
JSIL.EndLoadNativeLibrary(dllPath);
console.log("Loaded DLL " + this.src);
dllsToLoad -= 1;
if (dllsToLoad == 0)
doneLoadingDlls();
}, true);
JSIL.BeginLoadNativeLibrary(dllPath);
elt.src = dllPath;
document.querySelector("body").appendChild(elt);
}
}
if (dllsToLoad == 0)
doneLoadingDlls();
}
function onLoadFixture () {
var button = document.getElementById("runscript");
checkHash();
setInterval(checkHash, 100);
button.removeAttribute("disabled");
button.addEventListener("click", runScript, true);
var shouldAutoRun = window.location.search.indexOf("autoRun") >= 0;
if (window.location.search.indexOf("dll=") >= 0) {
loadDlls(shouldAutoRun);
} else if (shouldAutoRun) {
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>