2011-07-25 14:26:20 +08:00
|
|
|
var path = require('path'),
|
|
|
|
assert = require('assert'),
|
|
|
|
fs = require('fs');
|
|
|
|
|
|
|
|
var carto = require('../lib/carto');
|
|
|
|
var tree = require('../lib/carto/tree');
|
|
|
|
var helper = require('./support/helper');
|
|
|
|
|
2012-12-19 07:51:39 +08:00
|
|
|
describe('Error handling mml+mss', function() {
|
2011-07-25 14:26:20 +08:00
|
|
|
helper.files('errorhandling', 'mml', function(file) {
|
2012-05-03 00:56:38 +08:00
|
|
|
it('should handle errors in ' + path.basename(file), function(done) {
|
2011-07-25 14:26:20 +08:00
|
|
|
var completed = false;
|
|
|
|
var renderResult;
|
|
|
|
var mml = helper.mml(file);
|
2011-10-13 23:12:50 +08:00
|
|
|
try {
|
|
|
|
new carto.Renderer({
|
|
|
|
paths: [ path.dirname(file) ],
|
|
|
|
data_dir: path.join(__dirname, '../data'),
|
|
|
|
local_data_dir: path.join(__dirname, 'rendering'),
|
|
|
|
filename: file
|
|
|
|
}).render(mml, function (err) {
|
2012-11-30 03:36:39 +08:00
|
|
|
if (!err) {
|
|
|
|
console.warn("*** <--- WARNING invalid error handling test found (" + file + "): all error handling tests should throw errors!");
|
2012-12-19 08:02:44 +08:00
|
|
|
done();
|
2012-11-30 03:36:39 +08:00
|
|
|
} else {
|
|
|
|
var result = helper.resultFile(file);
|
|
|
|
var output = err.message;
|
|
|
|
// @TODO for some reason, fs.readFile includes an additional \n
|
|
|
|
// at the end of read files. Determine why.
|
|
|
|
fs.readFile(helper.resultFile(file), 'utf8', function(err, data) {
|
|
|
|
if (!err) assert.deepEqual(output, data.substr(0, data.length - 1));
|
2012-12-19 08:02:44 +08:00
|
|
|
done();
|
2012-11-30 03:36:39 +08:00
|
|
|
});
|
|
|
|
}
|
2011-10-13 23:12:50 +08:00
|
|
|
});
|
|
|
|
} catch(err) {
|
2011-07-25 14:26:20 +08:00
|
|
|
var result = helper.resultFile(file);
|
|
|
|
var output = err.message;
|
|
|
|
// @TODO for some reason, fs.readFile includes an additional \n
|
|
|
|
// at the end of read files. Determine why.
|
|
|
|
fs.readFile(helper.resultFile(file), 'utf8', function(err, data) {
|
2011-09-06 23:00:14 +08:00
|
|
|
if (!err) assert.deepEqual(output, data.substr(0, data.length - 1));
|
2012-12-19 08:02:44 +08:00
|
|
|
done();
|
2011-07-25 14:26:20 +08:00
|
|
|
});
|
2011-10-13 23:12:50 +08:00
|
|
|
}
|
2012-05-03 00:56:38 +08:00
|
|
|
});
|
|
|
|
});
|
2011-07-25 14:26:20 +08:00
|
|
|
});
|
2012-12-19 07:51:39 +08:00
|
|
|
|
|
|
|
describe('Error handling mss', function() {
|
|
|
|
helper.files('errorhandling', 'mss', function(file) {
|
|
|
|
it('should handle errors in ' + path.basename(file), function(done) {
|
|
|
|
var completed = false;
|
|
|
|
var renderResult;
|
|
|
|
console.log(file)
|
|
|
|
var mss = helper.mss(file);
|
|
|
|
try {
|
|
|
|
new carto.Renderer({
|
|
|
|
paths: [ path.dirname(file) ],
|
|
|
|
data_dir: path.join(__dirname, '../data'),
|
|
|
|
local_data_dir: path.join(__dirname, 'rendering'),
|
2012-12-19 08:24:14 +08:00
|
|
|
// note: we call basename here so that the expected error result
|
|
|
|
// will match if the style was loaded from mml
|
|
|
|
filename: path.basename(file)
|
2012-12-19 07:51:39 +08:00
|
|
|
}).renderMSS(mss, function (err) {
|
|
|
|
if (!err) {
|
|
|
|
console.warn("*** <--- WARNING invalid error handling test found (" + file + "): all error handling tests should throw errors!");
|
2012-12-19 08:02:44 +08:00
|
|
|
done();
|
|
|
|
} else {
|
2012-12-19 07:51:39 +08:00
|
|
|
var result = helper.resultFile(file);
|
|
|
|
var output = err.message;
|
|
|
|
// @TODO for some reason, fs.readFile includes an additional \n
|
|
|
|
// at the end of read files. Determine why.
|
|
|
|
fs.readFile(helper.resultFile(file), 'utf8', function(err, data) {
|
|
|
|
if (!err) assert.deepEqual(output, data.substr(0, data.length - 1));
|
2012-12-19 08:02:44 +08:00
|
|
|
done();
|
2012-12-19 07:51:39 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch(err) {
|
|
|
|
var result = helper.resultFile(file);
|
|
|
|
var output = err.message;
|
|
|
|
// @TODO for some reason, fs.readFile includes an additional \n
|
|
|
|
// at the end of read files. Determine why.
|
|
|
|
fs.readFile(helper.resultFile(file), 'utf8', function(err, data) {
|
|
|
|
if (!err) assert.deepEqual(output, data.substr(0, data.length - 1));
|
2012-12-19 08:02:44 +08:00
|
|
|
done();
|
2012-12-19 07:51:39 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|