From c81152ddbb0214620ed93a3a3ec41cb96f230523 Mon Sep 17 00:00:00 2001 From: tfloxolodeiro Date: Wed, 6 Apr 2022 13:06:24 -0300 Subject: [PATCH 1/7] Mulang tests --- .../unit/services/mulang-expectations-test.js | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/tests/unit/services/mulang-expectations-test.js b/tests/unit/services/mulang-expectations-test.js index ef46490e5..f81114edd 100644 --- a/tests/unit/services/mulang-expectations-test.js +++ b/tests/unit/services/mulang-expectations-test.js @@ -29,6 +29,12 @@ module('Unit | Service | Mulang | Expectations', function (hooks) { ) ]) + expectationTestOk('doSomething', doSomething(declaration), [ + procedure(declaration, [], + application(declaration) + ) + ], 'Recursion should count as doing something') + expectationTestFail('doSomething', doSomething('EMPTY'), [ procedure('EMPTY', []) ]) @@ -85,9 +91,17 @@ module('Unit | Service | Mulang | Expectations', function (hooks) { ) ]) + expectationTestFail('notTooLong', notTooLong(limit)(declaration), [ + procedure(declaration, [], + application(declaration), + application(declaration), + application(declaration) + ) + ], 'Recursive calls should count as being too long ') + expectationTestOk('doesNotUseRecursion', doesNotUseRecursion(declaration), [ procedure(declaration, [], - application("PROCEDURE2") + application("PROCEDURE2") ), procedure("PROCEDURE2", []) ]) @@ -95,31 +109,39 @@ module('Unit | Service | Mulang | Expectations', function (hooks) { // Direct recursion expectationTestFail('doesNotUseRecursion', doesNotUseRecursion(declaration), [ procedure(declaration, [], - application(declaration) + application(declaration) ) ]) - /* + // Indirect recursion expectationTestFail('doesNotUseRecursion', doesNotUseRecursion(declaration), [ procedure(declaration, [], - application("PROCEDURE2") + application("PROCEDURE2") ), procedure("PROCEDURE2", [], application(declaration) ) - ]) - */ + ], 'Indirect recursion should count as recursion') + + expectationTestFail('doesNotUseRecursion', doesNotUseRecursion(declaration), [ + procedure(declaration, [], + application(declaration), + application("PROCEDURE2") + ), + procedure("PROCEDURE2", [], + application('PRIMITIVE')) + ], 'Direct recursion with another procedure call should count as recursion') - function expectationTestOk(expectationName, expectation, astNodes) { - expectationTest(expectationName, expectation, astNodes, true) + function expectationTestOk(expectationName, expectation, astNodes, testName) { + expectationTest(expectationName, expectation, astNodes, true, testName) } - function expectationTestFail(expectationName, expectation, astNodes) { - expectationTest(expectationName, expectation, astNodes, false) + function expectationTestFail(expectationName, expectation, astNodes, testName) { + expectationTest(expectationName, expectation, astNodes, false, testName) } - function expectationTest(expectationName, edl, astNodes, shouldPass) { - test(`Expectation ${expectationName} - ${shouldPass ? 'ok' : 'fail'}`, function (assert) { + function expectationTest(expectationName, edl, astNodes, shouldPass, testName = '') { + test(`Expectation ${expectationName} - ${testName || (shouldPass ? 'ok' : 'fail')}`, function (assert) { const mulangResult = mulang .astCode(rawSequence(astNodes)) .customExpect(edl) From 488e2d7e9b1b0549353992cc5a514c2fdd15d874 Mon Sep 17 00:00:00 2001 From: tfloxolodeiro Date: Wed, 6 Apr 2022 14:54:34 -0300 Subject: [PATCH 2/7] fixing doesNotUseRecursion --- app/utils/expectations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/utils/expectations.js b/app/utils/expectations.js index d35f436e9..c7e88f9a0 100644 --- a/app/utils/expectations.js +++ b/app/utils/expectations.js @@ -24,7 +24,7 @@ export const notTooLong = (limit = 7) => (declaration) => newExpectation(`within ${toEDLString(declaration)} count(calls) <= ${limit - 1}`, 'too_long', { declaration, limit }) export const doesNotUseRecursion = (declaration) => - newExpectation(`through ${toEDLString(declaration)} ! calls ${toEDLString(declaration)}`, 'does_not_use_recursion', { declaration }) + newExpectation(`not (through ${toEDLString(declaration)} calls ${toEDLString(declaration)})`, 'does_not_use_recursion', { declaration }) // UTILS const newExpectation = (expect, id, opts = {}) => From f8aa7f17854b691cd5b8a96fd91433e6217f84ac Mon Sep 17 00:00:00 2001 From: tfloxolodeiro Date: Wed, 6 Apr 2022 15:01:43 -0300 Subject: [PATCH 3/7] Skipping mulang tests --- .../unit/services/mulang-expectations-test.js | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/unit/services/mulang-expectations-test.js b/tests/unit/services/mulang-expectations-test.js index f81114edd..90349d1cb 100644 --- a/tests/unit/services/mulang-expectations-test.js +++ b/tests/unit/services/mulang-expectations-test.js @@ -28,13 +28,13 @@ module('Unit | Service | Mulang | Expectations', function (hooks) { application('PRIMITIVE') ) ]) - - expectationTestOk('doSomething', doSomething(declaration), [ - procedure(declaration, [], - application(declaration) - ) - ], 'Recursion should count as doing something') - + /* + expectationTestOk('doSomething', doSomething(declaration), [ + procedure(declaration, [], + application(declaration) + ) + ], 'Recursion should count as doing something') + */ expectationTestFail('doSomething', doSomething('EMPTY'), [ procedure('EMPTY', []) ]) @@ -90,15 +90,15 @@ module('Unit | Service | Mulang | Expectations', function (hooks) { application('PRIMITIVE'), ) ]) - - expectationTestFail('notTooLong', notTooLong(limit)(declaration), [ - procedure(declaration, [], - application(declaration), - application(declaration), - application(declaration) - ) - ], 'Recursive calls should count as being too long ') - + /* + expectationTestFail('notTooLong', notTooLong(limit)(declaration), [ + procedure(declaration, [], + application(declaration), + application(declaration), + application(declaration) + ) + ], 'Recursive calls should count as being too long ') + */ expectationTestOk('doesNotUseRecursion', doesNotUseRecursion(declaration), [ procedure(declaration, [], application("PROCEDURE2") From 84cb3eda3a3102b631029b45c1d4368cecbca783 Mon Sep 17 00:00:00 2001 From: ezequielPereyra <31800576+ezequielPereyra@users.noreply.github.com> Date: Thu, 7 Apr 2022 15:30:19 -0300 Subject: [PATCH 4/7] Count counts recursive callings --- app/utils/expectations.js | 7 +++++-- tests/unit/services/mulang-expectations-test.js | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/utils/expectations.js b/app/utils/expectations.js index dfbb4c6af..930a2515a 100644 --- a/app/utils/expectations.js +++ b/app/utils/expectations.js @@ -12,7 +12,7 @@ export const multiExpect = (...expectations) => (element) => // DECLARATION EXPECTATIONS export const doSomething = (declaration) => - newExpectation(`within ${toEDLString(declaration)} count(calls) >= 1`, 'do_something', { declaration }) + newExpectation(`within ${toEDLString(declaration)} ${countWithRecursiveCalling(declaration)} >= 1`, 'do_something', { declaration }) export const isUsed = (declaration) => newExpectation(`calls ${toEDLString(declaration)}`, 'is_used', { declaration }) @@ -21,7 +21,7 @@ export const isUsedFromMain = (declaration) => newExpectation(`through ${toEDLString(entryPointType)} calls ${toEDLString(declaration)}`, 'is_used_from_main', { declaration }) export const notTooLong = (limit = 7) => (declaration) => - newExpectation(`within ${toEDLString(declaration)} count(calls) <= ${limit - 1}`, 'too_long', { declaration, limit }) + newExpectation(`within ${toEDLString(declaration)} ${countWithRecursiveCalling(declaration)} <= ${limit - 1}`, 'too_long', { declaration, limit }) export const doesNotUseRecursion = (declaration) => newExpectation(`not (through ${toEDLString(declaration)} calls ${toEDLString(declaration)})`, doesNotUseRecursionId, { declaration }) @@ -30,6 +30,9 @@ export const doesNotUseRecursion = (declaration) => const newExpectation = (expect, id, opts = {}) => `expectation "${stringify(id, opts)}": ${expect};` +const countWithRecursiveCalling = (declaration) => + `count(calls) + count(calls ${toEDLString(declaration)})` + export const stringify = (id, opts) => `${expectationName(id)}|${Object.entries(opts).map(([key, value]) => `${key}=${value}`).join(';')}` diff --git a/tests/unit/services/mulang-expectations-test.js b/tests/unit/services/mulang-expectations-test.js index d171c4374..d0eae2c6b 100644 --- a/tests/unit/services/mulang-expectations-test.js +++ b/tests/unit/services/mulang-expectations-test.js @@ -28,13 +28,13 @@ module('Unit | Service | Mulang | Expectations', function (hooks) { application('PRIMITIVE') ) ]) - /* + expectationTestOk('doSomething', doSomething(declaration), [ procedure(declaration, [], application(declaration) ) ], 'Recursion should count as doing something') - */ + expectationTestFail('doSomething', doSomething('EMPTY'), [ procedure('EMPTY', []) ]) @@ -90,7 +90,7 @@ module('Unit | Service | Mulang | Expectations', function (hooks) { application('PRIMITIVE'), ) ]) - /* + expectationTestFail('notTooLong', notTooLong(limit)(declaration), [ procedure(declaration, [], application(declaration), @@ -98,7 +98,7 @@ module('Unit | Service | Mulang | Expectations', function (hooks) { application(declaration) ) ], 'Recursive calls should count as being too long ') - */ + expectationTestOk('doesNotUseRecursion', doesNotUseRecursion(declaration), [ procedure(declaration, [], application("PROCEDURE2") From 34350a40256fb292e8c0da9e17c065197235fdc8 Mon Sep 17 00:00:00 2001 From: ezequielPereyra <31800576+ezequielPereyra@users.noreply.github.com> Date: Thu, 7 Apr 2022 15:40:01 -0300 Subject: [PATCH 5/7] Added within --- app/utils/expectations.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/utils/expectations.js b/app/utils/expectations.js index 930a2515a..d95b0f2de 100644 --- a/app/utils/expectations.js +++ b/app/utils/expectations.js @@ -12,7 +12,7 @@ export const multiExpect = (...expectations) => (element) => // DECLARATION EXPECTATIONS export const doSomething = (declaration) => - newExpectation(`within ${toEDLString(declaration)} ${countWithRecursiveCalling(declaration)} >= 1`, 'do_something', { declaration }) + newExpectation(`${countWithRecursiveCalling(declaration)} >= 1`, 'do_something', { declaration }) export const isUsed = (declaration) => newExpectation(`calls ${toEDLString(declaration)}`, 'is_used', { declaration }) @@ -21,7 +21,7 @@ export const isUsedFromMain = (declaration) => newExpectation(`through ${toEDLString(entryPointType)} calls ${toEDLString(declaration)}`, 'is_used_from_main', { declaration }) export const notTooLong = (limit = 7) => (declaration) => - newExpectation(`within ${toEDLString(declaration)} ${countWithRecursiveCalling(declaration)} <= ${limit - 1}`, 'too_long', { declaration, limit }) + newExpectation(`${countWithRecursiveCalling(declaration)} <= ${limit - 1}`, 'too_long', { declaration, limit }) export const doesNotUseRecursion = (declaration) => newExpectation(`not (through ${toEDLString(declaration)} calls ${toEDLString(declaration)})`, doesNotUseRecursionId, { declaration }) @@ -31,7 +31,7 @@ const newExpectation = (expect, id, opts = {}) => `expectation "${stringify(id, opts)}": ${expect};` const countWithRecursiveCalling = (declaration) => - `count(calls) + count(calls ${toEDLString(declaration)})` + `within ${toEDLString(declaration)} count(calls) + count(calls ${toEDLString(declaration)})` export const stringify = (id, opts) => `${expectationName(id)}|${Object.entries(opts).map(([key, value]) => `${key}=${value}`).join(';')}` From 2cc2791dbd5bc8d713f0065b1c1c6796ec0fc77e Mon Sep 17 00:00:00 2001 From: ezequielPereyra <31800576+ezequielPereyra@users.noreply.github.com> Date: Mon, 11 Apr 2022 11:37:53 -0300 Subject: [PATCH 6/7] countCalls rename --- app/utils/expectations.js | 10 ++++++---- tests/unit/services/mulang-expectations-test.js | 10 +++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/utils/expectations.js b/app/utils/expectations.js index d95b0f2de..be4e28d4b 100644 --- a/app/utils/expectations.js +++ b/app/utils/expectations.js @@ -12,7 +12,7 @@ export const multiExpect = (...expectations) => (element) => // DECLARATION EXPECTATIONS export const doSomething = (declaration) => - newExpectation(`${countWithRecursiveCalling(declaration)} >= 1`, 'do_something', { declaration }) + newExpectation(`${countCalls(declaration)} >= 1`, 'do_something', { declaration }) export const isUsed = (declaration) => newExpectation(`calls ${toEDLString(declaration)}`, 'is_used', { declaration }) @@ -21,16 +21,18 @@ export const isUsedFromMain = (declaration) => newExpectation(`through ${toEDLString(entryPointType)} calls ${toEDLString(declaration)}`, 'is_used_from_main', { declaration }) export const notTooLong = (limit = 7) => (declaration) => - newExpectation(`${countWithRecursiveCalling(declaration)} <= ${limit - 1}`, 'too_long', { declaration, limit }) + newExpectation(`${countCalls(declaration)} <= ${limit - 1}`, 'too_long', { declaration, limit }) export const doesNotUseRecursion = (declaration) => newExpectation(`not (through ${toEDLString(declaration)} calls ${toEDLString(declaration)})`, doesNotUseRecursionId, { declaration }) // UTILS -const newExpectation = (expect, id, opts = {}) => +export const newExpectation = (expect, id, opts = {}) => `expectation "${stringify(id, opts)}": ${expect};` -const countWithRecursiveCalling = (declaration) => +// Use this to count number of calls inside a procedure, including recursive calls +// Mulang count does not count recursive calls +export const countCalls = (declaration) => `within ${toEDLString(declaration)} count(calls) + count(calls ${toEDLString(declaration)})` export const stringify = (id, opts) => diff --git a/tests/unit/services/mulang-expectations-test.js b/tests/unit/services/mulang-expectations-test.js index d0eae2c6b..cdbfd4052 100644 --- a/tests/unit/services/mulang-expectations-test.js +++ b/tests/unit/services/mulang-expectations-test.js @@ -1,6 +1,6 @@ import { module, test } from 'qunit' import { entryPointType } from '../../../utils/blocks' -import { declaresAnyProcedure, doSomething, isUsed, isUsedFromMain, notTooLong, parseExpect, doesNotUseRecursion, stringify, expectationId, isCritical, doesNotUseRecursionId } from '../../../utils/expectations' +import { declaresAnyProcedure, doSomething, isUsed, isUsedFromMain, notTooLong, parseExpect, doesNotUseRecursion, stringify, expectationId, isCritical, doesNotUseRecursionId, newExpectation, countCalls } from '../../../utils/expectations' import { procedure, entryPoint, rawSequence, application } from '../../helpers/astFactories' import { setupPBUnitTest, setUpTestWorkspace } from '../../helpers/utils' @@ -132,6 +132,14 @@ module('Unit | Service | Mulang | Expectations', function (hooks) { application('PRIMITIVE')) ], 'Direct recursion with another procedure call should count as recursion') + expectationTestOk('countCalls', newExpectation(`${countCalls(declaration)} = 2`, 'counts', { declaration }), [ + procedure(declaration, [], + application("PROCEDURE2"), + application(declaration) + ), + procedure("PROCEDURE2", []) + ], 'countCalls includes recursive calls') + function expectationTestOk(expectationName, expectation, astNodes, testName) { expectationTest(expectationName, expectation, astNodes, true, testName) } From 67f0338337ef869203b75053197eba7cf37022c9 Mon Sep 17 00:00:00 2001 From: ezequielPereyra <31800576+ezequielPereyra@users.noreply.github.com> Date: Mon, 11 Apr 2022 11:54:49 -0300 Subject: [PATCH 7/7] countCallsWithin --- app/utils/expectations.js | 6 +++--- tests/unit/services/mulang-expectations-test.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/utils/expectations.js b/app/utils/expectations.js index be4e28d4b..2c3fe5e6b 100644 --- a/app/utils/expectations.js +++ b/app/utils/expectations.js @@ -12,7 +12,7 @@ export const multiExpect = (...expectations) => (element) => // DECLARATION EXPECTATIONS export const doSomething = (declaration) => - newExpectation(`${countCalls(declaration)} >= 1`, 'do_something', { declaration }) + newExpectation(`${countCallsWithin(declaration)} >= 1`, 'do_something', { declaration }) export const isUsed = (declaration) => newExpectation(`calls ${toEDLString(declaration)}`, 'is_used', { declaration }) @@ -21,7 +21,7 @@ export const isUsedFromMain = (declaration) => newExpectation(`through ${toEDLString(entryPointType)} calls ${toEDLString(declaration)}`, 'is_used_from_main', { declaration }) export const notTooLong = (limit = 7) => (declaration) => - newExpectation(`${countCalls(declaration)} <= ${limit - 1}`, 'too_long', { declaration, limit }) + newExpectation(`${countCallsWithin(declaration)} <= ${limit - 1}`, 'too_long', { declaration, limit }) export const doesNotUseRecursion = (declaration) => newExpectation(`not (through ${toEDLString(declaration)} calls ${toEDLString(declaration)})`, doesNotUseRecursionId, { declaration }) @@ -32,7 +32,7 @@ export const newExpectation = (expect, id, opts = {}) => // Use this to count number of calls inside a procedure, including recursive calls // Mulang count does not count recursive calls -export const countCalls = (declaration) => +export const countCallsWithin = (declaration) => `within ${toEDLString(declaration)} count(calls) + count(calls ${toEDLString(declaration)})` export const stringify = (id, opts) => diff --git a/tests/unit/services/mulang-expectations-test.js b/tests/unit/services/mulang-expectations-test.js index cdbfd4052..a2ca46fb9 100644 --- a/tests/unit/services/mulang-expectations-test.js +++ b/tests/unit/services/mulang-expectations-test.js @@ -1,6 +1,6 @@ import { module, test } from 'qunit' import { entryPointType } from '../../../utils/blocks' -import { declaresAnyProcedure, doSomething, isUsed, isUsedFromMain, notTooLong, parseExpect, doesNotUseRecursion, stringify, expectationId, isCritical, doesNotUseRecursionId, newExpectation, countCalls } from '../../../utils/expectations' +import { declaresAnyProcedure, doSomething, isUsed, isUsedFromMain, notTooLong, parseExpect, doesNotUseRecursion, stringify, expectationId, isCritical, doesNotUseRecursionId, newExpectation, countCallsWithin } from '../../../utils/expectations' import { procedure, entryPoint, rawSequence, application } from '../../helpers/astFactories' import { setupPBUnitTest, setUpTestWorkspace } from '../../helpers/utils' @@ -132,13 +132,13 @@ module('Unit | Service | Mulang | Expectations', function (hooks) { application('PRIMITIVE')) ], 'Direct recursion with another procedure call should count as recursion') - expectationTestOk('countCalls', newExpectation(`${countCalls(declaration)} = 2`, 'counts', { declaration }), [ + expectationTestOk('countCallsWithin', newExpectation(`${countCallsWithin(declaration)} = 2`, 'counts', { declaration }), [ procedure(declaration, [], application("PROCEDURE2"), application(declaration) ), procedure("PROCEDURE2", []) - ], 'countCalls includes recursive calls') + ], 'countCallsWithin includes recursive calls') function expectationTestOk(expectationName, expectation, astNodes, testName) { expectationTest(expectationName, expectation, astNodes, true, testName)