osrm-backend/features/step_definitions/options.js

99 lines
3.3 KiB
JavaScript
Raw Normal View History

'use strict';
const assert = require('assert');
const fs = require('fs');
2016-03-04 15:11:05 -05:00
module.exports = function () {
this.resetOptionsOutput = () => {
this.stdout = null;
this.stderr = null;
this.exitCode = null;
this.termSignal = null;
};
this.runAndSafeOutput = (binary, options, callback) => {
return this.runBin(binary, this.expandOptions(options), this.environment, (err, stdout, stderr) => {
this.stdout = stdout;
this.stderr = stderr;
this.exitCode = err && err.code || 0;
this.termSignal = err && err.signal || '';
callback(err);
2016-03-04 15:11:05 -05:00
});
};
this.When(/^I run "osrm\-routed\s?(.*?)"$/, { timeout: this.TIMEOUT }, (options, callback) => {
this.runAndSafeOutput('osrm-routed', options, callback);
2016-03-04 15:11:05 -05:00
});
2017-03-11 03:26:12 -05:00
this.When(/^I run "osrm\-(extract|contract|partition|customize)\s?(.*?)"$/, (binary, options, callback) => {
const stamp = this.processedCacheFile + '.stamp_' + binary;
this.runAndSafeOutput('osrm-' + binary, options, (err) => {
if (err) return callback(err);
fs.writeFile(stamp, 'ok', callback);
});
2016-03-04 15:11:05 -05:00
});
2017-03-11 03:26:12 -05:00
this.When(/^I try to run "(osrm\-[a-z]+)\s?(.*?)"$/, (binary, options, callback) => {
this.runAndSafeOutput(binary, options, () => { callback(); });
2016-03-04 15:11:05 -05:00
});
this.When(/^I run "osrm\-datastore\s?(.*?)"(?: with input "([^"]*)")?$/, (options, input, callback) => {
let child = this.runAndSafeOutput('osrm-datastore', options, callback);
if (input !== undefined)
child.stdin.write(input);
2016-03-04 15:11:05 -05:00
});
this.Then(/^it should exit successfully$/, () => {
assert.equal(this.exitCode, 0);
assert.equal(this.termSignal, '');
2016-03-04 15:11:05 -05:00
});
this.Then(/^it should exit with an error$/, () => {
assert.ok(this.exitCode !== 0 || this.termSignal);
});
2017-03-12 14:19:57 -04:00
this.Then(/^stdout should( not)? contain "(.*?)"$/, (not, str) => {
const contains = this.stdout.indexOf(str) > -1;
assert.ok(typeof not === 'undefined' ? contains : !contains);
2016-03-04 15:11:05 -05:00
});
2016-12-22 17:17:59 -05:00
this.Then(/^stderr should( not)? contain "(.*?)"$/, (not, str) => {
const contains = this.stderr.indexOf(str) > -1;
assert.ok(typeof not === 'undefined' ? contains : !contains);
2016-03-04 15:11:05 -05:00
});
this.Then(/^stdout should contain \/(.*)\/$/, (regexStr) => {
const re = new RegExp(regexStr);
2016-03-04 15:11:05 -05:00
assert.ok(this.stdout.match(re));
});
this.Then(/^stderr should contain \/(.*)\/$/, (regexStr) => {
const re = new RegExp(regexStr);
2016-03-04 15:11:05 -05:00
assert.ok(this.stdout.match(re));
});
this.Then(/^stdout should be empty$/, () => {
assert.equal(this.stdout.trim(), '');
});
this.Then(/^stderr should be empty$/, () => {
assert.equal(this.stderr.trim(), '');
});
this.Then(/^stdout should contain (\d+) lines?$/, (lines) => {
assert.equal(this.stdout.split('\n').length - 1, parseInt(lines));
});
this.Then(/^stderr should contain (\d+) lines?$/, (lines) => {
assert.equal(this.stderr.split('\n').length - 1, parseInt(lines));
});
2016-03-04 15:11:05 -05:00
this.Given(/^the query options$/, (table, callback) => {
2016-03-29 13:35:56 -04:00
table.raw().forEach(tuple => {
2016-03-29 13:39:48 -04:00
this.queryParams[tuple[0]] = tuple[1];
2016-03-04 15:11:05 -05:00
});
callback();
});
};