End-to-end CLI tests

This commit is contained in:
Bán Dénes 2021-07-17 01:15:27 +02:00
parent 1f3ecb5c58
commit 4d88dac40a
15 changed files with 343 additions and 7 deletions

1
test/cli/basic/command Normal file
View file

@ -0,0 +1 @@
node src/cli.js test/fixtures/minimal.yaml

13
test/cli/basic/log Normal file
View file

@ -0,0 +1,13 @@
Ergogen v2.0.0 CLI
Interpreting format: YAML
Preprocessing input...
Calculating variables...
Parsing points...
Generating outlines...
Extruding cases...
Scaffolding PCBs...
Output would be empty, rerunning in debug mode...
Writing output to disk...
Done.

View file

@ -0,0 +1,7 @@
points:
zones:
matrix:
columns:
col: {}
rows:
row: {}

View file

@ -0,0 +1,98 @@
0
SECTION
2
HEADER
9
$INSUNITS
70
4
0
ENDSEC
0
SECTION
2
TABLES
0
TABLE
2
LTYPE
0
LTYPE
72
65
70
64
2
CONTINUOUS
3
______
73
0
40
0
0
ENDTAB
0
TABLE
2
LAYER
0
ENDTAB
0
ENDSEC
0
SECTION
2
ENTITIES
0
LINE
8
0
10
-9
20
9
11
9
21
9
0
LINE
8
0
10
9
20
9
11
9
21
-9
0
LINE
8
0
10
9
20
-9
11
-9
21
-9
0
LINE
8
0
10
-9
20
-9
11
-9
21
9
0
ENDSEC
0
EOF

View file

@ -0,0 +1,69 @@
{
"models": {
"export": {
"models": {
"matrix_col_row": {
"paths": {
"top": {
"type": "line",
"origin": [
-9,
9
],
"end": [
9,
9
]
},
"right": {
"type": "line",
"origin": [
9,
9
],
"end": [
9,
-9
]
},
"bottom": {
"type": "line",
"origin": [
9,
-9
],
"end": [
-9,
-9
]
},
"left": {
"type": "line",
"origin": [
-9,
-9
],
"end": [
-9,
9
]
}
},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
}
},
"units": "mm",
"origin": [
0,
0
]
}

View file

@ -0,0 +1 @@
<svg width="18mm" height="18mm" viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg"><g id="svgGroup" stroke-linecap="round" fill-rule="evenodd" font-size="9pt" stroke="#000" stroke-width="0.25mm" fill="none" style="stroke:#000;stroke-width:0.25mm;fill:none"><path d="M 0 0 L 18 0 L 18 18 L 0 18 L 0 0 Z" vector-effect="non-scaling-stroke"/></g></svg>

After

Width:  |  Height:  |  Size: 353 B

View file

@ -0,0 +1,34 @@
{
"matrix_col_row": {
"x": 0,
"y": 0,
"r": 0,
"meta": {
"shift": [
0,
0
],
"rotate": 0,
"padding": 19,
"width": 1,
"height": 1,
"skip": false,
"asym": "both",
"name": "matrix_col_row",
"colrow": "col_row",
"col": {
"stagger": 0,
"spread": 0,
"rotate": 0,
"origin": [
0,
0
],
"rows": {},
"key": {},
"name": "col"
},
"row": "row"
}
}
}

View file

@ -0,0 +1,3 @@
points.zones.matrix:
columns.col: {}
rows.row: {}

View file

@ -0,0 +1,5 @@
{
"u": 19,
"cx": 18,
"cy": 17
}

View file

@ -0,0 +1 @@
node src/cli.js

View file

@ -0,0 +1 @@
Usage: ergogen <config_file> [options]

View file

@ -32,6 +32,7 @@ const cap = s => s.charAt(0).toUpperCase() + s.slice(1)
const test = function(input_path) {
this.timeout(120000)
this.slow(120000)
title = path.basename(input_path, '.yaml').split('_').join(' ')
it(title, async function() {
const input = yaml.load(fs.readFileSync(input_path).toString())
@ -100,3 +101,49 @@ 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)
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')) {
describe('CLI', function() {
this.timeout(120000)
this.slow(120000)
for (const t of glob.sync(path.join(__dirname, 'cli/*'))) {
it(cap(path.basename(t).split('_').join(' ')), function() {
const command = read(t, 'command')
const output_path = exists(t, 'path') ? read(t, 'path') : 'output'
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>')
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)
} else {
const ref_error = read(t, 'error').replace(version_regex, '<version>')
try {
execSync(command, {stdio: 'pipe'})
throw 'should_have_thrown'
} catch (ex) {
if (ex === 'should_have_thrown') {
throw new Error('This command should have thrown!')
}
const actual_error = ex.stderr.toString().replace(version_regex, '<version>')
actual_error.should.equal(ref_error)
}
}
})
}
})
}

View file

@ -13,6 +13,9 @@ const kle = load('atreus_kle.json')
describe('Interface', function() {
this.timeout(120000)
this.slow(120000)
it('debug', async function() {
// to check whether the output has "private" exports
const underscore = obj => {