feat(xod-cli): integrate tabtests with xodc

This commit is contained in:
Victor Nakoryakov
2018-04-04 19:26:43 +03:00
parent 5b163f552d
commit 5fc6fdd026
3 changed files with 107 additions and 3 deletions

View File

@@ -20,6 +20,7 @@
"dependencies": {
"cli-color": "^1.1.0",
"docopt": "^0.6.2",
"fs-extra": "^4.0.2",
"hm-def": "^0.3.2",
"inquirer": "^3.2.0",
"ramda": "^0.24.1",
@@ -31,12 +32,13 @@
"xod-fs": "^0.19.4",
"xod-func-tools": "^0.19.2",
"xod-pm": "^0.19.4",
"xod-project": "^0.19.4"
"xod-project": "^0.19.4",
"xod-pm": "^0.19.4",
"xod-tabtest": "^0.19.2"
},
"devDependencies": {
"chai": "^4.1.2",
"child-process-promise": "^2.2.1",
"cpx": "^1.5.0",
"fs-extra": "^4.0.2"
"cpx": "^1.5.0"
}
}

View File

@@ -0,0 +1,95 @@
// xodc tabtest [--workspace=<dir>] <input> <path>
import path from 'path';
import os from 'os';
import * as R from 'ramda';
import fs from 'fs-extra';
import childProcess from 'child_process';
import { foldEither, allPromises } from 'xod-func-tools';
import { loadProject } from 'xod-fs';
import * as Tabtest from 'xod-tabtest';
import * as msg from './messageUtils';
import { getWorkspacePath } from './utils';
const bundledWorkspace = path.resolve(__dirname, '..');
const tabtestWorkspace = path.resolve(
__dirname,
'..',
'..',
'xod-tabtest',
'workspace'
);
const tabtestSources = path.resolve(
__dirname,
'..',
'..',
'xod-tabtest',
'cpp'
);
const catch2Sources = path.resolve(
__dirname,
'..',
'..',
'..',
'vendor',
'catch2'
);
const showErrorAndExit = err => {
msg.error(err);
process.exit(1);
};
const spawn = (cmd, args, opts) =>
new Promise((resolve, reject) => {
childProcess.spawn(cmd, args, opts).on('exit', code => {
if (code === 0) {
resolve();
} else {
reject(new Error(`${cmd} exited with code ${code}`));
}
});
});
const tapProgress = note => R.tap(() => msg.notice(note));
export default (input, patchPath, program) => {
const workspaces = [
getWorkspacePath(program.workspace),
tabtestWorkspace,
bundledWorkspace,
];
const outDir = path.join(os.tmpdir(), 'xod-tabtest');
const childProcessOpts = {
stdio: 'inherit',
shell: true,
cwd: outDir,
};
const saveOutFile = ([filename, content]) =>
fs.outputFile(path.join(outDir, filename), content);
msg.notice(`Preparing test directory: ${outDir} ...`);
fs
.ensureDir(outDir)
.then(tapProgress('Loading project...'))
.then(() => loadProject(workspaces, input))
.then(tapProgress('Generating C++ code...'))
.then(project => Tabtest.generateSuite(project, patchPath))
.then(foldEither(err => showErrorAndExit(err), R.identity))
.then(R.toPairs)
.then(tapProgress('Saving files...'))
.then(R.map(saveOutFile))
.then(R.append(fs.copy(tabtestSources, outDir)))
.then(R.append(fs.copy(catch2Sources, outDir)))
.then(allPromises)
.then(tapProgress('Compiling...'))
.then(() => spawn('make', [], childProcessOpts))
.then(tapProgress('Testing...'))
.then(() => spawn('make', ['test'], childProcessOpts))
.catch(showErrorAndExit);
};

View File

@@ -9,6 +9,7 @@ import pack from './xodc-pack';
import publish from './xodc-publish';
import transpile from './xodc-transpile';
import unpack from './xodc-unpack';
import tabtest from './xodc-tabtest';
const PM_SWAGGER_URL = 'https://pm.xod.io/swagger';
@@ -29,6 +30,7 @@ Usage:
xodc transpile [--output=<filename>] [--workspace=<dir>] <input> <patchPath>
xodc publish [--swagger=<swagger>] [--orgname=<orgname>] [<projectDir>]
xodc install [--swagger=<swagger>] [--workspace=<dir>] <libUri>
xodc tabtest [--workspace=<dir>] <input> <patchPath>
Commands:
pack Pack project directory into xodball.
@@ -36,6 +38,7 @@ Commands:
transpile Transpile project into device runtime.
publish Publish a new library version.
install Install the library into workspace.
tabtest Run tabular tests.
Options:
--output=<filename> Write result of transpilation into file.
@@ -61,6 +64,10 @@ const programs = {
),
install: o =>
install(o['--swagger'] || PM_SWAGGER_URL, o['<libUri>'], o['--workspace']),
tabtest: o =>
tabtest(o['<input>'], o['<patchPath>'], {
workspace: o['--workspace'],
}),
};
// Running command