Complete CLI testing

This commit is contained in:
Bán Dénes 2021-07-17 15:23:19 +02:00
parent 4d88dac40a
commit 4105718ec6
41 changed files with 1384 additions and 7 deletions

View file

@ -0,0 +1 @@
'bad input'

View file

@ -0,0 +1 @@
node src/cli.js test/cli/bad_input/bad.yaml

1
test/cli/bad_input/error Normal file
View file

@ -0,0 +1 @@
Error: Input doesn't resolve into an object!

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

@ -0,0 +1 @@
node src/cli.js test/fixtures/big.yaml --debug --clean

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

@ -0,0 +1,13 @@
Ergogen <version> CLI (Debug Mode)
Interpreting format: YAML
Preprocessing input...
Calculating variables...
Parsing points...
Generating outlines...
Extruding cases...
Scaffolding PCBs...
Cleaning output folder...
Writing output to disk...
Done.

View file

@ -0,0 +1,33 @@
units:
a: 28 + u
points:
zones:
matrix:
columns:
col: {}
rows:
row: {}
outlines:
exports:
export:
-
type: keys
side: left
size: 18
_export:
-
type: keys
side: left
size: 18
cases:
export:
-
name: export
extrude: 1
_export:
-
name: export
extrude: 1
pcbs:
export: {}
_export: {}

View file

@ -0,0 +1,36 @@
function export_outline_fn(){
return new CSG.Path2D([[-9,-9],[9,-9]]).appendPoint([9,9]).appendPoint([-9,9]).appendPoint([-9,-9]).close().innerToCAG()
.extrude({ offset: [0, 0, 1] });
}
function _export_case_fn() {
// creating part 0 of case _export
let _export__part_0 = export_outline_fn();
// make sure that rotations are relative
let _export__part_0_bounds = _export__part_0.getBounds();
let _export__part_0_x = _export__part_0_bounds[0].x + (_export__part_0_bounds[1].x - _export__part_0_bounds[0].x) / 2
let _export__part_0_y = _export__part_0_bounds[0].y + (_export__part_0_bounds[1].y - _export__part_0_bounds[0].y) / 2
_export__part_0 = translate([-_export__part_0_x, -_export__part_0_y, 0], _export__part_0);
_export__part_0 = rotate([0,0,0], _export__part_0);
_export__part_0 = translate([_export__part_0_x, _export__part_0_y, 0], _export__part_0);
_export__part_0 = translate([0,0,0], _export__part_0);
let result = _export__part_0;
return result;
}
function main() {
return _export_case_fn();
}

View file

@ -0,0 +1,86 @@
solid csg.js
facet normal 0 0 -1
outer loop
vertex -9 9 0
vertex 9 9 0
vertex 9 -9 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex -9 9 0
vertex 9 -9 0
vertex -9 -9 0
endloop
endfacet
facet normal 0 0 1
outer loop
vertex -9 9 1
vertex -9 -9 1
vertex 9 -9 1
endloop
endfacet
facet normal 0 0 1
outer loop
vertex -9 9 1
vertex 9 -9 1
vertex 9 9 1
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 9 -9 0
vertex 9 -9 1
vertex -9 -9 1
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 9 -9 0
vertex -9 -9 1
vertex -9 -9 0
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 9 9 0
vertex 9 9 1
vertex 9 -9 1
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 9 9 0
vertex 9 -9 1
vertex 9 -9 0
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 9 9 1
vertex 9 9 0
vertex -9 9 0
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 9 9 1
vertex -9 9 0
vertex -9 9 1
endloop
endfacet
facet normal -1 0 0
outer loop
vertex -9 9 1
vertex -9 9 0
vertex -9 -9 0
endloop
endfacet
facet normal -1 0 0
outer loop
vertex -9 9 1
vertex -9 -9 0
vertex -9 -9 1
endloop
endfacet
endsolid csg.js

View file

@ -0,0 +1,36 @@
function export_outline_fn(){
return new CSG.Path2D([[-9,-9],[9,-9]]).appendPoint([9,9]).appendPoint([-9,9]).appendPoint([-9,-9]).close().innerToCAG()
.extrude({ offset: [0, 0, 1] });
}
function export_case_fn() {
// creating part 0 of case export
let export__part_0 = export_outline_fn();
// make sure that rotations are relative
let export__part_0_bounds = export__part_0.getBounds();
let export__part_0_x = export__part_0_bounds[0].x + (export__part_0_bounds[1].x - export__part_0_bounds[0].x) / 2
let export__part_0_y = export__part_0_bounds[0].y + (export__part_0_bounds[1].y - export__part_0_bounds[0].y) / 2
export__part_0 = translate([-export__part_0_x, -export__part_0_y, 0], export__part_0);
export__part_0 = rotate([0,0,0], export__part_0);
export__part_0 = translate([export__part_0_x, export__part_0_y, 0], export__part_0);
export__part_0 = translate([0,0,0], export__part_0);
let result = export__part_0;
return result;
}
function main() {
return export_case_fn();
}

