Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/adds flag to allow skipping some fields on iterative equals #135

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
17 changes: 15 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion bsc-plugin/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
19 changes: 19 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
34 changes: 22 additions & 12 deletions framework/src/source/CommonUtils.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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)*"
Expand Down
5 changes: 4 additions & 1 deletion rooibos.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"activityBar.activeBackground": "#b3b024",
"titleBar.activeBackground": "#b3b024",
"titleBar.activeForeground": "#F9F9F8"
}
},
"cSpell.words": [
"Inifnite"
]
}
}
44 changes: 22 additions & 22 deletions tests/src/source/Assertion.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)


Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/src/source/Common.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace tests

result = Rooibos.Common.eqArray(values, values2)
m.assertEqual(result, expected)

end function

end class
Expand Down
Loading