Complete CLI testing
This commit is contained in:
parent
4d88dac40a
commit
4105718ec6
41 changed files with 1384 additions and 7 deletions
|
@ -103,33 +103,43 @@ if (what) {
|
|||
}
|
||||
|
||||
// End-to-end tests to actually drive the CLI as well
|
||||
// --what filter is 'cli'
|
||||
// --dump is meaningless (just use the CLI itself)
|
||||
// --what filter is the same as above ('cli', or 'cli/prefix')
|
||||
// --dump saves the log, as well as prevents the output from being deleted
|
||||
|
||||
const read = (d, p) => fs.readFileSync(path.join(d, p)).toString()
|
||||
const exists = (d, p) => fs.existsSync(path.join(d, p))
|
||||
const { execSync } = require('child_process')
|
||||
const dircompare = require('dir-compare')
|
||||
|
||||
if (!what || what.includes('cli')) {
|
||||
const cli_what = what ? what.filter(w => w.startsWith('cli')) : ['cli']
|
||||
|
||||
for (let w of cli_what) {
|
||||
if (!w.includes('/')) w += '/'
|
||||
if (!w.endsWith('*')) w += '*'
|
||||
describe('CLI', function() {
|
||||
this.timeout(120000)
|
||||
this.slow(120000)
|
||||
for (const t of glob.sync(path.join(__dirname, 'cli/*'))) {
|
||||
for (const t of glob.sync(path.join(__dirname, w))) {
|
||||
it(cap(path.basename(t).split('_').join(' ')), function() {
|
||||
const command = read(t, 'command')
|
||||
const output_path = exists(t, 'path') ? read(t, 'path') : 'output'
|
||||
fs.removeSync(output_path)
|
||||
const version_regex = /\bv\d+\.\d+\.\d+\b/
|
||||
// correct execution
|
||||
if (exists(t, 'log')) {
|
||||
const ref_log = read(t, 'log').replace(version_regex, '<version>')
|
||||
const actual_log = execSync(command).toString().replace(version_regex, '<version>')
|
||||
if (dump) {
|
||||
fs.writeFileSync(path.join(t, 'log'), actual_log)
|
||||
}
|
||||
actual_log.should.equal(ref_log)
|
||||
const comp_res = dircompare.compareSync(output_path, path.join(t, 'reference'), {
|
||||
compareContent: true
|
||||
})
|
||||
comp_res.same.should.be.true
|
||||
fs.removeSync(output_path)
|
||||
if (!dump) {
|
||||
fs.removeSync(output_path)
|
||||
}
|
||||
} else {
|
||||
const ref_error = read(t, 'error').replace(version_regex, '<version>')
|
||||
try {
|
||||
|
@ -140,7 +150,10 @@ if (!what || what.includes('cli')) {
|
|||
throw new Error('This command should have thrown!')
|
||||
}
|
||||
const actual_error = ex.stderr.toString().replace(version_regex, '<version>')
|
||||
actual_error.should.equal(ref_error)
|
||||
if (dump) {
|
||||
fs.writeFileSync(path.join(t, 'error'), actual_error)
|
||||
}
|
||||
actual_error.includes(ref_error).should.be.true
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue