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

Fixed a bunch of potential crashes due to prop name conflicts with native functions #319

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
51 changes: 35 additions & 16 deletions framework/src/source/rooibos/BaseTestSuite.bs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ namespace rooibos
return false
end if

if not aa.DoesExist(key)
if not aa.ifAssociativeArray.DoesExist(key)
if msg = ""
actual = rooibos.common.asMultilineString(aa, true)
msg = `expected "${rooibos.common.truncateString(actual)}" to have property "${key}"`
Expand Down Expand Up @@ -635,7 +635,7 @@ namespace rooibos
return false
end if

if aa.DoesExist(key)
if aa.ifAssociativeArray.DoesExist(key)
if msg = ""
actual = rooibos.common.asMultilineString(aa, true)
msg = `expected "${rooibos.common.truncateString(actual)}" to not have property "${key}"`
Expand Down Expand Up @@ -688,7 +688,7 @@ namespace rooibos
foundKeys = []
missingKeys = []
for each key in keys
if not aa.DoesExist(key)
if not aa.ifAssociativeArray.DoesExist(key)
missingKeys.push(key)
else
foundKeys.push(key)
Expand Down Expand Up @@ -747,7 +747,7 @@ namespace rooibos

foundKeys = []
for each key in keys
if aa.DoesExist(key)
if aa.ifAssociativeArray.DoesExist(key)
foundKeys.push(formatJson(key))
end if
end for
Expand Down Expand Up @@ -1121,11 +1121,17 @@ namespace rooibos
return false
end if

if array.count() <> count
if rooibos.common.isAssociativeArray(array)
actualCount = array.ifAssociativeArray.count()
else
actualCount = array.count()
end if

if actualCount <> count
if msg = ""
msg = `expected count "${array.Count()}" to be "${count}"`
msg = `expected count "${actualCount}" to be "${count}"`
end if
m.currentResult.fail(msg, m.currentAssertLineNumber, rooibos.common.asMultilineString(array.count(), true), rooibos.common.asMultilineString(count, true))
m.currentResult.fail(msg, m.currentAssertLineNumber, rooibos.common.asMultilineString(actualCount, true), rooibos.common.asMultilineString(count, true))
return false
end if
return true
Expand Down Expand Up @@ -1169,9 +1175,15 @@ namespace rooibos
return false
end if

if array.count() = count
if rooibos.common.isAssociativeArray(array)
actualCount = array.ifAssociativeArray.count()
else
actualCount = array.count()
end if

if actualCount = count
if msg = ""
msg = `expected count "${array.count()}" to not be "${count}"`
msg = `expected count "${actualCount}" to not be "${count}"`
end if
m.currentResult.fail(msg, m.currentAssertLineNumber)
return false
Expand Down Expand Up @@ -1927,7 +1939,7 @@ namespace rooibos
end if
end for

if foundValues.count() <> filteredSubset.count()
if foundValues.ifAssociativeArray.count() <> filteredSubset.ifAssociativeArray.count()
actual = rooibos.common.asMultilineString(foundValues, true)
expected = rooibos.common.asMultilineString(filteredSubset, true)
if msg = ""
Expand Down Expand Up @@ -1997,7 +2009,7 @@ namespace rooibos
end if
end for

if foundValues.count() > 0
if foundValues.ifAssociativeArray.count() > 0
actual = rooibos.common.asMultilineString(foundValues, true)
expected = rooibos.common.asMultilineString({}, true)
if msg = ""
Expand Down Expand Up @@ -2082,7 +2094,7 @@ namespace rooibos
end if
end for

if foundValues.count() <> filteredSubset.count()
if foundValues.ifAssociativeArray.count() <> filteredSubset.ifAssociativeArray.count()
actual = rooibos.common.asMultilineString(foundValues, true)
expected = rooibos.common.asMultilineString(filteredSubset, true)
if msg = ""
Expand Down Expand Up @@ -2528,7 +2540,7 @@ namespace rooibos
throw m.errorToThrow
end if
'bs:disable-next-line
if type(m.returnValue) = "roAssociativeArray" and m.returnValue.doesExist("multiResult")
if type(m.returnValue) = "roAssociativeArray" and m.returnValue.ifAssociativeArray.doesExist("multiResult")
'bs:disable-next-line
returnValues = m.returnValue["multiResult"]
'bs:disable-next-line
Expand Down Expand Up @@ -2561,7 +2573,7 @@ namespace rooibos
function combineFakes(fake, otherFake)
'add on the expected invoked args
lineNumber = m.currentAssertLineNumber
if type(fake.expectedArgs) <> "roAssociativeArray" or not fake.expectedArgs.doesExist("multiInvoke")
if type(fake.expectedArgs) <> "roAssociativeArray" or not fake.expectedArgs.ifAssociativeArray.doesExist("multiInvoke")
currentExpectedArgsArgs = fake.expectedArgs
fake.expectedArgs = {
"multiInvoke": [currentExpectedArgsArgs]
Expand All @@ -2572,7 +2584,7 @@ namespace rooibos
end for

'add on the expected return values
if type(fake.returnValue) <> "roAssociativeArray" or not fake.returnValue.doesExist("multiResult")
if type(fake.returnValue) <> "roAssociativeArray" or not fake.returnValue.ifAssociativeArray.doesExist("multiResult")
currentReturnValue = fake.returnValue
fake.returnValue = {
"multiResult": [currentReturnValue]
Expand Down Expand Up @@ -2613,7 +2625,14 @@ namespace rooibos
else
expectedArgs = mock.expectedArgs
end if
for i = 0 to expectedArgs.count() - 1

if rooibos.common.isAssociativeArray(expectedArgs)
expectedArgsCount = expectedArgs.ifAssociativeArray.count()
else
expectedArgsCount = expectedArgs.count()
end if

for i = 0 to expectedArgsCount - 1
value = invokedArgs[i]
expected = expectedArgs[i]
didNotExpectArg = rooibos.common.isString(expected) and expected = m.invalidValue
Expand Down
12 changes: 6 additions & 6 deletions framework/src/source/rooibos/CommonUtils.bs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ namespace rooibos.common
end if

text = "{" + chr(10)
keys = input.keys()
keys = input.ifAssociativeArray.keys()
keys.sort()
for each key in keys
if rooibos.common.canSafelyIterateAAKey(input, key)
Expand Down Expand Up @@ -413,7 +413,7 @@ namespace rooibos.common
'bs:disable-next-line
isFirst = false
end if
keys = input.keys()
keys = input.ifAssociativeArray.keys()
keys.sort()
for each key in keys
if rooibos.common.canSafelyIterateAAKey(input, key)
Expand Down Expand Up @@ -614,7 +614,7 @@ namespace rooibos.common
compareValue = array[i]

if compareAttribute <> invalid and rooibos.common.isAssociativeArray(compareValue)
compareValue = compareValue.lookupCI(compareAttribute)
compareValue = compareValue.ifAssociativeArray.lookupCI(compareAttribute)
end if

if rooibos.common.eqValues(compareValue, value, callCount + 1)
Expand Down Expand Up @@ -862,14 +862,14 @@ namespace rooibos.common
if not rooibos.common.isAssociativeArray(Value1) or not rooibos.common.isAssociativeArray(Value2)
return false
end if
l1 = Value1.Count()
l2 = Value2.Count()
l1 = Value1.ifAssociativeArray.Count()
l2 = Value2.ifAssociativeArray.Count()

if not l1 = l2
return false
else
for each k in Value1
if not Value2.DoesExist(k)
if not Value2.ifAssociativeArray.DoesExist(k)
return false
else
if rooibos.common.canSafelyIterateAAKey(Value1, k) and rooibos.common.canSafelyIterateAAKey(Value2, k)
Expand Down
61 changes: 60 additions & 1 deletion tests/src/source/Assertion.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ namespace tests
m.assertEqual(obj, obj2)
end function

@it("handles AA with keys properties")
function _()
m.assertEqual({ keys: [1, 2, 3] }, { keys: [1, 2, 3] })
end function

@it("passes with invalid")
function _()
m.assertEqual(invalid, invalid)
Expand Down Expand Up @@ -746,6 +751,12 @@ namespace tests
m.assertAAHasKey(aa, "test")
end function

@it("supports aa with DoesExist property")
function _()
aa = { "DoesExist": 1 }
m.assertAAHasKey(aa, "DoesExist")
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("AssertAANotHasKey tests")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -756,6 +767,12 @@ namespace tests
m.assertAANotHasKey(aa, "missing")
end function

@it("supports aa with DoesExist property")
function _()
aa = { "DoesExist": 1 }
m.assertAANotHasKey(aa, "missing")
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("AssertAAHasKeys tests")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -766,6 +783,12 @@ namespace tests
m.assertAAHasKeys(aa, ["one", "two"])
end function

@it("supports aa with DoesExist property")
function _()
aa = { "one": 1, "two": 2, "three": 3, "DoesExist": true }
m.assertAAHasKeys(aa, ["one", "two"])
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("AssertAANotHasKeys tests")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -776,6 +799,12 @@ namespace tests
m.assertAANotHasKeys(aa, ["four", "five"])
end function

@it("supports aa with DoesExist property")
function _()
aa = { "one": 1, "two": 2, "three": 3, "DoesExist": true }
m.assertAANotHasKeys(aa, ["four", "five"])
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("AssertArrayContains tests")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down Expand Up @@ -958,6 +987,11 @@ namespace tests
m.assertArrayCount({ one: 1, two: 2 }, 2)
end function

@it("supports aa with count property")
function _()
m.assertArrayCount({ one: 1, count: 2 }, 2)
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("AssertArrayNotCount tests")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -972,6 +1006,11 @@ namespace tests
m.assertArrayNotCount({ one: 1, two: 2 }, 1)
end function

@it("supports aa with count property")
function _()
m.assertArrayNotCount({ one: 1, count: 2 }, 1)
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("AssertEmpty tests")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down Expand Up @@ -1243,6 +1282,13 @@ namespace tests
m.assertNodeContainsFields(node, { "id": "", "focusable": false })
end function

@it("supports node with count property")
function _()
node = createObject("roSGNode", "Node")
node.update({ count: "not a function" }, true)
m.assertNodeContainsFields(node, { "id": "", "focusable": false, count: "not a function" })
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("AssertNodeNotContainsFields tests")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -1260,6 +1306,13 @@ namespace tests
m.assertNodeNotContainsFields(node, { "focusable": true })
end function

@it("supports node with count property")
function _()
node = createObject("roSGNode", "Node")
node.update({ count: "not a function" }, true)
m.assertNodeNotContainsFields(node, { "count": true })
end function

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("AssertAAContainsSubset tests")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -1271,6 +1324,12 @@ namespace tests
m.assertAAContainsSubset({ one: 1, two: 2, three: 3 }, { one: 1, two: 2 })
end function

@it("supports aa with count property")
function _()
node = createObject("roSGNode", "Node")
m.assertAAContainsSubset({ one: 1, two: 2, three: 3, count: false }, { one: 1, two: 2, count: false })
end function


'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@describe("tests global is present on testSuite")
Expand Down Expand Up @@ -1305,7 +1364,7 @@ namespace tests
@it("multi return values")
function _()
obj = {}
m.expect(obj, "mockMethod", 5, invalid, { "multiResult": ["one", 2, invalid, "last"] }, true)
m.expect(obj, "mockMethod", 5, invalid, { "multiResult": ["one", 2, invalid, "last"], doesExist: "not a function" }, true)

result = obj.mockMethod()
m.assertEqual(result, "one")
Expand Down
34 changes: 34 additions & 0 deletions tests/src/source/FailedAssertion.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,40 @@ namespace tests
m.assertEqual(obj, obj2)
end function

@it("assertEqual handles actual objects with keys, DoesExist, and count properties")
function _()
obj = {
"mockMethod": invalid
key: "value1"
object: {
"otherKey1": "value"
}
array: [1, 2, 4, 3]
keys: "not a function"
DoesExist: "not a function"
count: "not a function"
}
obj2 = [1, 2, 3]
m.assertEqual(obj, obj2)
end function

@it("assertEqual handles expected objects with keys, DoesExist, and count properties")
function _()
obj = [1, 2, 3]
obj2 = {
"mockMethod": invalid
key: "value1"
object: {
"otherKey1": "value"
}
array: [1, 2, 4, 3]
keys: "not a function"
DoesExist: "not a function"
count: "not a function"
}
m.assertEqual(obj, obj2)
end function

@it("assertEqual fail on object1 vs object1")
function _()
obj = {
Expand Down