diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..94f480de --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index bd10dd06..17eff040 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,26 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). -#### [v4.3.1](https://github.com/georgejecook/rooibos/compare/4.2.1...v4.3.1) +#### [v4.4.0](https://github.com/georgejecook/rooibos/compare/4.3.2...v4.4.0) + +- Clutch of fixes [`#134`](https://github.com/georgejecook/rooibos/pull/134) + +#### [4.3.2](https://github.com/georgejecook/rooibos/compare/4.3.1...4.3.2) + +> 19 May 2021 + +- chore: fix docs [`#132`](https://github.com/georgejecook/rooibos/pull/132) +- remove travis [`#130`](https://github.com/georgejecook/rooibos/pull/130) + +#### [4.3.1](https://github.com/georgejecook/rooibos/compare/4.2.1...4.3.1) + +> 19 May 2021 - chore: update docs [`#131`](https://github.com/georgejecook/rooibos/pull/131) - Beta [`#121`](https://github.com/georgejecook/rooibos/pull/121) - add workflow [`4b235e9`](https://github.com/georgejecook/rooibos/commit/4b235e93175fb52763687c3c8f128672565b89d5) - version bump [`a064344`](https://github.com/georgejecook/rooibos/commit/a06434458cf3f25fd84d2c06af677addf1efcfae) -- Update build.yml [`8833bc5`](https://github.com/georgejecook/rooibos/commit/8833bc54afffe9ddb737ec39d943c8321c0b911c) +- version bump [`e048ebf`](https://github.com/georgejecook/rooibos/commit/e048ebff7a2be252abe18b0e816b1d3474cee5ed) #### [4.2.1](https://github.com/georgejecook/rooibos/compare/4.1.1...4.2.1) diff --git a/bsc-plugin/package.json b/bsc-plugin/package.json index 1eb21c44..ca99c141 100644 --- a/bsc-plugin/package.json +++ b/bsc-plugin/package.json @@ -1,6 +1,6 @@ { "name": "rooibos-roku", - "version": "4.3.2", + "version": "4.4.0", "description": "simple, flexible, fun brightscript test framework for roku scenegraph apps - roku brighterscript plugin", "repository": { "type": "git", diff --git a/docs/index.md b/docs/index.md index e1c85414..17f3a59e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -269,6 +269,25 @@ Rooibos provids many assertions to test your code with: If an assertion fails, then the next assertions will not run. +#### Special `__rooibosSkipFields` value + +If an aa has the `__rooibosSkipFields` value set to an associative array of fields, as follows: + +``` +myObj = { + id: "myId" + refToSomethingThatWillLoopForever: myOtherObjPointingToMyObj + __rooibosSkipFields: { + refToSomethingThatWillLoopForever: true + } +} + +``` + +then rooibos will skip comparing `myObj.refToSomethingThatWillLoopForever` and will skip it when printing that object as as string. + +This is useful in some scenarios, such as in maestro framework, where an object, might point to itself (i.e. m and top are the same, and the object has a reference to m.top) + ### Async tests Rooibos runs in sync mode. Due to scenegraph limitations, we can't use observefield. We can workaround this though, using `assertAsyncField` diff --git a/framework/src/source/CommonUtils.bs b/framework/src/source/CommonUtils.bs index 1f573928..7420fdc1 100755 --- a/framework/src/source/CommonUtils.bs +++ b/framework/src/source/CommonUtils.bs @@ -305,7 +305,7 @@ namespace rooibos.Common isFirst = false end if for each key in input - if key <> "__mocks" and key <> "__stubs" + if rooibos.Common.canSafelyIterateAAKey(input, key) text = text + key + ":" + Rooibos.Common.asString(input[key]) end if end for @@ -322,7 +322,7 @@ namespace rooibos.Common end if end for if len(text) > maxLen - text = left(text, maxLen -3) + "..." + text = left(text, maxLen - 3) + "..." end if text = text + "]" return text @@ -571,8 +571,8 @@ namespace rooibos.Common ' * @function ' * @instance ' * @description Compare two arbtrary values to eachother. - ' * @param {Dynamic} Vallue1 - first item to compare - ' * @param {Dynamic} Vallue2 - second item to compare + ' * @param {Dynamic} Value1 - first item to compare + ' * @param {Dynamic} Value2 - second item to compare ' * @returns {boolean} - True if values are equal or False in other case. ' */ function eqValues(Value1, Value2) as dynamic @@ -639,8 +639,8 @@ namespace rooibos.Common ' * @function ' * @instance ' * @description Compare to roAssociativeArray objects for equality. - ' * @param {Dynamic} Vallue1 - first associative array - ' * @param {Dynamic} Vallue2 - second associative array + ' * @param {Dynamic} Value1 - first associative array + ' * @param {Dynamic} Value2 - second associative array ' * @returns {boolean} - True if arrays are equal or False in other case. ' */ function eqAssocArray(Value1, Value2) as dynamic @@ -651,10 +651,10 @@ namespace rooibos.Common return false else for each k in Value1 - if k <> "__mocks" and k <> "__stubs" 'fix infinite loop/box crash when doing equals on an aa with a mock - if not Value2.DoesExist(k) - return false - else + if not Value2.DoesExist(k) + return false + else + if rooibos.common.canSafelyIterateAAKey(Value1, k) and rooibos.common.canSafelyIterateAAKey(Value2, k) v1 = Value1[k] v2 = Value2[k] if not Rooibos.Common.eqValues(v1, v2) @@ -667,14 +667,24 @@ namespace rooibos.Common end if end function + function canSafelyIterateAAKey(aa, key) as boolean + if lcase(key) = "__rooibosskipfields" or key = "__mocks" or key = "__stubs" 'fix infinite loop/box crash when doing equals on an aa with a mock + return false + else if aa.__rooibosSkipFields <> invalid and aa.__rooibosSkipFields.doesExist(key) + return false + end if + + return true + end function + ' /** ' * @memberof module:CommonUtils ' * @name EqArray ' * @function ' * @instance ' * @description Compare to roArray objects for equality. - ' * @param {Dynamic} Vallue1 - first array - ' * @param {Dynamic} Vallue2 - second array + ' * @param {Dynamic} Value1 - first array + ' * @param {Dynamic} Value2 - second array ' * @returns {boolean} - True if arrays are equal or False in other case. ' */ function eqArray(Value1, Value2) as dynamic diff --git a/package-lock.json b/package-lock.json index 2c56d372..06271c4d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "rooibos", - "version": "4.3.2", + "version": "4.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "4.3.2", + "version": "4.4.0", "license": "MIT", "devDependencies": { "brighterscript": "^0.39.0", diff --git a/package.json b/package.json index 55c2b3e7..1a4fc81f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rooibos", - "version": "4.3.2", + "version": "4.4.0", "description": "simple, flexible, fun brightscript test framework for roku scenegraph apps", "files": [ "dist/**/!(manifest)*" diff --git a/rooibos.code-workspace b/rooibos.code-workspace index e7cc867d..2028e1fa 100644 --- a/rooibos.code-workspace +++ b/rooibos.code-workspace @@ -24,6 +24,9 @@ "activityBar.activeBackground": "#b3b024", "titleBar.activeBackground": "#b3b024", "titleBar.activeForeground": "#F9F9F8" - } + }, + "cSpell.words": [ + "Inifnite" + ] } } \ No newline at end of file diff --git a/tests/src/source/Assertion.spec.bs b/tests/src/source/Assertion.spec.bs index fe8042c6..cf84f7dd 100644 --- a/tests/src/source/Assertion.spec.bs +++ b/tests/src/source/Assertion.spec.bs @@ -11,12 +11,12 @@ namespace tests @it("Fail") function _() - assertResult = m.Fail("reason") + m.Fail("reason") isFail = m.currentResult.isFail m.currentResult.Reset() - m.assertFalse(assertResult) + m.assertTrue(isFail) end function @@ -29,11 +29,11 @@ namespace tests @params("test", false) function _(value, expectedAssertResult) - assertResult = m.assertTrue(value) + m.assertTrue(value) isFail = m.currentResult.isFail m.currentResult.Reset() - m.assertEqual(assertResult, expectedAssertResult) + m.assertEqual(isFail, not expectedAssertResult) end function @@ -47,12 +47,12 @@ namespace tests @params("test", false) function _(value, expectedAssertResult) - assertResult = m.assertFalse(value) + m.assertFalse(value) isFail = m.currentResult.isFail m.currentResult.Reset() - m.assertEqual(assertResult, expectedAssertResult) + m.assertEqual(isFail, not expectedAssertResult) end function @@ -79,12 +79,12 @@ namespace tests @params([{ "one": 1 }, { "two": 2 }], [{ "a": 1 }, { "a": 1 }, { "a": 1 }]) function _(expectedAAs, items) - assertResult = m.assertArrayContainsAAs(items, expectedAAs) + m.assertArrayContainsAAs(items, expectedAAs) isFail = m.currentResult.isFail m.currentResult.Reset() - m.assertFalse(assertResult) + m.assertTrue(isFail) end function @@ -99,12 +99,12 @@ namespace tests @params([{ "one": 1, "two": 2 }, { "one": 1 }, { "three": 3 }], [{ "one": 1 }, { "three": 3 }, { "two": 2, "one": 1 }]) function _(expectedAAs, items) - assertResult = m.assertArrayContainsAAs(items, expectedAAs) + m.assertArrayContainsAAs(items, expectedAAs) isFail = m.currentResult.isFail m.currentResult.Reset() - m.assertTrue(assertResult) + m.assertFalse(isFail) end function @@ -146,11 +146,11 @@ namespace tests @params([{ "test": 1 }, { "test": 1 }], "AssociativeArray") function _(values, typeName) - assertResult = m.assertArrayContainsOnlyValuesOfType(values, typeName) + m.assertArrayContainsOnlyValuesOfType(values, typeName) isFail = m.currentResult.isFail m.currentResult.Reset() - m.assertTrue(assertResult) + m.assertFalse(isFail) end function @@ -169,11 +169,11 @@ namespace tests @params([{ "test": 1 }, { "test": 1 }], "Array") function _(values, typeName) - assertResult = m.assertArrayContainsOnlyValuesOfType(values, typeName) + m.assertArrayContainsOnlyValuesOfType(values, typeName) isFail = m.currentResult.isFail m.currentResult.Reset() - m.assertFalse(assertResult) + m.assertTrue(isFail) @@ -193,11 +193,11 @@ namespace tests @params([invalid]) function _(values) - assertResult = m.assertNotEmpty(values) + m.assertNotEmpty(values) isFail = m.currentResult.isFail m.currentResult.Reset() - m.assertTrue(assertResult) + m.assertFalse(isFail) end function @@ -210,11 +210,11 @@ namespace tests @params("") function _(values) - assertResult = m.assertNotEmpty(values) + m.assertNotEmpty(values) isFail = m.currentResult.isFail m.currentResult.Reset() - m.assertFalse(assertResult) + m.assertTrue(isFail) end function @@ -229,11 +229,11 @@ namespace tests @params("") function _(values) - assertResult = m.assertEmpty(values) + m.assertEmpty(values) isFail = m.currentResult.isFail m.currentResult.Reset() - m.assertTrue(assertResult) + m.assertFalse(isFail) end function @@ -250,11 +250,11 @@ namespace tests @params([invalid]) function _(values) - assertResult = m.assertEmpty(values) + m.assertEmpty(values) isFail = m.currentResult.isFail m.currentResult.Reset() - m.assertFalse(assertResult) + m.assertTrue(isFail) end function diff --git a/tests/src/source/Common.spec.bs b/tests/src/source/Common.spec.bs index d5884177..43066f7f 100644 --- a/tests/src/source/Common.spec.bs +++ b/tests/src/source/Common.spec.bs @@ -23,7 +23,6 @@ namespace tests result = Rooibos.Common.eqArray(values, values2) m.assertEqual(result, expected) - end function end class diff --git a/tests/src/source/Infinite-looping-fixes.spec.bs b/tests/src/source/Infinite-looping-fixes.spec.bs new file mode 100644 index 00000000..d697aa59 --- /dev/null +++ b/tests/src/source/Infinite-looping-fixes.spec.bs @@ -0,0 +1,142 @@ +namespace tests + + @suite + class InfiniteLoopingFixes extends Rooibos.BaseTestSuite + + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @describe("AssertEquals") + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + @it("should ignore __mocks on both sides") + function _() + + a = { + __mocks: { + "id": "not" + } + id: "equal" + } + + b = { + __mocks: { + "id": "equal" + } + id: "equal" + } + m.assertEqual(a, b) + + isFail = m.currentResult.isFail + m.currentResult.Reset() + + m.assertFalse(isFail) + end function + + @it("should ignore __stubs on both sides") + function _() + + a = { + __stubs: { + "id": "not" + } + id: "equal" + } + + b = { + __stubs: { + "id": "equal" + } + id: "equal" + } + m.assertEqual(a, b) + + isFail = m.currentResult.isFail + m.currentResult.Reset() + + m.assertFalse(isFail) + end function + + @it("should account for __rooibosSkipFields on both sides - one field") + function _() + + a = { + top: { + "id": "not" + } + __rooibosSkipFields: { top: true } + id: "equal" + } + + b = { + top: { + "id": "equal" + } + __rooibosSkipFields: { top: true } + id: "equal" + } + m.assertEqual(a, b) + + isFail = m.currentResult.isFail + m.currentResult.Reset() + + m.assertFalse(isFail) + end function + + @it("should account for __rooibosSkipFields on both sides - two fields") + function _() + + a = { + top: { + "id": "not" + } + top2: { + "id": "not2" + } + __rooibosSkipFields: { top: true, top2: true } + id: "equal" + } + + b = { + top: { + "id": "equal" + } + top2: { + "id": "equal2" + } + __rooibosSkipFields: { top: true, top2: true } + id: "equal" + } + m.assertEqual(a, b) + + isFail = m.currentResult.isFail + m.currentResult.Reset() + + m.assertFalse(isFail) + end function + + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @describe("asString") + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + @it("ignores special fields in output, and skipped fields") + function _() + + a = { + top: { + "id": "not" + } + __mocks: { + "id": "not" + } + __stubs: { + "id": "not" + } + __rooibosSkipFields: { top: true } + id: "equal" + } + + m.assertEqual(rooibos.common.asString(a), "{id:equal}") + + end function + + end class +end namespace \ No newline at end of file diff --git a/tests/src/source/issue_5_duplicateGroupNames.spec.bs b/tests/src/source/issue_5_duplicateGroupNames.spec.bs index 62807903..c32c534e 100644 --- a/tests/src/source/issue_5_duplicateGroupNames.spec.bs +++ b/tests/src/source/issue_5_duplicateGroupNames.spec.bs @@ -21,12 +21,12 @@ namespace tests @it("called beforeEach and afterEach") function _() - assertResult = m.Fail("reason") + m.Fail("reason") isFail = m.currentResult.isFail m.currentResult.Reset() - m.assertFalse(assertResult) + m.assertTrue(isFail) end function