From d09b3fdf3841b3f214dfebb4e552184e08c85e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1n=20D=C3=A9nes?= Date: Wed, 14 Jul 2021 19:35:47 +0200 Subject: [PATCH] Smarter dump switch for the test runner, reference adjustments --- test/index.js | 38 +- .../001_basic_outline___outlines.json | 506 ------------------ ...1_basic_outline___outlines_outline_dxf.dxf | 290 ++++++++++ 3 files changed, 321 insertions(+), 513 deletions(-) delete mode 100644 test/outlines/001_basic_outline___outlines.json create mode 100644 test/outlines/001_basic_outline___outlines_outline_dxf.dxf diff --git a/test/index.js b/test/index.js index c603558..d7ea67b 100644 --- a/test/index.js +++ b/test/index.js @@ -3,15 +3,16 @@ const path = require('path') const yaml = require('js-yaml') const glob = require('glob') const u = require('../src/utils') +const a = require('../src/assert') const ergogen = require('../src/ergogen') require('./helpers/mock_footprints').inject(ergogen) let what = process.env.npm_config_what -let first = process.env.npm_config_first +let dump = process.env.npm_config_dump // Unit tests // the --what switch supports each unit individually -// the --first switch does nothing here +// the --dump switch does nothing here what = what ? what.split(',') : false for (const unit of glob.sync(path.join(__dirname, 'unit', '*.js'))) { @@ -23,7 +24,9 @@ for (const unit of glob.sync(path.join(__dirname, 'unit', '*.js'))) { // Integration tests // the --what switch supports categories (like `points` and `outlines`) // as well as individual tests using slash-notation (like `points/000`) -// the --first switch outputs the actual results for easier reference creation +// the --dump switch can output actual results for easier reference creation +// by default, json output is generated of the whole `actual`, but a raw, +// type-specific representation can be written if a deep path is specified const cap = s => s.charAt(0).toUpperCase() + s.slice(1) @@ -33,13 +36,34 @@ const test = function(input_path) { it(title, function() { const input = yaml.load(fs.readFileSync(input_path).toString()) const actual = ergogen.process(input, true) - if (first) { - const out = path.join(path.dirname(input_path), path.basename(input_path, '.yaml') + '___actual.json') - fs.writeJSONSync(out, actual, {spaces: 4}) + + // if we're just creating the reference, we can dump the current output + if (dump) { + const out = path.join( + path.dirname(input_path), + path.basename(input_path, '.yaml') + '___ref_candidate' + ) + // whole dump + if (dump === true) { + fs.writeJSONSync(out + '.json', actual, {spaces: 4}) + // partial, type-specific dump + } else { + const part = u.deep(actual, dump) + if (a.type(part)() == 'string') { + fs.writeFileSync(out + '.txt', part) + } else { + fs.writeJSONSync(out + '.json', part, {spaces: 4}) + } + } } + + // compare actual vs. reference const base = path.join(path.dirname(input_path), path.basename(input_path, '.yaml')) for (const expected_path of glob.sync(base + '___*')) { - const expected = JSON.parse(fs.readFileSync(expected_path).toString()) + let expected = fs.readFileSync(expected_path).toString() + if (expected_path.endsWith('.json')) { + expected = JSON.parse(expected) + } const comp_path = expected_path.split('___')[1].split('.')[0].split('_').join('.') u.deep(actual, comp_path).should.deep.equal(expected) } diff --git a/test/outlines/001_basic_outline___outlines.json b/test/outlines/001_basic_outline___outlines.json deleted file mode 100644 index 258bf48..0000000 --- a/test/outlines/001_basic_outline___outlines.json +++ /dev/null @@ -1,506 +0,0 @@ -{ - "outline": { - "models": { - "a": { - "models": { - "a": { - "models": {}, - "origin": [ - 0, - 0 - ] - }, - "b": { - "models": { - "a": { - "models": { - "a": { - "models": { - "a": { - "models": { - "a": { - "models": {}, - "origin": [ - 0, - 0 - ] - }, - "b": { - "models": { - "a": { - "models": { - "a": { - "paths": { - "ShapeLine1": { - "type": "line", - "origin": [ - -10, - -10 - ], - "end": [ - 29, - -10 - ] - }, - "ShapeLine4": { - "type": "line", - "origin": [ - -10, - -10 - ], - "end": [ - -10, - 29 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": {}, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": {}, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "models": { - "a": { - "models": { - "a": { - "paths": { - "ShapeLine3": { - "type": "line", - "origin": [ - -10, - 29 - ], - "end": [ - 29, - 29 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": {}, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": {}, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "models": { - "a": { - "models": { - "a": { - "paths": { - "ShapeLine2": { - "type": "line", - "origin": [ - 29, - -10 - ], - "end": [ - 29, - 29 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": {}, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": {}, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "models": { - "a": { - "models": { - "a": { - "paths": {}, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": {}, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": {}, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "models": { - "a": { - "models": { - "a": { - "models": { - "a": { - "models": { - "a": { - "models": {}, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": { - "ShapeLine1": { - "type": "line", - "origin": [ - -7, - -7 - ], - "end": [ - 7, - -7 - ] - }, - "ShapeLine2": { - "type": "line", - "origin": [ - 7, - -7 - ], - "end": [ - 7, - 7 - ] - }, - "ShapeLine3": { - "type": "line", - "origin": [ - 7, - 7 - ], - "end": [ - -7, - 7 - ] - }, - "ShapeLine4": { - "type": "line", - "origin": [ - -7, - 7 - ], - "end": [ - -7, - -7 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": { - "ShapeLine1": { - "type": "line", - "origin": [ - -7, - 12 - ], - "end": [ - 7, - 12 - ] - }, - "ShapeLine2": { - "type": "line", - "origin": [ - 7, - 12 - ], - "end": [ - 7, - 26 - ] - }, - "ShapeLine3": { - "type": "line", - "origin": [ - 7, - 26 - ], - "end": [ - -7, - 26 - ] - }, - "ShapeLine4": { - "type": "line", - "origin": [ - -7, - 26 - ], - "end": [ - -7, - 12 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": { - "ShapeLine1": { - "type": "line", - "origin": [ - 12, - -7 - ], - "end": [ - 26, - -7 - ] - }, - "ShapeLine2": { - "type": "line", - "origin": [ - 26, - -7 - ], - "end": [ - 26, - 7 - ] - }, - "ShapeLine3": { - "type": "line", - "origin": [ - 26, - 7 - ], - "end": [ - 12, - 7 - ] - }, - "ShapeLine4": { - "type": "line", - "origin": [ - 12, - 7 - ], - "end": [ - 12, - -7 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - }, - "b": { - "paths": { - "ShapeLine1": { - "type": "line", - "origin": [ - 12, - 12 - ], - "end": [ - 26, - 12 - ] - }, - "ShapeLine2": { - "type": "line", - "origin": [ - 26, - 12 - ], - "end": [ - 26, - 26 - ] - }, - "ShapeLine3": { - "type": "line", - "origin": [ - 26, - 26 - ], - "end": [ - 12, - 26 - ] - }, - "ShapeLine4": { - "type": "line", - "origin": [ - 12, - 26 - ], - "end": [ - 12, - 12 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - } - }, - "origin": [ - 0, - 0 - ] - } -} \ No newline at end of file diff --git a/test/outlines/001_basic_outline___outlines_outline_dxf.dxf b/test/outlines/001_basic_outline___outlines_outline_dxf.dxf new file mode 100644 index 0000000..7b0b293 --- /dev/null +++ b/test/outlines/001_basic_outline___outlines_outline_dxf.dxf @@ -0,0 +1,290 @@ +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 +-10 +20 +-10 +11 +29 +21 +-10 +0 +LINE +8 +0 +10 +-10 +20 +-10 +11 +-10 +21 +29 +0 +LINE +8 +0 +10 +-10 +20 +29 +11 +29 +21 +29 +0 +LINE +8 +0 +10 +29 +20 +-10 +11 +29 +21 +29 +0 +LINE +8 +0 +10 +-7 +20 +-7 +11 +7 +21 +-7 +0 +LINE +8 +0 +10 +7 +20 +-7 +11 +7 +21 +7 +0 +LINE +8 +0 +10 +7 +20 +7 +11 +-7 +21 +7 +0 +LINE +8 +0 +10 +-7 +20 +7 +11 +-7 +21 +-7 +0 +LINE +8 +0 +10 +-7 +20 +12 +11 +7 +21 +12 +0 +LINE +8 +0 +10 +7 +20 +12 +11 +7 +21 +26 +0 +LINE +8 +0 +10 +7 +20 +26 +11 +-7 +21 +26 +0 +LINE +8 +0 +10 +-7 +20 +26 +11 +-7 +21 +12 +0 +LINE +8 +0 +10 +12 +20 +-7 +11 +26 +21 +-7 +0 +LINE +8 +0 +10 +26 +20 +-7 +11 +26 +21 +7 +0 +LINE +8 +0 +10 +26 +20 +7 +11 +12 +21 +7 +0 +LINE +8 +0 +10 +12 +20 +7 +11 +12 +21 +-7 +0 +LINE +8 +0 +10 +12 +20 +12 +11 +26 +21 +12 +0 +LINE +8 +0 +10 +26 +20 +12 +11 +26 +21 +26 +0 +LINE +8 +0 +10 +26 +20 +26 +11 +12 +21 +26 +0 +LINE +8 +0 +10 +12 +20 +26 +11 +12 +21 +12 +0 +ENDSEC +0 +EOF \ No newline at end of file