fix race condition in specificity tests and change expected result so all specificity tests now pass

This commit is contained in:
Dane Springmeyer 2012-12-21 16:29:59 -08:00
parent c707188ed5
commit bd17eed9f5
3 changed files with 18 additions and 19 deletions

View File

@ -33,8 +33,21 @@ helper.files('specificity', 'mss', function(file) {
var mss = tree.toList({});
mss = helper.makePlain(mss, cleanupItem);
helper.compareToFile(mss, file, helper.resultFile(file));
var json = JSON.parse(fs.readFileSync(helper.resultFile(file)));
var actual = file.replace(path.extname(file),'') + '-actual.json';
var expected = file.replace(path.extname(file),'') + '-expected.json';
try {
assert.deepEqual(mss, json);
// cleanup any actual renders that no longer fail
try {
fs.unlinkSync(actual);
fs.unlinkSync(expected);
} catch (err) {}
} catch (err) {
fs.writeFileSync(actual,JSON.stringify(mss,null,4));
fs.writeFileSync(expected,JSON.stringify(json,null,4));
throw new Error('failed: ' + actual + ' not equal to expected: ' + expected);
}
done();
});
});

View File

@ -1,6 +1,6 @@
[
{"elements":["#world"],"filters":["OBJECTID=12"],"specificity":[1,0,1,131]},
{"elements":["#world"],"filters":["NET_INFLOW>-10000"],"specificity":[1,0,1,83]},
{"elements":["#world"],"filters":["NET_INFLOW>-30000"],"specificity":[1,0,1,35]},
{"elements":["#world"],"filters":["[OBJECTID]=12"],"specificity":[1,0,1,131]},
{"elements":["#world"],"filters":["[NET_INFLOW]>-10000"],"specificity":[1,0,1,83]},
{"elements":["#world"],"filters":["[NET_INFLOW]>-30000"],"specificity":[1,0,1,35]},
{"elements":["#world"],"specificity":[1,0,0,0]}
]

View File

@ -70,20 +70,6 @@ exports.makePlain = function(obj, fn) {
return JSON.parse(JSON.stringify(obj, fn));
};
exports.compareToFile = function(value, originalFile, resultFile) {
helper.json(resultFile, function(json) {
try {
assert.deepEqual(value, json);
} catch (e) {
console.warn(helper.stylize('Failure', 'red')
+ ': ' + helper.stylize(originalFile, 'underline')
+ ' differs from expected result.');
helper.showDifferences(e, helper.formatJSON);
throw '';
}
});
};
exports.parseXML = function(xml, callback) {
var parser = sax.parser(true);
var i = 0;