Skip to content

Commit

Permalink
Fix a number of ECMA-5-isms in the test runner
Browse files Browse the repository at this point in the history
We do still support IE7/8.

Also removes some non-CodeMirror-code-style things like left-aligned
commas and semicolons.
  • Loading branch information
marijnh committed Sep 7, 2012
1 parent fafa9d2 commit cab9417
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
24 changes: 14 additions & 10 deletions test/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ var tests = [], debug = null, debugUsed = new Array(), allNames = [];

function Failure(why) {this.message = why;}

function indexOf(collection, elt) {
if (collection.indexOf) return collection.indexOf(elt);
for (var i = 0, e = collection.length; i < e; ++i)
if (collection[i] == elt) return i;
return -1;
}

function test(name, run, expectedFail) {
// Force unique names
var originalName = name;
var i = 2; // Second function would be NAME_2
while(allNames.indexOf(name) !== -1){
while (indexOf(allNames, name) !== -1){
i++;
name = originalName + "_" + i;
}
Expand All @@ -32,7 +39,7 @@ function testCM(name, run, opts, expectedFail) {

function runTests(callback) {
if (debug) {
if (debug.indexOf("verbose") === 0) {
if (indexOf(debug, "verbose") === 0) {
verbose = true;
debug.splice(0, 1);
}
Expand All @@ -50,24 +57,21 @@ function runTests(callback) {
running = false;
return callback("done");
}
var test = tests[i]
, expFail = test.expectedFail
, startTime = Date.now()
;
var test = tests[i], expFail = test.expectedFail, startTime = +new Date;
if (debug !== null) {
var debugIndex = debug.indexOf(test.name);
var debugIndex = indexOf(debug, test.name);
if (debugIndex !== -1) {
// Remove from array for reporting incorrect tests later
debug.splice(debugIndex, 1);
} else {
var wildcardName = test.name.split("_").shift() + "_*";
debugIndex = debug.indexOf(wildcardName);
debugIndex = indexOf(debug, wildcardName);
if (debugIndex !== -1) {
// Remove from array for reporting incorrect tests later
debug.splice(debugIndex, 1);
debugUsed.push(wildcardName);
} else {
debugIndex = debugUsed.indexOf(wildcardName);
debugIndex = indexOf(debugUsed, wildcardName);
if (debugIndex !== -1) {
totalTests++;
} else {
Expand All @@ -87,7 +91,7 @@ function runTests(callback) {
}
if (!quit) { // Run next test
var delay = 0;
totalTime += (Date.now() - startTime);
totalTime += (+new Date) - startTime;
if (totalTime > 500){
totalTime = 0;
delay = 50;
Expand Down
27 changes: 13 additions & 14 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,24 @@ <h1>CodeMirror: Test Suite</h1>
window.onload = function() {
runHarness();
};
window.addEventListener('hashchange', function(){
CodeMirror.connect(window, 'hashchange', function(){
runHarness();
});

function esc(str) {
return str.replace(/[<&]/, function(ch) { return ch == "<" ? "&lt;" : "&amp;"; });
}

var output = document.getElementById("output")
, progress = document.getElementById("progress")
, progressRan = document.getElementById("progress_ran").childNodes[0]
, progressTotal = document.getElementById("progress_total").childNodes[0];
var count = 0
, failed = 0
, bad = ""
, running = false // Flag that states tests are running
, quit = false // Flag to quit tests ASAP
, verbose = false // Adds message for *every* test to output
;
var output = document.getElementById("output"),
progress = document.getElementById("progress"),
progressRan = document.getElementById("progress_ran").childNodes[0],
progressTotal = document.getElementById("progress_total").childNodes[0];
var count = 0,
failed = 0,
bad = "",
running = false, // Flag that states tests are running
quit = false, // Flag to quit tests ASAP
verbose = false; // Adds message for *every* test to output

function runHarness(){
if (running) {
Expand Down Expand Up @@ -96,12 +95,12 @@ <h1>CodeMirror: Test Suite</h1>
if (!message) throw("must provide message");
var status = document.getElementById("status").childNodes[0];
status.nodeValue = message;
status.parentNode.setAttribute("class", className);
status.parentNode.className = className;
}
function addOutput(name, className, code){
var newOutput = document.createElement("dl");
var newTitle = document.createElement("dt");
newTitle.setAttribute("class", className);
newTitle.className = className;
newTitle.appendChild(document.createTextNode(name));
newOutput.appendChild(newTitle);
var newMessage = document.createElement("dd");
Expand Down

0 comments on commit cab9417

Please sign in to comment.