2011-01-25 06:23:18 +08:00
|
|
|
var path = require('path'),
|
|
|
|
sys = require('sys'),
|
|
|
|
assert = require('assert'),
|
2011-01-27 06:56:16 +08:00
|
|
|
fs = require('fs');
|
2011-01-25 06:23:18 +08:00
|
|
|
|
2011-02-08 00:22:14 +08:00
|
|
|
var carto = require('carto');
|
|
|
|
var tree = require('carto/tree');
|
2011-01-25 06:23:18 +08:00
|
|
|
var helper = require('./support/helper');
|
|
|
|
|
|
|
|
helper.files('rendering', 'mml', function(file) {
|
|
|
|
exports['test rendering ' + file] = function(beforeExit) {
|
2011-01-25 07:50:27 +08:00
|
|
|
var completed = false;
|
2011-01-26 06:12:45 +08:00
|
|
|
var renderResult;
|
2011-01-25 06:23:18 +08:00
|
|
|
|
|
|
|
helper.file(file, function(mml) {
|
2011-02-08 00:22:14 +08:00
|
|
|
new carto.Renderer({
|
2011-01-25 06:23:18 +08:00
|
|
|
paths: [ path.dirname(file) ],
|
|
|
|
data_dir: path.join(__dirname, '../data'),
|
|
|
|
local_data_dir: path.join(__dirname, 'rendering'),
|
|
|
|
filename: file
|
|
|
|
}).render(mml, function (err, output) {
|
|
|
|
if (err) {
|
2011-02-08 01:50:04 +08:00
|
|
|
if (Array.isArray(err)){
|
|
|
|
err.forEach(carto.writeError);
|
|
|
|
} else {
|
|
|
|
throw err;
|
|
|
|
}
|
2011-01-25 06:23:18 +08:00
|
|
|
} else {
|
2011-01-26 06:12:45 +08:00
|
|
|
renderResult = output;
|
2011-01-25 06:23:18 +08:00
|
|
|
var result = helper.resultFile(file);
|
2011-01-27 06:56:16 +08:00
|
|
|
helper.compareToXMLFile(result, output, function(err) {
|
|
|
|
completed = true;
|
|
|
|
if (err) {
|
|
|
|
console.warn(
|
|
|
|
helper.stylize("Failure", 'red') + ': '
|
|
|
|
+ helper.stylize(file, 'underline')
|
|
|
|
+ ' differs from expected result.');
|
|
|
|
helper.showDifferences(err);
|
|
|
|
throw '';
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
helper.removeAbsoluteImages,
|
|
|
|
helper.removeAbsoluteDatasources
|
|
|
|
]);
|
2011-01-25 06:23:18 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeExit(function() {
|
2011-01-26 06:12:45 +08:00
|
|
|
if (!completed && renderResult) {
|
2011-01-28 09:50:53 +08:00
|
|
|
console.warn(helper.stylize('renderer produced:', 'bold'));
|
|
|
|
console.warn(renderResult);
|
2011-01-26 06:12:45 +08:00
|
|
|
}
|
2011-01-26 07:14:40 +08:00
|
|
|
assert.ok(completed, 'Rendering finished.');
|
2011-01-25 06:23:18 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|