diff --git a/packages/xod-arduino/src/transpiler.js b/packages/xod-arduino/src/transpiler.js index a48e5a6b..09dd79df 100644 --- a/packages/xod-arduino/src/transpiler.js +++ b/packages/xod-arduino/src/transpiler.js @@ -46,6 +46,7 @@ const kebabToSnake = R.replace(/-/g, '_'); const createPatchNames = def( 'createPatchNames :: PatchPath -> { owner :: String, libName :: String, patchName :: String }', (path) => { + // TODO: this handles @/local-patches incorrectly const [owner, libName, ...patchNameParts] = R.split('/', path); const patchName = patchNameParts.join('/'); @@ -194,7 +195,7 @@ const getPinLabelsMap = def( ); const getNodePinsUnsafe = def( - 'getNodePinLabels :: Node -> Project -> [Pin]', + 'getNodePinsUnsafe :: Node -> Project -> [Pin]', (node, project) => R.compose( explodeMaybe(`Can’t get node pins of node ${node}. Referred type missing?`), Project.getNodePins @@ -349,6 +350,19 @@ const createTNodes = def( export const transformProject = def( 'transformProject :: [Source] -> Project -> PatchPath -> Either Error TProject', (impls, project, path) => R.compose( + R.chain((tProject) => { + const nodeWithTooManyOutputs = R.find( + R.pipe(R.prop('outputs'), R.length, R.lte(7)), + tProject.patches + ); + + if (nodeWithTooManyOutputs) { + const { owner, libName, patchName } = nodeWithTooManyOutputs; + return Either.Left(new Error(`Native node ${owner}/${libName}/${patchName} has more than 7 outputs`)); + } + + return Either.of(tProject); + }), R.map(([proj, topology]) => { const patches = createTPatches(path, proj); diff --git a/packages/xod-arduino/test/mocha.opts b/packages/xod-arduino/test/mocha.opts index cd47db09..a692071a 100644 --- a/packages/xod-arduino/test/mocha.opts +++ b/packages/xod-arduino/test/mocha.opts @@ -1,4 +1,4 @@ --require babel-register --colors ---timeout 120000 +--timeout 240000 --plugins babel-plugin-inline-import diff --git a/packages/xod-arduino/test/transpiler.spec.js b/packages/xod-arduino/test/transpiler.spec.js index 4d03af7f..2372dfa2 100644 --- a/packages/xod-arduino/test/transpiler.spec.js +++ b/packages/xod-arduino/test/transpiler.spec.js @@ -3,7 +3,7 @@ import path from 'path'; import R from 'ramda'; import { assert } from 'chai'; -import { explode } from 'xod-func-tools'; +import { explode, foldEither } from 'xod-func-tools'; import { loadProject } from 'xod-fs'; import { PIN_TYPE } from 'xod-project'; import { defaultizePin } from 'xod-project/test/helpers'; @@ -35,6 +35,19 @@ describe('xod-arduino transpiler', () => { .then(transpile(R.__, '@/non-existing-patch')) .then(result => assert.ok(result.isLeft)) ); + + it('returns error if some native node has more than 7 outputs', + () => + loadProject(wsPath('faulty')) + .then(transpile(R.__, '@/too-many-outputs-main')) + .then(foldEither( + (err) => { + assert.include(err.message, '@/too_many_outputs'); + assert.include(err.message, 'has more than 7 outputs'); + }, + () => assert.fail('expecting Either.Left') + )) + ); }); describe('getInitialDirtyFlags', () => { diff --git a/packages/xod-client-electron/test-func/fixtures/blink.cpp b/packages/xod-client-electron/test-func/fixtures/blink.cpp index 87d510d5..1e4f7ce3 100644 --- a/packages/xod-client-electron/test-func/fixtures/blink.cpp +++ b/packages/xod-client-electron/test-func/fixtures/blink.cpp @@ -1136,11 +1136,11 @@ namespace xod { }; DirtyFlags dirtyFlags[NODE_COUNT] = { - DirtyFlags(-1), - DirtyFlags(-1), - DirtyFlags(-1), - DirtyFlags(-1), - DirtyFlags(-1) + DirtyFlags(253), + DirtyFlags(255), + DirtyFlags(255), + DirtyFlags(255), + DirtyFlags(255) }; NodeId topology[NODE_COUNT] = { diff --git a/workspace/faulty/project.xod b/workspace/faulty/project.xod new file mode 100644 index 00000000..549ea25a --- /dev/null +++ b/workspace/faulty/project.xod @@ -0,0 +1,3 @@ +{ + "name": "faulty" +} \ No newline at end of file diff --git a/workspace/faulty/too-many-outputs-main/patch.xodp b/workspace/faulty/too-many-outputs-main/patch.xodp new file mode 100644 index 00000000..c6388689 --- /dev/null +++ b/workspace/faulty/too-many-outputs-main/patch.xodp @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "id": "Bk-49Oyw-", + "position": { + "x": 138, + "y": 120 + }, + "type": "@/too-many-outputs" + } + ] +} \ No newline at end of file diff --git a/workspace/faulty/too-many-outputs/any.cpp b/workspace/faulty/too-many-outputs/any.cpp new file mode 100644 index 00000000..31fac8b7 --- /dev/null +++ b/workspace/faulty/too-many-outputs/any.cpp @@ -0,0 +1 @@ +// it shoud not transpile anyway diff --git a/workspace/faulty/too-many-outputs/patch.xodp b/workspace/faulty/too-many-outputs/patch.xodp new file mode 100644 index 00000000..0bbff884 --- /dev/null +++ b/workspace/faulty/too-many-outputs/patch.xodp @@ -0,0 +1,76 @@ +{ + "nodes": [ + { + "id": "Bkby9_1vb", + "position": { + "x": 138, + "y": 224 + }, + "type": "xod/patch-nodes/output-number" + }, + { + "id": "H14e5uyDZ", + "position": { + "x": 778, + "y": 224 + }, + "type": "xod/patch-nodes/output-pulse" + }, + { + "id": "Hy0CF_kDW", + "position": { + "x": 10, + "y": 224 + }, + "type": "xod/patch-nodes/output-boolean" + }, + { + "id": "S1N1cdJDW", + "position": { + "x": 266, + "y": 224 + }, + "type": "xod/patch-nodes/output-pulse" + }, + { + "id": "SJ_e9uJvZ", + "position": { + "x": 906, + "y": 224 + }, + "type": "xod/patch-nodes/output-string" + }, + { + "id": "SkhkcdyDb", + "position": { + "x": 522, + "y": 224 + }, + "type": "xod/patch-nodes/output-boolean" + }, + { + "id": "rJ4ZcukDb", + "position": { + "x": 10, + "y": 16 + }, + "type": "xod/patch-nodes/not-implemented-in-xod" + }, + { + "id": "rkO1quyPW", + "position": { + "x": 394, + "y": 224 + }, + "type": "xod/patch-nodes/output-string" + }, + { + "id": "rkbl5dyPb", + "position": { + "x": 650, + "y": 224 + }, + "type": "xod/patch-nodes/output-number" + } + ] +} \ No newline at end of file