From 793984443085ea997fcdcd914b527f990b93251d Mon Sep 17 00:00:00 2001 From: Christopher Dwyer-Perkins Date: Wed, 8 Jan 2025 17:00:38 -0400 Subject: [PATCH] More updates --- framework/src/source/BaseTestSuite.bs | 248 ++++++++++++++++++-------- tests/bsconfig.json | 5 +- tests/src/source/Assertion.spec.bs | 159 ++++++++++++++++- tests/src/source/Basic.spec.bs | 1 + 4 files changed, 337 insertions(+), 76 deletions(-) diff --git a/framework/src/source/BaseTestSuite.bs b/framework/src/source/BaseTestSuite.bs index 9a082ff0..3870651e 100644 --- a/framework/src/source/BaseTestSuite.bs +++ b/framework/src/source/BaseTestSuite.bs @@ -1462,7 +1462,6 @@ namespace rooibos else actual = rooibos.common.getTypeWithComponentWrapper(node) expected = `` - if msg = "" msg = `expected type "${rooibos.common.truncateString(actual)}" to be type "${rooibos.common.truncateString(expected)}"` end if @@ -1492,6 +1491,7 @@ namespace rooibos if m.currentResult.isFail return false end if + try if type(node) = "roSGNode" if node.isSubType("mc_Node") @@ -1500,13 +1500,19 @@ namespace rooibos childCount = node.getChildCount() end if if childCount = count - msg = "node items count = " + rooibos.common.asString(count) + "." - m.currentResult.fail(msg, m.currentAssertLineNumber) + actual = rooibos.common.asMultilineString(childCount, true) + expected = rooibos.common.asMultilineString(count, true) + msg = `expected count "${actual}" to not be "${expected}"` + m.currentResult.fail(msg, m.currentAssertLineNumber, actual, expected) return false end if else - msg = "Input value is not an node." - m.currentResult.fail(msg, m.currentAssertLineNumber) + actual = rooibos.common.getTypeWithComponentWrapper(node) + expected = `` + if msg = "" + msg = `expected type "${rooibos.common.truncateString(actual)}" to be type "${rooibos.common.truncateString(expected)}"` + end if + m.currentResult.fail(msg, m.currentAssertLineNumber, actual, expected) return false end if return true @@ -1515,7 +1521,6 @@ namespace rooibos m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber) end try return false - end function ' /** @@ -1532,6 +1537,7 @@ namespace rooibos if m.currentResult.isFail return false end if + try if type(node) = "roSGNode" if node.isSubType("mc_Node") @@ -1540,10 +1546,18 @@ namespace rooibos childCount = node.getChildCount() end if if childCount > 0 - msg = "node is not empty." + msg = `expected child count "${childCount}" to be "0"` m.currentResult.fail(msg, m.currentAssertLineNumber) return false end if + else + actual = rooibos.common.getTypeWithComponentWrapper(node) + expected = `` + if msg = "" + msg = `expected type "${rooibos.common.truncateString(actual)}" to be type "${rooibos.common.truncateString(expected)}"` + end if + m.currentResult.fail(msg, m.currentAssertLineNumber, actual, expected) + return false end if return true catch error @@ -1551,7 +1565,6 @@ namespace rooibos m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber) end try return false - end function ' /** @@ -1568,13 +1581,28 @@ namespace rooibos if m.currentResult.isFail return false end if + try if type(node) = "roSGNode" - if node.Count() = 0 - msg = "Array is empty." + if node.isSubType("mc_Node") + childCount = node.length + else + childCount = node.getChildCount() + end if + + if childCount = 0 + msg = `expected child count "${childCount}" to be greater then "0"` m.currentResult.fail(msg, m.currentAssertLineNumber) return false end if + else + actual = rooibos.common.getTypeWithComponentWrapper(node) + expected = `` + if msg = "" + msg = `expected type "${rooibos.common.truncateString(actual)}" to be type "${rooibos.common.truncateString(expected)}"` + end if + m.currentResult.fail(msg, m.currentAssertLineNumber, actual, expected) + return false end if return true catch error @@ -1582,7 +1610,6 @@ namespace rooibos m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber) end try return false - end function ' /** @@ -1600,16 +1627,21 @@ namespace rooibos if m.currentResult.isFail return false end if + try if type(node) = "roSGNode" if not rooibos.common.nodeContains(node, value) - msg = "Node doesn't have the '" + rooibos.common.asString(value, true) + "' value." + msg = `expected "${rooibos.common.truncateString(rooibos.common.getTypeWithComponentWrapper(node, true))}" to contain child "${rooibos.common.truncateString(rooibos.common.getTypeWithComponentWrapper(value, true))}" by reference` m.currentResult.fail(msg, m.currentAssertLineNumber) return false end if else - msg = "Input value is not an Node." - m.currentResult.fail(msg, m.currentAssertLineNumber) + actual = rooibos.common.getTypeWithComponentWrapper(node) + expected = `` + if msg = "" + msg = `expected type "${rooibos.common.truncateString(actual)}" to be type "${rooibos.common.truncateString(expected)}"` + end if + m.currentResult.fail(msg, m.currentAssertLineNumber, actual, expected) return false end if return true @@ -1618,7 +1650,6 @@ namespace rooibos m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber) end try return false - end function ' /** @@ -1639,7 +1670,7 @@ namespace rooibos try if type(node) = "roSGNode" if not rooibos.common.nodeContains(node, value) - msg = "Node doesn't have the '" + rooibos.common.asString(value, true) + "' value." + msg = `expected "${rooibos.common.truncateString(rooibos.common.getTypeWithComponentWrapper(node, true))}" to contain child "${rooibos.common.truncateString(rooibos.common.getTypeWithComponentWrapper(value, true))}" by reference` m.currentResult.fail(msg, m.currentAssertLineNumber) return false else @@ -1648,15 +1679,20 @@ namespace rooibos else childCount = node.getChildCount() end if + if childCount <> 1 - msg = "Node Contains specified value; but other values as well" + msg = `expected child count "${childCount}" to be "1"` m.currentResult.fail(msg, m.currentAssertLineNumber) return false end if end if else - msg = "Input value is not an Node." - m.currentResult.fail(msg, m.currentAssertLineNumber) + actual = rooibos.common.getTypeWithComponentWrapper(node) + expected = `` + if msg = "" + msg = `expected type "${rooibos.common.truncateString(actual)}" to be type "${rooibos.common.truncateString(expected)}"` + end if + m.currentResult.fail(msg, m.currentAssertLineNumber, actual, expected) return false end if return true @@ -1687,13 +1723,17 @@ namespace rooibos try if type(node) = "roSGNode" if rooibos.common.nodeContains(node, value) - msg = "Node has the '" + rooibos.common.asString(value, true) + "' value." + msg = `expected "${rooibos.common.truncateString(rooibos.common.getTypeWithComponentWrapper(node, true))}" to not contain child "${rooibos.common.truncateString(rooibos.common.getTypeWithComponentWrapper(value, true))}" by reference` m.currentResult.fail(msg, m.currentAssertLineNumber) return false end if else - msg = "Input value is not an Node." - m.currentResult.fail(msg, m.currentAssertLineNumber) + actual = rooibos.common.getTypeWithComponentWrapper(node) + expected = `` + if msg = "" + msg = `expected type "${rooibos.common.truncateString(actual)}" to be type "${rooibos.common.truncateString(expected)}"` + end if + m.currentResult.fail(msg, m.currentAssertLineNumber, actual, expected) return false end if return true @@ -1720,36 +1760,56 @@ namespace rooibos if m.currentResult.isFail return false end if + try - if (type(node) = "roSGNode" and rooibos.common.isAssociativeArray(subset)) or (type(node) = "roSGNode" and rooibos.common.isArray(subset)) - isIgnoredFields = rooibos.common.isArray(ignoredFields) - for each key in subset - if key <> "" - if not isIgnoredFields or not rooibos.common.arrayContains(ignoredFields, key) - subsetValue = subset[key] - nodeValue = node[key] - if not rooibos.common.eqValues(nodeValue, subsetValue) - msg = key + ": Expected '" + rooibos.common.asString(subsetValue, true) + "', got '" + rooibos.common.asString(nodeValue, true) + "'" - m.currentResult.fail(msg, m.currentAssertLineNumber) - return false - end if - end if + if not type(node) = "roSGNode" + actual = rooibos.common.getTypeWithComponentWrapper(node) + expected = `` + if msg = "" + msg = `expected type "${rooibos.common.truncateString(actual)}" to be type "${rooibos.common.truncateString(expected)}"` + end if + m.currentResult.fail(msg, m.currentAssertLineNumber, actual, expected) + return false + end if + + if not rooibos.common.isAssociativeArray(subset) + msg = `expected subset "${rooibos.common.truncateString(rooibos.common.asMultilineString(subset, true))}" to be an AssociativeArray` + m.currentResult.fail(msg, m.currentAssertLineNumber) + return false + end if + + isIgnoredFields = rooibos.common.isArray(ignoredFields) + + foundValues = {} + missingValues = {} + for each key in subset + if not isIgnoredFields or not rooibos.common.arrayContains(ignoredFields, key) + subsetValue = subset[key] + nodeValue = node[key] + if rooibos.common.eqValues(nodeValue, subsetValue) + foundValues[key] = subsetValue else - ? "Found empty key!" + missingValues[key] = subsetValue end if - end for - else - msg = "Input value is not an Node." - m.currentResult.fail(msg, m.currentAssertLineNumber) + end if + end for + + if foundValues.count() <> subset.count() + actual = rooibos.common.asMultilineString(foundValues, true) + expected = rooibos.common.asMultilineString(subset, true) + if msg = "" + msg = `expected "${rooibos.common.truncateString(rooibos.common.getTypeWithComponentWrapper(node, true))}" to have properties "${rooibos.common.truncateString(rooibos.common.asMultilineString(missingValues))}"` + end if + m.currentResult.fail(msg, m.currentAssertLineNumber, actual, expected) return false end if return true catch error 'bs:disable-next-line - m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber) + m.currentResult.failCrash(error, error.message) + return false end try return false - end function ' /** @@ -1767,25 +1827,51 @@ namespace rooibos if m.currentResult.isFail return false end if + try - if (type(node) = "roSGNode" and rooibos.common.isAssociativeArray(subset)) or (type(node) = "roSGNode" and rooibos.common.isArray(subset)) - isAA = rooibos.common.isAssociativeArray(subset) - for each item in subset - key = invalid - value = item - if isAA - key = item - value = item[key] - end if + if not type(node) = "roSGNode" + actual = rooibos.common.getTypeWithComponentWrapper(node) + expected = `` + if msg = "" + msg = `expected type "${rooibos.common.truncateString(actual)}" to be type "${rooibos.common.truncateString(expected)}"` + end if + m.currentResult.fail(msg, m.currentAssertLineNumber, actual, expected) + return false + end if + + if rooibos.common.isArray(subset) + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + ' NOTE: Legacy check for children via array support. + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + for each value in subset if rooibos.common.nodeContains(node, value) - msg = "Node has the '" + rooibos.common.asString(value, true) + "' value." + msg = `expected "${rooibos.common.truncateString(rooibos.common.getTypeWithComponentWrapper(node, true))}" to not contain child "${rooibos.common.truncateString(rooibos.common.getTypeWithComponentWrapper(value, true))}" by reference` m.currentResult.fail(msg, m.currentAssertLineNumber) return false end if end for + else if rooibos.common.isAssociativeArray(subset) + foundValues = {} + for each key in subset + subsetValue = subset[key] + nodeValue = node[key] + if rooibos.common.eqValues(nodeValue, subsetValue) + foundValues[key] = subsetValue + end if + end for + + if foundValues.count() > 0 + actual = rooibos.common.asMultilineString(foundValues, true) + expected = rooibos.common.asMultilineString({}, true) + if msg = "" + msg = `expected "${rooibos.common.truncateString(rooibos.common.getTypeWithComponentWrapper(node, true))}" to have not have properties "${rooibos.common.truncateString(rooibos.common.asMultilineString(foundValues))}"` + end if + m.currentResult.fail(msg, m.currentAssertLineNumber, actual, expected) + return false + end if else - msg = "Input value is not an Node." - m.currentResult.fail(msg, m.currentAssertLineNumber) + msg = `expected subset "${rooibos.common.truncateString(rooibos.common.asMultilineString(subset, true))}" to be an AssociativeArray` + m.currentResult.fail(msg, m.currentAssertLineNumber) return false end if return true @@ -1794,7 +1880,6 @@ namespace rooibos m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber) end try return false - end function '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -1817,27 +1902,43 @@ namespace rooibos if m.currentResult.isFail return false end if + try - if rooibos.common.isAssociativeArray(array) and rooibos.common.isAssociativeArray(subset) - isIgnoredFields = rooibos.common.isArray(ignoredFields) - for each key in subset - if key <> "" - if not isIgnoredFields or not rooibos.common.arrayContains(ignoredFields, key) - subsetValue = subset[key] - arrayValue = array[key] - if not rooibos.common.eqValues(arrayValue, subsetValue) - msg = key + ": Expected '" + rooibos.common.asString(subsetValue, true) + "', got '" + rooibos.common.asString(arrayValue, true) + "'" - m.currentResult.fail(msg, m.currentAssertLineNumber) - return false - end if - end if + if not rooibos.common.isAssociativeArray(array) and not rooibos.common.isArray(array) + msg = `expected target "${rooibos.common.truncateString(rooibos.common.asMultilineString(array, true))}" to be an AssociativeArray` + m.currentResult.fail(msg, m.currentAssertLineNumber) + return false + end if + + if not rooibos.common.isAssociativeArray(subset) and not rooibos.common.isArray(subset) + msg = `expected subset "${rooibos.common.truncateString(rooibos.common.asMultilineString(subset, true))}" to be an AssociativeArray` + m.currentResult.fail(msg, m.currentAssertLineNumber) + return false + end if + + isIgnoredFields = rooibos.common.isArray(ignoredFields) + + foundValues = {} + missingValues = {} + for each key in subset + if not isIgnoredFields or not rooibos.common.arrayContains(ignoredFields, key) + subsetValue = subset[key] + nodeValue = array[key] + if rooibos.common.eqValues(nodeValue, subsetValue) + foundValues[key] = subsetValue else - ? "Found empty key!" + missingValues[key] = subsetValue end if - end for - else - msg = "Input values are not an Associative Array." - m.currentResult.fail("Assert failed: " + msg, m.currentAssertLineNumber) + end if + end for + + if foundValues.count() <> subset.count() + actual = rooibos.common.asMultilineString(foundValues, true) + expected = rooibos.common.asMultilineString(subset, true) + if msg = "" + msg = `expected "${rooibos.common.truncateString(rooibos.common.asMultilineString(array, true))}" to have properties "${rooibos.common.truncateString(rooibos.common.asMultilineString(missingValues))}"` + end if + m.currentResult.fail(msg, m.currentAssertLineNumber, actual, expected) return false end if return true @@ -1846,7 +1947,6 @@ namespace rooibos m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber) end try return false - end function diff --git a/tests/bsconfig.json b/tests/bsconfig.json index 08ba2e32..7888644f 100644 --- a/tests/bsconfig.json +++ b/tests/bsconfig.json @@ -33,7 +33,10 @@ "sendHomeOnFinish": false, "keepAppOpen": true, "isGlobalMethodMockingEnabled": true, - "isRecordingCodeCoverage": false + "isRecordingCodeCoverage": false, + "reporters": [ + "mocha" + ] }, "sourceMap": true } \ No newline at end of file diff --git a/tests/src/source/Assertion.spec.bs b/tests/src/source/Assertion.spec.bs index d33cf69f..421bee4a 100644 --- a/tests/src/source/Assertion.spec.bs +++ b/tests/src/source/Assertion.spec.bs @@ -996,10 +996,167 @@ namespace tests @it("fail assertNodeCount on count miss match") function _() node = createObject("roSGNode", "Node") - node.createChildren(10, "Node") + node.createChildren(10, "Group") m.assertNodeCount(node, 5) end function + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @describe("tests assertNodeEmpty fail") + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + @it("fail assertNodeEmpty missing node") + function _() + m.assertNodeEmpty(invalid, 0) + end function + + @it("fail assertNodeEmpty on non-empty node") + function _() + node = createObject("roSGNode", "Node") + node.createChildren(10, "Group") + m.assertNodeEmpty(node) + end function + + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @describe("tests assertNodeNotEmpty fail") + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + @it("fail assertNodeNotEmpty missing node") + function _() + m.assertNodeNotEmpty(invalid) + end function + + @it("fail assertNodeNotEmpty on empty node") + function _() + node = createObject("roSGNode", "Node") + m.assertNodeNotEmpty(node) + end function + + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @describe("tests assertNodeContains fail") + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + @it("fail assertNodeContains missing node") + function _() + m.assertNodeContains(invalid, invalid) + end function + + @it("fail assertNodeContains when child not found") + function _() + node = createObject("roSGNode", "Node") + node.createChildren(10, "Group") + m.assertNodeContains(node, createObject("roSGNode", "Group")) + end function + + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @describe("tests assertNodeContainsOnly fail") + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + @it("fail assertNodeContainsOnly missing node") + function _() + m.assertNodeContainsOnly(invalid, invalid) + end function + + @it("fail assertNodeContainsOnly when child if found but contains other children") + function _() + node = createObject("roSGNode", "Node") + node.createChildren(10, "Group") + m.assertNodeContainsOnly(node, node.getChild(0)) + end function + + @it("fail assertNodeContainsOnly when child is not found") + function _() + node = createObject("roSGNode", "Node") + node.createChildren(1, "Group") + m.assertNodeContainsOnly(node, createObject("roSGNode", "Group")) + end function + + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @describe("tests assertNodeNotContains fail") + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + @it("fail assertNodeNotContains missing node") + function _() + m.assertNodeNotContains(invalid, invalid) + end function + + @it("fail assertNodeNotContains when child is found") + function _() + node = createObject("roSGNode", "Node") + node.createChildren(10, "Group") + m.assertNodeNotContains(node, node.getChild(5)) + end function + + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @describe("tests assertNodeContainsFields fail") + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + @it("fail assertNodeContainsFields missing node") + function _() + m.assertNodeContainsFields(invalid, invalid) + end function + + @it("fail assertNodeContainsFields bad subset value") + function _() + node = createObject("roSGNode", "Node") + m.assertNodeContainsFields(node, []) + end function + + @it("fail assertNodeContainsFields fields are not found") + function _() + node = createObject("roSGNode", "Node") + m.assertNodeContainsFields(node, { "field": "value", "id": "", "focusable": false, "": false }) + end function + + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @describe("tests assertNodeNotContainsFields fail") + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + @it("fail assertNodeNotContainsFields with missing node") + function _() + m.assertNodeNotContainsFields(invalid, []) + end function + + @it("fail assertNodeNotContainsFields with missing subset") + function _() + node = createObject("roSGNode", "Node") + m.assertNodeNotContainsFields(node, invalid) + end function + + @it("fail assertNodeNotContainsFields legacy find child support in array subset") + function _() + node = createObject("roSGNode", "Node") + node.createChildren(10, "Group") + m.assertNodeNotContainsFields(node, [ node.getChild(5) ]) + end function + + @it("fail assertNodeNotContainsFields subset AA of fields") + function _() + node = createObject("roSGNode", "Node") + m.assertNodeNotContainsFields(node, { "focusable": false }) + end function + + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @only + @describe("tests assertAAContainsSubset fail") + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + @it("fail assertAAContainsSubset with missing actual AA") + function _() + m.assertAAContainsSubset(invalid, {}) + end function + + @it("fail assertAAContainsSubset with missing subset") + function _() + node = createObject("roSGNode", "Node") + m.assertAAContainsSubset({ one: 1, two: 2, three: 3 }, invalid) + end function + + @it("fail assertAAContainsSubset with subset item not found") + function _() + node = createObject("roSGNode", "Node") + m.assertAAContainsSubset({ one: 1, two: 2, three: 3 }, { three: 4}) + end function + 'ASSERTIONS TO WRITE TESTS FOR! 'This is coming soon! diff --git a/tests/src/source/Basic.spec.bs b/tests/src/source/Basic.spec.bs index 04af20b6..980e81aa 100644 --- a/tests/src/source/Basic.spec.bs +++ b/tests/src/source/Basic.spec.bs @@ -176,6 +176,7 @@ namespace tests @describe("test array string printing") '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + ' TODO: remove or update @it("prints strings for failed array tests - simple") function _() arr1 = [