View file

@ -0,0 +1,86 @@
solid csg.js
facet normal 0 0 -1
outer loop
vertex -9 9 0
vertex 9 9 0
vertex 9 -9 0
endloop
endfacet
facet normal 0 0 -1
outer loop
vertex -9 9 0
vertex 9 -9 0
vertex -9 -9 0
endloop
endfacet
facet normal 0 0 1
outer loop
vertex -9 9 1
vertex -9 -9 1
vertex 9 -9 1
endloop
endfacet
facet normal 0 0 1
outer loop
vertex -9 9 1
vertex 9 -9 1
vertex 9 9 1
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 9 -9 0
vertex 9 -9 1
vertex -9 -9 1
endloop
endfacet
facet normal 0 -1 0
outer loop
vertex 9 -9 0
vertex -9 -9 1
vertex -9 -9 0
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 9 9 0
vertex 9 9 1
vertex 9 -9 1
endloop
endfacet
facet normal 1 0 0
outer loop
vertex 9 9 0
vertex 9 -9 1
vertex 9 -9 0
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 9 9 1
vertex 9 9 0
vertex -9 9 0
endloop
endfacet
facet normal 0 1 0
outer loop
vertex 9 9 1
vertex -9 9 0
vertex -9 9 1
endloop
endfacet
facet normal -1 0 0
outer loop
vertex -9 9 1
vertex -9 9 0
vertex -9 -9 0
endloop
endfacet
facet normal -1 0 0
outer loop
vertex -9 9 1
vertex -9 -9 0
vertex -9 -9 1
endloop
endfacet
endsolid csg.js

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,91 @@
{
"models": {
"export": {
"models": {
"a": {
"models": {},
"origin": [
0,
0
]
},
"b": {
"models": {
"a": {
"models": {},
"origin": [
0,
0
]
},
"b": {
"paths": {
"ShapeLine1": {
"type": "line",
"origin": [
-9,
-9
],
"end": [
9,
-9
]
},
"ShapeLine2": {
"type": "line",
"origin": [
9,
-9
],
"end": [
9,
9
]
},
"ShapeLine3": {
"type": "line",
"origin": [
9,
9
],
"end": [
-9,
9
]
},
"ShapeLine4": {
"type": "line",
"origin": [
-9,
9
],
"end": [
-9,
-9
]
}
},
"origin": [
0,
0
]
}
},
"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 18 L 18 18 L 18 0 L 0 0 L 0 18 Z" vector-effect="non-scaling-stroke"/></g></svg>

After

Width:  |  Height:  |  Size: 354 B

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,91 @@
{
"models": {
"export": {
"models": {
"a": {
"models": {},
"origin": [
0,
0
]
},
"b": {
"models": {
"a": {
"models": {},
"origin": [
0,
0
]
},
"b": {
"paths": {
"ShapeLine1": {
"type": "line",
"origin": [
-9,
-9
],
"end": [
9,
-9
]
},
"ShapeLine2": {
"type": "line",
"origin": [
9,
-9
],
"end": [
9,
9
]
},
"ShapeLine3": {
"type": "line",
"origin": [
9,
9
],
"end": [
-9,
9
]
},
"ShapeLine4": {
"type": "line",
"origin": [
-9,
9
],
"end": [
-9,
-9
]
}
},
"origin": [
0,
0
]
}
},
"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 18 L 18 18 L 18 0 L 0 0 L 0 18 Z" vector-effect="non-scaling-stroke"/></g></svg>

After

Width:  |  Height:  |  Size: 354 B

View file

@ -0,0 +1,112 @@
(kicad_pcb (version 20171130) (host pcbnew 5.1.6)
(page A3)
(title_block
(title KEYBOARD_NAME_HERE)
(rev VERSION_HERE)
(company YOUR_NAME_HERE)
)
(general
(thickness 1.6)
)
(layers
(0 F.Cu signal)
(31 B.Cu signal)
(32 B.Adhes user)
(33 F.Adhes user)
(34 B.Paste user)
(35 F.Paste user)
(36 B.SilkS user)
(37 F.SilkS user)
(38 B.Mask user)
(39 F.Mask user)
(40 Dwgs.User user)
(41 Cmts.User user)
(42 Eco1.User user)
(43 Eco2.User user)
(44 Edge.Cuts user)
(45 Margin user)
(46 B.CrtYd user)
(47 F.CrtYd user)
(48 B.Fab user)
(49 F.Fab user)
)
(setup
(last_trace_width 0.25)
(trace_clearance 0.2)
(zone_clearance 0.508)
(zone_45_only no)
(trace_min 0.2)
(via_size 0.8)
(via_drill 0.4)
(via_min_size 0.4)
(via_min_drill 0.3)
(uvia_size 0.3)
(uvia_drill 0.1)
(uvias_allowed no)
(uvia_min_size 0.2)
(uvia_min_drill 0.1)
(edge_width 0.05)
(segment_width 0.2)
(pcb_text_width 0.3)
(pcb_text_size 1.5 1.5)
(mod_edge_width 0.12)
(mod_text_size 1 1)
(mod_text_width 0.15)
(pad_size 1.524 1.524)
(pad_drill 0.762)
(pad_to_mask_clearance 0.05)
(aux_axis_origin 0 0)
(visible_elements FFFFFF7F)
(pcbplotparams
(layerselection 0x010fc_ffffffff)
(usegerberextensions false)
(usegerberattributes true)
(usegerberadvancedattributes true)
(creategerberjobfile true)
(excludeedgelayer true)
(linewidth 0.100000)
(plotframeref false)
(viasonmask false)
(mode 1)
(useauxorigin false)
(hpglpennumber 1)
(hpglpenspeed 20)
(hpglpendiameter 15.000000)
(psnegative false)
(psa4output false)
(plotreference true)
(plotvalue true)
(plotinvisibletext false)
(padsonsilk false)
(subtractmaskfromsilk false)
(outputformat 1)
(mirror false)
(drillshape 1)
(scaleselection 1)
(outputdirectory ""))
)
(net 0 "")
(net_class Default "This is the default net class."
(clearance 0.2)
(trace_width 0.25)
(via_dia 0.8)
(via_drill 0.4)
(uvia_dia 0.3)
(uvia_drill 0.1)
(add_net "")
)
)

View file

@ -0,0 +1,112 @@
(kicad_pcb (version 20171130) (host pcbnew 5.1.6)
(page A3)
(title_block
(title KEYBOARD_NAME_HERE)
(rev VERSION_HERE)
(company YOUR_NAME_HERE)
)
(general
(thickness 1.6)
)
(layers
(0 F.Cu signal)
(31 B.Cu signal)
(32 B.Adhes user)
(33 F.Adhes user)
(34 B.Paste user)
(35 F.Paste user)
(36 B.SilkS user)
(37 F.SilkS user)
(38 B.Mask user)
(39 F.Mask user)
(40 Dwgs.User user)
(41 Cmts.User user)
(42 Eco1.User user)
(43 Eco2.User user)
(44 Edge.Cuts user)
(45 Margin user)
(46 B.CrtYd user)
(47 F.CrtYd user)
(48 B.Fab user)
(49 F.Fab user)
)
(setup
(last_trace_width 0.25)
(trace_clearance 0.2)
(zone_clearance 0.508)
(zone_45_only no)
(trace_min 0.2)
(via_size 0.8)
(via_drill 0.4)
(via_min_size 0.4)
(via_min_drill 0.3)
(uvia_size 0.3)
(uvia_drill 0.1)
(uvias_allowed no)
(uvia_min_size 0.2)
(uvia_min_drill 0.1)
(edge_width 0.05)
(segment_width 0.2)
(pcb_text_width 0.3)
(pcb_text_size 1.5 1.5)
(mod_edge_width 0.12)
(mod_text_size 1 1)
(mod_text_width 0.15)
(pad_size 1.524 1.524)
(pad_drill 0.762)
(pad_to_mask_clearance 0.05)
(aux_axis_origin 0 0)
(visible_elements FFFFFF7F)
(pcbplotparams
(layerselection 0x010fc_ffffffff)
(usegerberextensions false)
(usegerberattributes true)
(usegerberadvancedattributes true)
(creategerberjobfile true)
(excludeedgelayer true)
(linewidth 0.100000)
(plotframeref false)
(viasonmask false)
(mode 1)
(useauxorigin false)
(hpglpennumber 1)
(hpglpenspeed 20)
(hpglpendiameter 15.000000)
(psnegative false)
(psa4output false)
(plotreference true)
(plotvalue true)
(plotinvisibletext false)
(padsonsilk false)
(subtractmaskfromsilk false)
(outputformat 1)
(mirror false)
(drillshape 1)
(scaleselection 1)
(outputdirectory ""))
)
(net 0 "")
(net_class Default "This is the default net class."
(clearance 0.2)
(trace_width 0.25)
(via_dia 0.8)
(via_drill 0.4)
(uvia_dia 0.3)
(uvia_drill 0.1)
(add_net "")
)
)

View file

Before

Width:  |  Height:  |  Size: 353 B

After

Width:  |  Height:  |  Size: 353 B

Before After
Before After

View file

@ -0,0 +1,24 @@
units:
a: 28 + u
points.zones.matrix:
columns.col: {}
rows.row: {}
outlines.exports:
export:
- type: 'keys'
side: 'left'
size: 18
_export:
- type: 'keys'
side: 'left'
size: 18
cases:
export:
- name: 'export'
extrude: 1
_export:
- name: 'export'
extrude: 1
pcbs:
export: {}
_export: {}

View file

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

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

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

12
test/cli/medium/log Normal file
View file

@ -0,0 +1,12 @@
Ergogen <version> CLI
Interpreting format: YAML
Preprocessing input...
Calculating variables...
Parsing points...
Generating outlines...
Extruding cases...
Scaffolding PCBs...
Writing output to disk...
Done.

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,112 @@
(kicad_pcb (version 20171130) (host pcbnew 5.1.6)
(page A3)
(title_block
(title KEYBOARD_NAME_HERE)
(rev VERSION_HERE)
(company YOUR_NAME_HERE)
)
(general
(thickness 1.6)
)
(layers
(0 F.Cu signal)
(31 B.Cu signal)
(32 B.Adhes user)
(33 F.Adhes user)
(34 B.Paste user)
(35 F.Paste user)
(36 B.SilkS user)
(37 F.SilkS user)
(38 B.Mask user)
(39 F.Mask user)
(40 Dwgs.User user)
(41 Cmts.User user)
(42 Eco1.User user)
(43 Eco2.User user)
(44 Edge.Cuts user)
(45 Margin user)
(46 B.CrtYd user)
(47 F.CrtYd user)
(48 B.Fab user)
(49 F.Fab user)
)
(setup
(last_trace_width 0.25)
(trace_clearance 0.2)
(zone_clearance 0.508)
(zone_45_only no)
(trace_min 0.2)
(via_size 0.8)
(via_drill 0.4)
(via_min_size 0.4)
(via_min_drill 0.3)
(uvia_size 0.3)
(uvia_drill 0.1)
(uvias_allowed no)
(uvia_min_size 0.2)
(uvia_min_drill 0.1)
(edge_width 0.05)
(segment_width 0.2)
(pcb_text_width 0.3)
(pcb_text_size 1.5 1.5)
(mod_edge_width 0.12)
(mod_text_size 1 1)
(mod_text_width 0.15)
(pad_size 1.524 1.524)
(pad_drill 0.762)
(pad_to_mask_clearance 0.05)
(aux_axis_origin 0 0)
(visible_elements FFFFFF7F)
(pcbplotparams
(layerselection 0x010fc_ffffffff)
(usegerberextensions false)
(usegerberattributes true)
(usegerberadvancedattributes true)
(creategerberjobfile true)
(excludeedgelayer true)
(linewidth 0.100000)
(plotframeref false)
(viasonmask false)
(mode 1)
(useauxorigin false)
(hpglpennumber 1)
(hpglpenspeed 20)
(hpglpendiameter 15.000000)
(psnegative false)
(psa4output false)
(plotreference true)
(plotvalue true)
(plotinvisibletext false)
(padsonsilk false)
(subtractmaskfromsilk false)
(outputformat 1)
(mirror false)
(drillshape 1)
(scaleselection 1)
(outputdirectory ""))
)
(net 0 "")
(net_class Default "This is the default net class."
(clearance 0.2)
(trace_width 0.25)
(via_dia 0.8)
(via_drill 0.4)
(uvia_dia 0.3)
(uvia_drill 0.1)
(add_net "")
)
)

View file

@ -1,4 +1,4 @@
Ergogen v2.0.0 CLI
Ergogen <version> CLI
Interpreting format: YAML
Preprocessing input...

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 @@
node src/cli.js nonexistent.yaml

View file

@ -0,0 +1 @@
Could not read config file "nonexistent.yaml": Error: ENOENT: no such file or directory, open 'nonexistent.yaml'

9
test/fixtures/medium.yaml vendored Normal file
View file

@ -0,0 +1,9 @@
points.zones.matrix:
columns.col: {}
outlines.exports:
export:
- type: 'keys'
side: 'left'
size: 18
pcbs:
export: {}

View file

@ -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
}
}
})