From 391b902c82b63a261a73f452879fbde72eb57ae0 Mon Sep 17 00:00:00 2001 From: George Cook Date: Sun, 22 Sep 2019 12:22:51 -0500 Subject: [PATCH] feat: migrate to using brighterscript, via maestro project's compiler --- dist/rooibosDist.brs | 2237 ----------------- docs/Rooibos_TestRunner.brs.html | 2 +- gulpfile.ts | 26 +- package-lock.json | 146 +- package.json | 8 +- .../source/tests/rooibos/rooibosDist.brs | 1438 ++++++----- ...bos_BaseTestSuite.brs => BaseTestSuite.bs} | 866 +++---- ...Rooibos_CommonUtils.brs => CommonUtils.bs} | 177 +- src/{Rooibos_ItGroup.brs => ItGroup.bs} | 19 +- ...bos_ItemGenerator.brs => ItemGenerator.bs} | 47 +- src/{Rooibos.brs => Rooibos.bs} | 46 +- src/Rooibos_TestCase.brs | 37 - ...bos_RuntimeConfig.brs => RuntimeConfig.bs} | 28 +- src/{Rooibos_Stats.brs => Stats.bs} | 29 +- src/TestCase.bs | 50 + src/{Rooibos_TestLogger.brs => TestLogger.bs} | 55 +- src/{Rooibos_TestRunner.brs => TestRunner.bs} | 77 +- ...oibos_TestResult.brs => UnitTestResult.bs} | 29 +- 18 files changed, 1620 insertions(+), 3697 deletions(-) delete mode 100644 dist/rooibosDist.brs rename src/{Rooibos_BaseTestSuite.brs => BaseTestSuite.bs} (69%) rename src/{Rooibos_CommonUtils.brs => CommonUtils.bs} (72%) rename src/{Rooibos_ItGroup.brs => ItGroup.bs} (59%) rename src/{Rooibos_ItemGenerator.brs => ItemGenerator.bs} (82%) rename src/{Rooibos.brs => Rooibos.bs} (78%) delete mode 100644 src/Rooibos_TestCase.brs rename src/{Rooibos_RuntimeConfig.brs => RuntimeConfig.bs} (64%) rename src/{Rooibos_Stats.brs => Stats.bs} (82%) create mode 100644 src/TestCase.bs rename src/{Rooibos_TestLogger.brs => TestLogger.bs} (81%) rename src/{Rooibos_TestRunner.brs => TestRunner.bs} (85%) rename src/{Rooibos_TestResult.brs => UnitTestResult.bs} (52%) diff --git a/dist/rooibosDist.brs b/dist/rooibosDist.brs deleted file mode 100644 index 6d8b4c6f..00000000 --- a/dist/rooibosDist.brs +++ /dev/null @@ -1,2237 +0,0 @@ -'/** -' * rooibos - simple, flexible, fun brihhtscript test framework for roku scenegraph apps -' * @version v3.1.1 -' * @link https://github.com/georgejecook/rooibos#readme -' * @license MIT -' */ -function Rooibos__Init(preTestSetup = invalid, testUtilsDecoratorMethodName = invalid, testSceneName = invalid, nodeContext = invalid) as void - args = {} - if createObject("roAPPInfo").IsDev() <> true then - ? " not running in dev mode! - rooibos tests only support sideloaded builds - aborting" - return - end if - args.testUtilsDecoratorMethodName = testUtilsDecoratorMethodName - args.nodeContext = nodeContext - screen = CreateObject("roSGScreen") - m.port = CreateObject("roMessagePort") - screen.setMessagePort(m.port) - if testSceneName = invalid - testSceneName = "TestsScene" - end if - ? "Starting test using test scene with name TestsScene" ; testSceneName - scene = screen.CreateScene(testSceneName) - scene.id = "ROOT" - screen.show() - m.global = screen.getGlobalNode() - m.global.addFields({ "testsScene": scene }) - if (preTestSetup <> invalid) - preTestSetup(screen) - end if - testId = args.TestId - if (testId = invalid) - testId = "UNDEFINED_TEST_ID" - end if - ? "#########################################################################" - ? "#TEST START : ###" ; testId ; "###" - args.testScene = scene - args.global = m.global - rooibosVersion = "3.1.1" - requiredRooibosPreprocessorVersion = "1.0.0" - if not RBS_CMN_isFunction(RBSFM_getPreprocessorVersion) - versionError = "You are using a rooibos-preprocessor (i.e. rooibos-cli) version older than 1.0.0 - please update to " + requiredRooibosPreprocessorVersion - else - if RBSFM_getPreprocessorVersion() = requiredRooibosPreprocessorVersion - versionError = "" - else - versionError = "Your rooibos-preprocessor (i.e. rooibos-cli) version '" + RBSFM_getPreprocessorVersion() + "' is not compatible with rooibos version " + rooibosVersion + ". Please upgrade your rooibos-cli to version " + requiredRooibosPreprocessorVersion - end if - end if - if versionError = "" - ? "######################################################" - ? "" - ? "# rooibos framework version: " ; rooibosVersion - ? "# tests parsed with rooibosC version: " ; rooibosVersion - ? "######################################################" - ? "" - runner = RBS_TR_TestRunner(args) - runner.Run() - while(true) - msg = wait(0, m.port) - msgType = type(msg) - if msgType = "roSGScreenEvent" - if msg.isScreenClosed() - return - end if - end if - end while - else - ? "" - ? "#########################################################" - ? "ERROR - VERSION MISMATCH" - ? versionError - ? "#########################################################" - end if -end function -function BaseTestSuite() as object - this = {} - this.Name = "BaseTestSuite" - this.invalidValue = "#ROIBOS#INVALID_VALUE" ' special value used in mock arguments - this.ignoreValue = "#ROIBOS#IGNORE_VALUE" ' special value used in mock arguments - this.allowNonExistingMethodsOnMocks = true - this.isAutoAssertingMocks = true - this.TestCases = [] - this.AddTest = RBS_BTS_AddTest - this.CreateTest = RBS_BTS_CreateTest - this.GetLegacyCompatibleReturnValue = RBS_BTS_GetLegacyCompatibleReturnValue - this.Fail = RBS_BTS_Fail - this.AssertFalse = RBS_BTS_AssertFalse - this.AssertTrue = RBS_BTS_AssertTrue - this.AssertEqual = RBS_BTS_AssertEqual - this.AssertLike = RBS_BTS_AssertLike - this.AssertNotEqual = RBS_BTS_AssertNotEqual - this.AssertInvalid = RBS_BTS_AssertInvalid - this.AssertNotInvalid = RBS_BTS_AssertNotInvalid - this.AssertAAHasKey = RBS_BTS_AssertAAHasKey - this.AssertAANotHasKey = RBS_BTS_AssertAANotHasKey - this.AssertAAHasKeys = RBS_BTS_AssertAAHasKeys - this.AssertAANotHasKeys = RBS_BTS_AssertAANotHasKeys - this.AssertArrayContains = RBS_BTS_AssertArrayContains - this.AssertArrayNotContains = RBS_BTS_AssertArrayNotContains - this.AssertArrayContainsSubset = RBS_BTS_AssertArrayContainsSubset - this.AssertArrayContainsAAs = RBS_BTS_AssertArrayContainsAAs - this.AssertArrayNotContainsSubset = RBS_BTS_AssertArrayNotContainsSubset - this.AssertArrayCount = RBS_BTS_AssertArrayCount - this.AssertArrayNotCount = RBS_BTS_AssertArrayNotCount - this.AssertEmpty = RBS_BTS_AssertEmpty - this.AssertNotEmpty = RBS_BTS_AssertNotEmpty - this.AssertArrayContainsOnlyValuesOfType = RBS_BTS_AssertArrayContainsOnlyValuesOfType - this.AssertType = RBS_BTS_AssertType - this.AssertSubType = RBS_BTS_AssertSubType - this.AssertNodeCount = RBS_BTS_AssertNodeCount - this.AssertNodeNotCount = RBS_BTS_AssertNodeNotCount - this.AssertNodeEmpty = RBS_BTS_AssertNodeEmpty - this.AssertNodeNotEmpty = RBS_BTS_AssertNodenotEmpty - this.AssertNodeContains = RBS_BTS_AssertNodeContains - this.AssertNodeNotContains = RBS_BTS_AssertNodeNotContains - this.AssertNodeContainsFields = RBS_BTS_AssertNodeContainsFields - this.AssertNodeNotContainsFields = RBS_BTS_AssertNodeNotContainsFields - this.AssertAAContainsSubset = RBS_BTS_AssertAAContainsSubset - this.EqValues = RBS_BTS_EqValues - this.EqAssocArrays = RBS_BTS_EqAssocArray - this.EqArray = RBS_BTS_EqArray - this.Stub = RBS_BTS_Stub - this.Mock = RBS_BTS_Mock - this.AssertMocks = RBS_BTS_AssertMocks - this.CreateFake = RBS_BTS_CreateFake - this.CombineFakes = RBS_BTS_CombineFakes - this.MockFail = RBS_BTS_MockFail - this.CleanMocks = RBS_BTS_CleanMocks - this.CleanStubs = RBS_BTS_CleanStubs - this.ExpectOnce = RBS_BTS_ExpectOnce - this.ExpectNone = RBS_BTS_ExpectNone - this.Expect = RBS_BTS_Expect - this.ExpectOnceOrNone = RBS_BTS_ExpectOnceOrNone - this.MockCallback0 = RBS_BTS_MockCallback0 - this.MockCallback1 = RBS_BTS_MockCallback1 - this.MockCallback2 = RBS_BTS_MockCallback2 - this.MockCallback3 = RBS_BTS_MockCallback3 - this.MockCallback4 = RBS_BTS_MockCallback4 - this.MockCallback5 = RBS_BTS_MockCallback5 - this.StubCallback0 = RBS_BTS_StubCallback0 - this.StubCallback1 = RBS_BTS_StubCallback1 - this.StubCallback2 = RBS_BTS_StubCallback2 - this.StubCallback3 = RBS_BTS_StubCallback3 - this.StubCallback4 = RBS_BTS_StubCallback4 - this.StubCallback5 = RBS_BTS_StubCallback5 - this.pathAsArray_ = RBS_BTS_rodash_pathsAsArray_ - this.g = RBS_BTS_rodash_get_ - return this -end function -sub RBS_BTS_AddTest(name, func,funcName, setup = invalid, teardown = invalid) - m.testCases.Push(m.createTest(name, func, setup, teardown)) -end sub -function RBS_BTS_CreateTest(name, func, funcName, setup = invalid, teardown = invalid ) as object - if (func = invalid) - ? " ASKED TO CREATE TEST WITH INVALID FUNCITON POINTER FOR FUNCTION " ; funcName - end if - return { - Name: name - Func: func - FuncName: funcName - SetUp: setup - TearDown: teardown - } -end function -function RBS_BTS_Fail(msg = "Error" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) -end function -function RBS_BTS_GetLegacyCompatibleReturnValue(value) as object - if (value = true) - if (m.isLegacy = true) - return "" - else - return true - end if - else - if (m.isLegacy = true) - return "ERROR" - else - return false - end if - end if -end function -function RBS_BTS_AssertFalse(expr , msg = "Expression evaluates to true" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if not RBS_CMN_IsBoolean(expr) or expr - m.currentResult.AddResult(msg) - return m.fail(msg) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertTrue(expr , msg = "Expression evaluates to false" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if not RBS_CMN_IsBoolean(expr) or not expr then - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertEqual(first , second , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if not m.eqValues(first, second) - if msg = "" - first_as_string = RBS_CMN_AsString(first) - second_as_string = RBS_CMN_AsString(second) - msg = first_as_string + " != " + second_as_string - end if - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertLike(first , second , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if first <> second - if msg = "" - first_as_string = RBS_CMN_AsString(first) - second_as_string = RBS_CMN_AsString(second) - msg = first_as_string + " != " + second_as_string - end if - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertNotEqual(first , second , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if m.eqValues(first, second) - if msg = "" - first_as_string = RBS_CMN_AsString(first) - second_as_string = RBS_CMN_AsString(second) - msg = first_as_string + " == " + second_as_string - end if - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertInvalid(value , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if value <> invalid - if msg = "" - expr_as_string = RBS_CMN_AsString(value) - msg = expr_as_string + " <> Invalid" - end if - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertNotInvalid(value , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if value = invalid - if msg = "" - expr_as_string = RBS_CMN_AsString(value) - msg = expr_as_string + " = Invalid" - end if - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertAAHasKey(array , key , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) - if not array.DoesExist(key) - if msg = "" - msg = "Array doesn't have the '" + key + "' key." - end if - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "Input value is not an Associative Array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertAANotHasKey(array , key , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) - if array.DoesExist(key) - if msg = "" - msg = "Array has the '" + key + "' key." - end if - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "Input value is not an Associative Array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertAAHasKeys(array , keys , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsArray(keys) - for each key in keys - if not array.DoesExist(key) - if msg = "" - msg = "Array doesn't have the '" + key + "' key." - end if - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - end for - else - msg = "Input value is not an Associative Array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertAANotHasKeys(array , keys , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsArray(keys) - for each key in keys - if array.DoesExist(key) - if msg = "" - msg = "Array has the '" + key + "' key." - end if - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - end for - else - msg = "Input value is not an Associative Array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertArrayContains(array , value , key = invalid , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) - if not RBS_CMN_ArrayContains(array, value, key) - msg = "Array doesn't have the '" + RBS_CMN_AsString(value) + "' value." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "Input value is not an Array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertArrayContainsAAs(array , values , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if not RBS_CMN_IsArray(values) - msg = "values to search for are not an Array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - if RBS_CMN_IsArray(array) - for each value in values - isMatched = false - if not RBS_CMN_IsAssociativeArray(value) - msg = "Value to search for was not associativeArray "+ RBS_CMN_AsString(value) - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - for each item in array - if (RBS_CMN_IsAssociativeArray(item)) - isValueMatched = true - for each key in value - fieldValue = value[key] - itemValue = item[key] - if (not m.EqValues(fieldValue, itemValue)) - isValueMatched = false - exit for - end if - end for - if (isValueMatched) - isMatched = true - exit for - end if - end if - end for ' items in array - if not isMatched - msg = "array missing value: "+ RBS_CMN_AsString(value) - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - end for 'values to match - else - msg = "Input value is not an Array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertArrayNotContains(array , value , key = invalid , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) - if RBS_CMN_ArrayContains(array, value, key) - msg = "Array has the '" + RBS_CMN_AsString(value) + "' value." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "Input value is not an Array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertArrayContainsSubset(array , subset , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if (RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsAssociativeArray(subset)) or (RBS_CMN_IsArray(array) and RBS_CMN_IsArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) - for each item in subset - key = invalid - value = item - if isAA - key = item - value = subset[key] - end if - if not RBS_CMN_ArrayContains(array, value, key) - msg = "Array doesn't have the '" + RBS_CMN_AsString(value) + "' value." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - end for - else - msg = "Input value is not an Array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertArrayNotContainsSubset(array , subset , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if (RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsAssociativeArray(subset)) or (RBS_CMN_IsArray(array) and RBS_CMN_IsArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) - for each item in subset - key = invalid - value = item - if isAA - key = item - value = item[key] - end if - if RBS_CMN_ArrayContains(array, value, key) - msg = "Array has the '" + RBS_CMN_AsString(value) + "' value." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - end for - else - msg = "Input value is not an Array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertArrayCount(array , count , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) - if array.Count() <> count - msg = "Array items count " + RBS_CMN_AsString(array.Count()) + " <> " + RBS_CMN_AsString(count) + "." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "Input value is not an Array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertArrayNotCount(array , count , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) - if array.Count() = count - msg = "Array items count = " + RBS_CMN_AsString(count) + "." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "Input value is not an Array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertEmpty(item , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(item) or RBS_CMN_IsArray(item) - if item.Count() > 0 - msg = "Array is not empty." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else if (RBS_CMN_IsString(item)) - if (RBS_CMN_AsString(item) <> "") - msg = "Input value is not empty." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "AssertEmpty: Input value was not an array or a string" - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertNotEmpty(item , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(item) or RBS_CMN_IsArray(item) - if item.Count() = 0 - msg = "Array is empty." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else if RBS_CMN_IsString(item) - if (item = "") - msg = "Input value is empty." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "Input value is not a string or array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertArrayContainsOnlyValuesOfType(array , typeStr , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if typeStr <> "String" and typeStr <> "Integer" and typeStr <> "Boolean" and typeStr <> "Array" and typeStr <> "AssociativeArray" - msg = "Type must be Boolean, String, Array, Integer, or AssociativeArray" - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) - methodName = "RBS_CMN_Is" + typeStr - typeCheckFunction = RBS_CMN_GetIsTypeFunction(methodName) - if (typeCheckFunction <> invalid) - for each item in array - if not typeCheckFunction(item) - msg = RBS_CMN_AsString(item) + "is not a '" + typeStr + "' type." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - end for - else - msg = "could not find comparator for type '" + typeStr + "' type." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "Input value is not an Array." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_CMN_GetIsTypeFunction(name) - if name = "RBS_CMN_IsFunction" - return RBS_CMN_IsFunction - else if name = "RBS_CMN_IsXmlElement" - return RBS_CMN_IsXmlElement - else if name = "RBS_CMN_IsInteger" - return RBS_CMN_IsInteger - else if name = "RBS_CMN_IsBoolean" - return RBS_CMN_IsBoolean - else if name = "RBS_CMN_IsFloat" - return RBS_CMN_IsFloat - else if name = "RBS_CMN_IsDouble" - return RBS_CMN_IsDouble - else if name = "RBS_CMN_IsLongInteger" - return RBS_CMN_IsLongInteger - else if name = "RBS_CMN_IsNumber" - return RBS_CMN_IsNumber - else if name = "RBS_CMN_IsList" - return RBS_CMN_IsList - else if name = "RBS_CMN_IsArray" - return RBS_CMN_IsArray - else if name = "RBS_CMN_IsAssociativeArray" - return RBS_CMN_IsAssociativeArray - else if name = "RBS_CMN_IsSGNode" - return RBS_CMN_IsSGNode - else if name = "RBS_CMN_IsString" - return RBS_CMN_IsString - else if name = "RBS_CMN_IsDateTime" - return RBS_CMN_IsDateTime - else if name = "RBS_CMN_IsUndefined" - return RBS_CMN_IsUndefined - else - return invalid - end if -end function -function RBS_BTS_AssertType(value , typeStr , msg ="" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(value) <> typeStr - if msg = "" - expr_as_string = RBS_CMN_AsString(value) - msg = expr_as_string + " was not expected type " + typeStr - end if - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertSubType(value , typeStr , msg ="" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(value) <> "roSGNode" - if msg = "" - expr_as_string = RBS_CMN_AsString(value) - msg = expr_as_string + " was not a node, so could not match subtype " + typeStr - end if - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - else if (value.subType() <> typeStr) - if msg = "" - expr_as_string = RBS_CMN_AsString(value) - msg = expr_as_string + "( type : " + value.subType() +") was not of subType " + typeStr - end if - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_EqValues(Value1 , Value2 ) as dynamic - val1Type = type(Value1) - val2Type = type(Value2) - if val1Type = "" or val2Type = "" or val1Type = "" or val2Type = "" - ? "ERROR!!!! - undefined value passed" - return false - end if - if val1Type = "roString" or val1Type = "String" - Value1 = RBS_CMN_AsString(Value1) - else - Value1 = box(Value1) - end if - if val2Type = "roString" or val2Type = "String" - Value2 = RBS_CMN_AsString(Value2) - else - Value2 = box(Value2) - end if - val1Type = type(Value1) - val2Type = type(Value2) - if val1Type = "roFloat" and val2Type = "roInt" - Value2 = box(Cdbl(Value2)) - else if val2Type = "roFloat" and val1Type = "roInt" - Value1 = box(Cdbl(Value1)) - end if - if val1Type <> val2Type - return false - else - valtype = val1Type - if valtype = "roList" - return RBS_BTS_EqArray(Value1, Value2) - else if valtype = "roAssociativeArray" - return RBS_BTS_EqAssocArray(Value1, Value2) - else if valtype = "roArray" - return RBS_BTS_EqArray(Value1, Value2) - else if (valtype = "roSGNode") - if (val2Type <> "roSGNode") - return false - else - return Value1.isSameNode(Value2) - end if - else - return Value1 = Value2 - end if - end if -end function -function RBS_BTS_EqAssocArray(Value1 , Value2 ) as dynamic - l1 = Value1.Count() - l2 = Value2.Count() - if not l1 = l2 - 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 - v1 = Value1[k] - v2 = Value2[k] - if not RBS_BTS_EqValues(v1, v2) - return false - end if - end if - end if - end for - return true - end if -end function -function RBS_BTS_EqArray(Value1 , Value2 ) as dynamic - if not (RBS_CMN_IsArray(Value1)) or not RBS_CMN_IsArray(Value2) then return false - l1 = Value1.Count() - l2 = Value2.Count() - if not l1 = l2 - return false - else - for i = 0 to l1 - 1 - v1 = Value1[i] - v2 = Value2[i] - if not RBS_BTS_EqValues(v1, v2) then - return false - end if - end for - return true - end if -end function -function RBS_BTS_AssertNodeCount(node , count , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(node) = "roSGNode" - if node.getChildCount() <> count - msg = "node items count <> " + RBS_CMN_AsString(count) + ". Received " + RBS_CMN_AsString(node.getChildCount()) - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "Input value is not an node." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertNodeNotCount(node , count , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(node) = "roSGNode" - if node.getChildCount() = count - msg = "node items count = " + RBS_CMN_AsString(count) + "." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "Input value is not an node." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertNodeEmpty(node , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(node) = "roSGNode" - if node.getChildCount() > 0 - msg = "node is not empty." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertNodeNotEmpty(node , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(node) = "roSGNode" - if node.Count() = 0 - msg = "Array is empty." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertNodeContains(node , value , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(node) = "roSGNode" - if not RBS_CMN_NodeContains(node, value) - msg = "Node doesn't have the '" + RBS_CMN_AsString(value) + "' value." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "Input value is not an Node." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertNodeContainsOnly(node , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(node) = "roSGNode" - if not RBS_CMN_NodeContains(node, value) - msg = "Node doesn't have the '" + RBS_CMN_AsString(value) + "' value." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - else if node.getChildCount() <> 1 - msg = "Node Contains speicified value; but other values as well" - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "Input value is not an Node." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertNodeNotContains(node , value , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(node) = "roSGNode" - if RBS_CMN_NodeContains(node, value) - msg = "Node has the '" + RBS_CMN_AsString(value) + "' value." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - else - msg = "Input value is not an Node." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertNodeContainsFields(node , subset , ignoredFields=invalid, msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if ( type(node) = "roSGNode" and RBS_CMN_IsAssociativeArray(subset)) or ( type(node) = "roSGNode" and RBS_CMN_IsArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) - isIgnoredFields = RBS_CMN_IsArray(ignoredFields) - for each key in subset - if (key <> "") - if (not isIgnoredFields or not RBS_CMN_ArrayContains(ignoredFields, key)) - subsetValue = subset[key] - nodeValue = node[key] - if not m.eqValues(nodeValue, subsetValue) - msg = key + ": Expected '" + RBS_CMN_AsString(subsetValue) + "', got '" + RBS_CMN_AsString(nodeValue) + "'" - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - end if - else - ? "Found empty key!" - end if - end for - else - msg = "Input value is not an Node." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertNodeNotContainsFields(node , subset , msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if ( type(node) = "roSGNode" and RBS_CMN_IsAssociativeArray(subset)) or ( type(node) = "roSGNode" and RBS_CMN_IsArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) - for each item in subset - key = invalid - value = item - if isAA - key = item - value = item[key] - end if - if RBS_CMN_NodeContains(node, value, key) - msg = "Node has the '" + RBS_CMN_AsString(value) + "' value." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - end for - else - msg = "Input value is not an Node." - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_AssertAAContainsSubset(array , subset , ignoredFields = invalid, msg = "" ) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if (RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsAssociativeArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) - isIgnoredFields = RBS_CMN_IsArray(ignoredFields) - for each key in subset - if (key <> "") - if (not isIgnoredFields or not RBS_CMN_ArrayContains(ignoredFields, key)) - subsetValue = subset[key] - arrayValue = array[key] - if not m.eqValues(arrayValue, subsetValue) - msg = key + ": Expected '" + RBS_CMN_AsString(subsetValue) + "', got '" + RBS_CMN_AsString(arrayValue) + "'" - m.currentResult.AddResult(msg) - return m.GetLegacyCompatibleReturnValue(false) - end if - end if - else - ? "Found empty key!" - end if - end for - else - msg = "Input values are not an Associative Array." - return m.GetLegacyCompatibleReturnValue(false) - end if - m.currentResult.AddResult("") - return m.GetLegacyCompatibleReturnValue(true) -end function -function RBS_BTS_Stub(target, methodName, returnValue = invalid, allowNonExistingMethods = false) as object - if (type(target) <> "roAssociativeArray") - m.Fail("could not create Stub provided target was null") - return {} - end if - if (m.stubs =invalid) - m.__stubId = -1 - m.stubs = {} - end if - m.__stubId++ - if (m.__stubId > 5) - ? "ERROR ONLY 6 STUBS PER TEST ARE SUPPORTED!!" - return invalid - end if - id = stri(m.__stubId).trim() - fake = m.CreateFake(id, target, methodName, 1, invalid, returnValue) - m.stubs[id] = fake - allowNonExisting = m.allowNonExistingMethodsOnMocks = true or allowNonExistingMethods - isMethodPresent = type(target[methodName]) = "Function" or type(target[methodName]) = "roFunction" - if (isMethodPresent or allowNonExisting) - target[methodName] = m["StubCallback" + id] - target.__stubs = m.stubs - if (not isMethodPresent) - ? "WARNING - stubbing call " ; methodName; " which did not exist on target object" - end if - else - ? "ERROR - could not create Stub : method not found "; target ; "." ; methodName - end if - return fake -end function -function RBS_BTS_ExpectOnce(target, methodName, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object - return m.Mock(target, methodName, 1, expectedArgs, returnValue, allowNonExistingMethods) -end function -function RBS_BTS_ExpectOnceOrNone(target, methodName, isExpected, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object - if isExpected - return m.ExpectOnce(target, methodName, expectedArgs, returnValue, allowNonExistingMethods) - else - return m.ExpectNone(target, methodName, allowNonExistingMethods) - end if -end function -function RBS_BTS_ExpectNone(target, methodName, allowNonExistingMethods = false) as object - return m.Mock(target, methodName, 0, invalid, invalid, allowNonExistingMethods) -end function -function RBS_BTS_Expect(target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object - return m.Mock(target, methodName, expectedInvocations, expectedArgs, returnValue, allowNonExistingMethods) -end function -function RBS_BTS_Mock(target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object - if not RBS_CMN_IsAssociativeArray(target) - m.Fail("mock args: target was not an AA") - else if not RBS_CMN_IsString(methodName) - m.Fail("mock args: methodName was not a string") - else if not RBS_CMN_IsNumber(expectedInvocations) - m.Fail("mock args: expectedInvocations was not an int") - else if not RBS_CMN_IsArray(expectedArgs) and RBS_CMN_IsValid(expectedArgs) - m.Fail("mock args: expectedArgs was not invalid or an array of args") - else if RBS_CMN_IsUndefined(expectedArgs) - m.Fail("mock args: expectedArgs undefined") - end if - if m.currentResult.isFail - ? "ERROR: "; m.currentResult.messages[m.currentResult.currentAssertIndex - 1] - return {} - end if - if (m.mocks = invalid) - m.__mockId = -1 - m.__mockTargetId = -1 - m.mocks = {} - end if - fake = invalid - if not target.doesExist("__rooibosTargetId") - m.__mockTargetId++ - target["__rooibosTargetId"] = m.__mockTargetId - end if - for i = 0 to m.__mockId - id = stri(i).trim() - mock = m.mocks[id] - if mock <> invalid and mock.methodName = methodName and mock.target.__rooibosTargetId = target.__rooibosTargetId - fake = mock - exit for - end if - end for - if fake = invalid - m.__mockId++ - id = stri(m.__mockId).trim() - if (m.__mockId > 6) - ? "ERROR ONLY 6 MOCKS PER TEST ARE SUPPORTED!! you're on # " ; m.__mockId - ? " Method was " ; methodName - return invalid - end if - fake = m.CreateFake(id, target, methodName, expectedInvocations, expectedArgs, returnValue) - m.mocks[id] = fake 'this will bind it to m - allowNonExisting = m.allowNonExistingMethodsOnMocks = true or allowNonExistingMethods - isMethodPresent = type(target[methodName]) = "Function" or type(target[methodName]) = "roFunction" - if (isMethodPresent or allowNonExisting) - target[methodName] = m["MockCallback" + id] - target.__mocks = m.mocks - if (not isMethodPresent) - ? "WARNING - mocking call " ; methodName; " which did not exist on target object" - end if - else - ? "ERROR - could not create Mock : method not found "; target ; "." ; methodName - end if - else - m.CombineFakes(fake, m.CreateFake(id, target, methodName, expectedInvocations, expectedArgs, returnValue)) - end if - return fake -end function -function RBS_BTS_CreateFake(id, target, methodName, expectedInvocations = 1, expectedArgs =invalid, returnValue=invalid ) as object - expectedArgsValues = [] - hasArgs = RBS_CMN_IsArray(expectedArgs) - if (hasArgs) - defaultValue = m.invalidValue - else - defaultValue = m.ignoreValue - expectedArgs = [] - end if - for i = 0 to 9 - if (hasArgs and expectedArgs.count() > i) - value = expectedArgs[i] - if not RBS_CMN_IsUndefined(value) - expectedArgsValues.push(expectedArgs[i]) - else - expectedArgsValues.push("#ERR-UNDEFINED!") - end if - else - expectedArgsValues.push(defaultValue) - end if - end for - fake = { - id : id, - target: target, - methodName: methodName, - returnValue: returnValue, - isCalled: false, - invocations: 0, - invokedArgs: [invalid, invalid, invalid, invalid, invalid, invalid, invalid, invalid, invalid], - expectedArgs: expectedArgsValues, - expectedInvocations: expectedInvocations, - callback: function (arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - if (m.allInvokedArgs = invalid) - m.allInvokedArgs = [] - end if - m.invokedArgs = [arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ] - m.allInvokedArgs.push ([arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ]) - m.isCalled = true - m.invocations++ - if (type(m.returnValue) = "roAssociativeArray" and m.returnValue.doesExist("multiResult")) - returnValues = m.returnValue["multiResult"] - returnIndex = m.invocations -1 - if (type(returnValues) = "roArray" and returnValues.count() > 0) - if returnValues.count() <= m.invocations - returnIndex = returnValues.count() -1 - print "Multi return values all used up - repeating last value" - end if - return returnValues[returnIndex] - else - ? "Multi return value was specified; but no array of results were found" - return invalid - end if - else - return m.returnValue - end if - end function - } - return fake -end function -function RBS_BTS_CombineFakes(fake, otherFake) - if type(fake.expectedArgs) <> "roAssociativeArray" or not fake.expectedArgs.doesExist("multiInvoke") - currentExpectedArgsArgs = fake.expectedArgs - fake.expectedArgs = { - "multiInvoke": [currentExpectedArgsArgs] - } - end if - fake.expectedArgs.multiInvoke.push(otherFake.expectedArgs) - if type(fake.returnValue) <> "roAssociativeArray" or not fake.returnValue.doesExist("multiResult") - currentReturnValue = fake.returnValue - fake.returnValue = { - "multiResult": [currentReturnValue] - } - end if - fake.returnValue.multiResult.push(otherFake.returnValue) - fake.expectedInvocations++ -end function -function RBS_BTS_AssertMocks() as void - if (m.__mockId = invalid or not RBS_CMN_IsAssociativeArray(m.mocks)) - return - end if - lastId = int(m.__mockId) - for each id in m.mocks - mock = m.mocks[id] - methodName = mock.methodName - if (mock.expectedInvocations <> mock.invocations) - m.MockFail(methodName, "Wrong number of calls. (" + stri(mock.invocations).trim() + " / " + stri(mock.expectedInvocations).trim() + ")") - m.CleanMocks() - return - else if mock.expectedInvocations > 0 and (RBS_CMN_IsArray(mock.expectedArgs) or (type(mock.expectedArgs) = "roAssociativeArray" and RBS_CMN_IsArray(mock.expectedArgs.multiInvoke))) - isMultiArgsSupported = type(mock.expectedArgs) = "roAssociativeArray" and RBS_CMN_IsArray(mock.expectedArgs.multiInvoke) - for invocationIndex = 0 to mock.invocations - 1 - invokedArgs = mock.allInvokedArgs[invocationIndex] - if isMultiArgsSupported - expectedArgs = mock.expectedArgs.multiInvoke[invocationIndex] - else - expectedArgs = mock.expectedArgs - end if - for i = 0 to expectedArgs.count() -1 - value = invokedArgs[i] - expected = expectedArgs[i] - didNotExpectArg = RBS_CMN_IsString(expected) and expected = m.invalidValue - if (didNotExpectArg) - expected = invalid - end if - if (not (RBS_CMN_IsString(expected) and expected = m.ignoreValue) and not m.eqValues(value, expected)) - if (expected = invalid) - expected = "[INVALID]" - end if - m.MockFail(methodName, "on Invocation #" + stri(invocationIndex).trim() + ", expected arg #" + stri(i).trim() + " to be '" + RBS_CMN_AsString(expected) + "' got '" + RBS_CMN_AsString(value) + "')") - m.CleanMocks() - return - end if - end for - end for - end if - end for - m.CleanMocks() -end function -function RBS_BTS_CleanMocks() as void - if m.mocks = invalid return - for each id in m.mocks - mock = m.mocks[id] - mock.target.__mocks = invalid - end for - m.mocks = invalid - end function - function RBS_BTS_CleanStubs() as void - if m.stubs = invalid return - for each id in m.stubs - stub = m.stubs[id] - stub.target.__stubs = invalid - end for - m.stubs = invalid - end function - function RBS_BTS_MockFail(methodName, message) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - m.currentResult.AddResult("mock failure on '" + methodName + "' : " + message) - return m.GetLegacyCompatibleReturnValue(false) - end function - function RBS_BTS_StubCallback0(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["0"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_StubCallback1(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["1"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_StubCallback2(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["2"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_StubCallback3(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["3"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_StubCallback4(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["4"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_StubCallback5(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["5"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_MockCallback0(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["0"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_MockCallback1(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["1"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_MockCallback2(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["2"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_MockCallback3(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["3"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_MockCallback4(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["4"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_MockCallback5(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["5"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_rodash_pathsAsArray_(path) - pathRE = CreateObject("roRegex", "\[([0-9]+)\]", "i") - segments = [] - if type(path) = "String" or type(path) = "roString" - dottedPath = pathRE.replaceAll(path, ".\1") - stringSegments = dottedPath.tokenize(".") - for each s in stringSegments - if (Asc(s) >= 48) and (Asc(s) <= 57) - segments.push(s.toInt()) - else - segments.push(s) - end if - end for - else if type(path) = "roList" or type(path) = "roArray" - stringPath = "" - for each s in path - stringPath = stringPath + "." + Box(s).toStr() - end for - segments = m.pathAsArray_(stringPath) - else - segments = invalid - end if - return segments - end function - function RBS_BTS_rodash_get_(aa, path, default=invalid) - if type(aa) <> "roAssociativeArray" and type(aa) <> "roArray" and type(aa) <> "roSGNode" then return default - segments = m.pathAsArray_(path) - if (Type(path) = "roInt" or Type(path) = "roInteger" or Type(path) = "Integer") - path = stri(path).trim() - end if - if segments = invalid then return default - result = invalid - while segments.count() > 0 - key = segments.shift() - if (type(key) = "roInteger") 'it's a valid index - if (aa <> invalid and GetInterface(aa, "ifArray") <> invalid) - value = aa[key] - else if (aa <> invalid and GetInterface(aa, "ifSGNodeChildren") <> invalid) - value = aa.getChild(key) - else if (aa <> invalid and GetInterface(aa, "ifAssociativeArray") <> invalid) - key = tostr(key) - if not aa.doesExist(key) - exit while - end if - value = aa.lookup(key) - else - value = invalid - end if - else - if not aa.doesExist(key) - exit while - end if - value = aa.lookup(key) - end if - if segments.count() = 0 - result = value - exit while - end if - if type(value) <> "roAssociativeArray" and type(value) <> "roArray" and type(value) <> "roSGNode" - exit while - end if - aa = value - end while - if result = invalid then return default - return result - end function -function RBS_CMN_IsXmlElement(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifXMLElement") <> invalid -end function -function RBS_CMN_IsFunction(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifFunction") <> invalid -end function -function RBS_CMN_GetFunction(filename, functionName) as object - if (not RBS_CMN_IsNotEmptyString(functionName)) then return invalid - if (not RBS_CMN_IsNotEmptyString(filename)) then return invalid - mapFunction = RBSFM_getFunctionsForFile(filename) - if mapFunction <> invalid - map = mapFunction() - if (type(map) = "roAssociativeArray") - functionPointer = map[functionName] - return functionPointer - else - return invalid - end if - end if - return invalid -end function -function RBS_CMN_GetFunctionBruteForce(functionName) as object - if (not RBS_CMN_IsNotEmptyString(functionName)) then return invalid - filenames = RBSFM_getFilenames() - for i = 0 to filenames.count() - 1 - filename = filenames[i] - mapFunction = RBSFM_getFunctionsForFile(filename) - if mapFunction <> invalid - map = mapFunction() - if (type(map) = "roAssociativeArray") - functionPointer = map[functionName] - if functionPointer <> invalid - return functionPointer - end if - end if - end if - end for - return invalid -end function -function RBS_CMN_IsBoolean(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifBoolean") <> invalid -end function -function RBS_CMN_IsInteger(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifInt") <> invalid and (Type(value) = "roInt" or Type(value) = "roInteger" or Type(value) = "Integer") -end function -function RBS_CMN_IsFloat(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifFloat") <> invalid -end function -function RBS_CMN_IsDouble(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifDouble") <> invalid -end function -function RBS_CMN_IsLongInteger(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifLongInt") <> invalid -end function -function RBS_CMN_IsNumber(value) as boolean - return RBS_CMN_IsLongInteger(value) or RBS_CMN_IsDouble(value) or RBS_CMN_IsInteger(value) or RBS_CMN_IsFloat(value) -end function -function RBS_CMN_IsList(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifList") <> invalid -end function -function RBS_CMN_IsArray(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifArray") <> invalid -end function -function RBS_CMN_IsAssociativeArray(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifAssociativeArray") <> invalid -end function -function RBS_CMN_IsSGNode(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifSGNodeChildren") <> invalid -end function -function RBS_CMN_IsString(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifString") <> invalid -end function -function RBS_CMN_IsNotEmptyString(value) as boolean - return RBS_CMN_IsString(value) and len(value) > 0 -end function -function RBS_CMN_IsDateTime(value) as boolean - return RBS_CMN_IsValid(value) and (GetInterface(value, "ifDateTime") <> invalid or Type(value) = "roDateTime") -end function -function RBS_CMN_IsValid(value) as boolean - return not RBS_CMN_IsUndefined(value) and value <> invalid -end function -function RBS_CMN_IsUndefined(value) as boolean - return type(value) = "" or Type(value) = "" -end function -function RBS_CMN_ValidStr(obj) as string - if obj <> invalid and GetInterface(obj, "ifString") <> invalid - return obj - else - return "" - end if -end function -function RBS_CMN_AsString(input) as string - if RBS_CMN_IsValid(input) = false - return "" - else if RBS_CMN_IsString(input) - return input - else if RBS_CMN_IsInteger(input) or RBS_CMN_IsLongInteger(input) or RBS_CMN_IsBoolean(input) - return input.ToStr() - else if RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) - return Str(input).Trim() - else if type(input) = "roSGNode" - return "Node(" + input.subType() + ")" - else if type(input) = "roAssociativeArray" - isFirst = true - text = "{" - if (not isFirst) - text += "," - isFirst = false - end if - for each key in input - if key <> "__mocks" and key <> "__stubs" - text += key + ":" + RBS_CMN_AsString(input[key]) - end if - end for - text += "}" - return text - else - return "" - end if -end function -function RBS_CMN_AsInteger(input) as integer - if RBS_CMN_IsValid(input) = false - return 0 - else if RBS_CMN_IsString(input) - return input.ToInt() - else if RBS_CMN_IsInteger(input) - return input - else if RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) or RBS_CMN_IsLongInteger(input) - return Int(input) - else - return 0 - end if -end function -function RBS_CMN_AsLongInteger(input) as longinteger - if RBS_CMN_IsValid(input) = false - return 0 - else if RBS_CMN_IsString(input) - return RBS_CMN_AsInteger(input) - else if RBS_CMN_IsLongInteger(input) or RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) or RBS_CMN_IsInteger(input) - return input - else - return 0 - end if -end function -function RBS_CMN_AsFloat(input) as float - if RBS_CMN_IsValid(input) = false - return 0.0 - else if RBS_CMN_IsString(input) - return input.ToFloat() - else if RBS_CMN_IsInteger(input) - return (input / 1) - else if RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) or RBS_CMN_IsLongInteger(input) - return input - else - return 0.0 - end if -end function -function RBS_CMN_AsDouble(input) as double - if RBS_CMN_IsValid(input) = false - return 0.0 - else if RBS_CMN_IsString(input) - return RBS_CMN_AsFloat(input) - else if RBS_CMN_IsInteger(input) or RBS_CMN_IsLongInteger(input) or RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) - return input - else - return 0.0 - end if -end function -function RBS_CMN_AsBoolean(input) as boolean - if RBS_CMN_IsValid(input) = false - return false - else if RBS_CMN_IsString(input) - return LCase(input) = "true" - else if RBS_CMN_IsInteger(input) or RBS_CMN_IsFloat(input) - return input <> 0 - else if RBS_CMN_IsBoolean(input) - return input - else - return false - end if -end function -function RBS_CMN_AsArray(value) as object - if RBS_CMN_IsValid(value) - if not RBS_CMN_IsArray(value) - return [value] - else - return value - end if - end if - return [] -end function -function RBS_CMN_IsNullOrEmpty(value) as boolean - if RBS_CMN_IsString(value) - return Len(value) = 0 - else - return not RBS_CMN_IsValid(value) - end if -end function -function RBS_CMN_FindElementIndexInArray(array , value , compareAttribute = invalid , caseSensitive = false) as integer - if RBS_CMN_IsArray(array) - for i = 0 to RBS_CMN_AsArray(array).Count() - 1 - compareValue = array[i] - if compareAttribute <> invalid and RBS_CMN_IsAssociativeArray(compareValue) - compareValue = compareValue.LookupCI(compareAttribute) - end if - if RBS_BTS_EqValues(compareValue, value) - return i - end if - item = array[i] - next - end if - return -1 -end function -function RBS_CMN_ArrayContains(array , value , compareAttribute = invalid) as boolean - return (RBS_CMN_FindElementIndexInArray(array, value, compareAttribute) > -1) -end function -function RBS_CMN_FindElementIndexInNode(node , value) as integer - if type(node) = "roSGNode" - for i = 0 to node.getChildCount() - 1 - compareValue = node.getChild(i) - if type(compareValue) = "roSGNode" and compareValue.isSameNode(value) - return i - end if - next - end if - return -1 -end function -function RBS_CMN_NodeContains(node , value) as boolean - return (RBS_CMN_FindElementIndexInNode(node, value) > -1) -end function -function RBS_ItG_GetTestCases(group) as object - if (group.hasSoloTests = true) - return group.soloTestCases - else - return group.testCases - end if -end function -function RBS_ItG_GetRunnableTestSuite(group) as object - testCases = RBS_ItG_GetTestCases(group) - runnableSuite = BaseTestSuite() - runnableSuite.name = group.name - runnableSuite.isLegacy = group.isLegacy = true - if group.testCaseLookup = invalid - group.testCaseLookup = {} - end if - for each testCase in testCases - name = testCase.name - if (testCase.isSolo = true) - name += " [SOLO] " - end if - testFunction = RBS_CMN_GetFunction(group.filename, testCase.funcName) - runnableSuite.addTest(name, testFunction, testCase.funcName) - group.testCaseLookup[name] = testCase - end for - runnableSuite.SetUp = RBS_CMN_GetFunction(group.filename, group.setupFunctionName) - runnableSuite.TearDown = RBS_CMN_GetFunction(group.filename, group.teardownFunctionName) - runnableSuite.BeforeEach = RBS_CMN_GetFunction(group.filename, group.beforeEachFunctionName) - runnableSuite.AfterEach = RBS_CMN_GetFunction(group.filename, group.afterEachFunctionName) - return runnableSuite -end function -function ItemGenerator(scheme as object) as object - this = {} - this.getItem = RBS_IG_GetItem - this.getAssocArray = RBS_IG_GetAssocArray - this.getArray = RBS_IG_GetArray - this.getSimpleType = RBS_IG_GetSimpleType - this.getInteger = RBS_IG_GetInteger - this.getFloat = RBS_IG_GetFloat - this.getString = RBS_IG_GetString - this.getBoolean = RBS_IG_GetBoolean - if not RBS_CMN_IsValid(scheme) - return invalid - end if - return this.getItem(scheme) -end function -function RBS_IG_GetItem(scheme as object) as object - item = invalid - if RBS_CMN_IsAssociativeArray(scheme) - item = m.getAssocArray(scheme) - else if RBS_CMN_IsArray(scheme) - item = m.getArray(scheme) - else if RBS_CMN_IsString(scheme) - item = m.getSimpleType(lCase(scheme)) - end if - return item -end function -function RBS_IG_GetAssocArray(scheme as object) as object - item = {} - for each key in scheme - if not item.DoesExist(key) - item[key] = m.getItem(scheme[key]) - end if - end for - return item -end function -function RBS_IG_GetArray(scheme as object) as object - item = [] - for each key in scheme - item.Push(m.getItem(key)) - end for - return item -end function -function RBS_IG_GetSimpleType(typeStr as string) as object - item = invalid - if typeStr = "integer" or typeStr = "int" or typeStr = "roint" - item = m.getInteger() - else if typeStr = "float" or typeStr = "rofloat" - item = m.getFloat() - else if typeStr = "string" or typeStr = "rostring" - item = m.getString(10) - else if typeStr = "boolean" or typeStr = "roboolean" - item = m.getBoolean() - end if - return item -end function -function RBS_IG_GetBoolean() as boolean - return RBS_CMN_AsBoolean(Rnd(2) \ Rnd(2)) -end function -function RBS_IG_GetInteger(seed = 100 as integer) as integer - return Rnd(seed) -end function -function RBS_IG_GetFloat() as float - return Rnd(0) -end function -function RBS_IG_GetString(seed as integer) as string - item = "" - if seed > 0 - stringLength = Rnd(seed) - for i = 0 to stringLength - chType = Rnd(3) - if chType = 1 'Chr(48-57) - numbers - chNumber = 47 + Rnd(10) - else if chType = 2 'Chr(65-90) - Uppercase Letters - chNumber = 64 + Rnd(26) - else 'Chr(97-122) - Lowercase Letters - chNumber = 96 + Rnd(26) - end if - item = item + Chr(chNumber) - end for - end if - return item -end function -function UnitTestRuntimeConfig() - this = {} - this.CreateSuites = RBS_CreateSuites - this.hasSoloSuites = false - this.hasSoloGroups = false - this.hasSoloTests = false - this.suites = this.CreateSuites() - return this -end function -function RBS_CreateSuites() - suites = RBSFM_getTestSuitesForProject() - includedSuites = [] - for i = 0 to suites.count() -1 - suite = suites[i] - if (suite.valid) - if (suite.isSolo) - m.hasSoloSuites = true - end if - if (suite.hasSoloTests = true) - m.hasSoloTests = true - end if - if (suite.hasSoloGroups = true) - m.hasSoloGroups = true - end if - includedSuites.Push(suite) - else - ? "ERROR! suite was not valid - ignoring" - end if - end for - return includedSuites -end function -function RBS_STATS_CreateTotalStatistic() as object - statTotalItem = { - Suites : [] - Time : 0 - Total : 0 - Correct : 0 - Fail : 0 - Ignored : 0 - Crash : 0 - IgnoredTestNames: [] - } - return statTotalItem -end function -function RBS_STATS_MergeTotalStatistic(stat1, stat2) as void - for each suite in stat2.Suites - stat1.Suites.push(suite) - end for - stat1.Time += stat2.Time - stat1.Total += stat2.Total - stat1.Correct += stat2.Correct - stat1.Fail += stat2.Fail - stat1.Crash += stat2.Crash - stat1.Ignored += stat2.Ignored - stat1.IgnoredTestNames.append(stat2.IgnoredTestNames) -end function -function RBS_STATS_CreateSuiteStatistic(name as string) as object - statSuiteItem = { - Name : name - Tests : [] - Time : 0 - Total : 0 - Correct : 0 - Fail : 0 - Crash : 0 - Ignored : 0 - IgnoredTestNames:[] - } - return statSuiteItem -end function -function RBS_STATS_CreateTestStatistic(name as string, result = "Success" as string, time = 0 as integer, errorCode = 0 as integer, errorMessage = "" as string) as object - statTestItem = { - Name : name - Result : result - Time : time - Error : { - Code : errorCode - Message : errorMessage - } - } - return statTestItem -end function -sub RBS_STATS_AppendTestStatistic(statSuiteObj as object, statTestObj as object) - if RBS_CMN_IsAssociativeArray(statSuiteObj) and RBS_CMN_IsAssociativeArray(statTestObj) - statSuiteObj.Tests.Push(statTestObj) - if RBS_CMN_IsInteger(statTestObj.time) - statSuiteObj.Time = statSuiteObj.Time + statTestObj.Time - end if - statSuiteObj.Total = statSuiteObj.Total + 1 - if lCase(statTestObj.Result) = "success" - statSuiteObj.Correct = statSuiteObj.Correct + 1 - else if lCase(statTestObj.result) = "fail" - statSuiteObj.Fail = statSuiteObj.Fail + 1 - else - statSuiteObj.crash = statSuiteObj.crash + 1 - end if - end if -end sub -sub RBS_STATS_AppendSuiteStatistic(statTotalObj as object, statSuiteObj as object) - if RBS_CMN_IsAssociativeArray(statTotalObj) and RBS_CMN_IsAssociativeArray(statSuiteObj) - statTotalObj.Suites.Push(statSuiteObj) - statTotalObj.Time = statTotalObj.Time + statSuiteObj.Time - if RBS_CMN_IsInteger(statSuiteObj.Total) - statTotalObj.Total = statTotalObj.Total + statSuiteObj.Total - end if - if RBS_CMN_IsInteger(statSuiteObj.Correct) - statTotalObj.Correct = statTotalObj.Correct + statSuiteObj.Correct - end if - if RBS_CMN_IsInteger(statSuiteObj.Fail) - statTotalObj.Fail = statTotalObj.Fail + statSuiteObj.Fail - end if - if RBS_CMN_IsInteger(statSuiteObj.Crash) - statTotalObj.Crash = statTotalObj.Crash + statSuiteObj.Crash - end if - end if -end sub -function UnitTestCase(name as string, func as dynamic, funcName as string, isSolo as boolean, isIgnored as boolean, lineNumber as integer, params = invalid, paramTestIndex =0, paramLineNumber = 0) - this = {} - this.isSolo = isSolo - this.func = func - this.funcName = funcName - this.isIgnored = isIgnored - this.name = name - this.lineNumber = lineNumber - this.paramLineNumber = paramLineNumber - this.assertIndex = 0 - this.assertLineNumberMap = {} - this.AddAssertLine = RBS_TC_AddAssertLine - this.getTestLineIndex = 0 - this.rawParams = params - this.paramTestIndex = paramTestIndex - this.isParamTest = false - this.time = 0 - if (params <> invalid) - this.name += stri(this.paramTestIndex) - end if - return this -end function -function RBS_TC_AddAssertLine(lineNumber as integer) - m.assertLineNumberMap[stri(m.assertIndex).trim()] = lineNumber - m.assertIndex++ -end function -function RBS_TC_GetAssertLine(testCase, index) - if (testCase.assertLineNumberMap.doesExist(stri(index).trim())) - return testCase.assertLineNumberMap[stri(index).trim()] - else - return testCase.lineNumber - end if -end function -function Logger(config) as object - this = {} - this.config = config - this.verbosityLevel = { - basic : 0 - normal : 1 - verbose : 2 - } - this.verbosity = this.config.logLevel - this.PrintStatistic = RBS_LOGGER_PrintStatistic - this.PrintMetaSuiteStart = RBS_LOGGER_PrintMetaSuiteStart - this.PrintSuiteStatistic = RBS_LOGGER_PrintSuiteStatistic - this.PrintTestStatistic = RBS_LOGGER_PrintTestStatistic - this.PrintStart = RBS_LOGGER_PrintStart - this.PrintEnd = RBS_LOGGER_PrintEnd - this.PrintSuiteStart = RBS_LOGGER_PrintSuiteStart - return this -end function -sub RBS_LOGGER_PrintStatistic(statObj as object) - m.PrintStart() - previousfile = invalid - for each testSuite in statObj.Suites - if (not statObj.testRunHasFailures or ((not m.config.showOnlyFailures) or testSuite.fail > 0 or testSuite.crash > 0)) - if (testSuite.metaTestSuite.filePath <> previousfile) - m.PrintMetaSuiteStart(testSuite.metaTestSuite) - previousfile = testSuite.metaTestSuite.filePath - end if - m.PrintSuiteStatistic(testSuite, statObj.testRunHasFailures) - end if - end for - ? "" - m.PrintEnd() - ignoredInfo = RBSFM_getIgnoredTestInfo() - ? "Total = "; RBS_CMN_AsString(statObj.Total); " ; Passed = "; statObj.Correct; " ; Failed = "; statObj.Fail; " ; Ignored = "; ignoredInfo.count - ? " Time spent: "; statObj.Time; "ms" - ? "" - ? "" - if (ignoredInfo.count > 0) - ? "IGNORED TESTS:" - for each ignoredItemName in ignoredInfo.items - print ignoredItemName - end for - end if - if (statObj.ignored > 0) - ? "IGNORED TESTS:" - for each ignoredItemName in statObj.IgnoredTestNames - print ignoredItemName - end for - end if - if (statObj.Total = statObj.Correct) - overrallResult = "Success" - else - overrallResult = "Fail" - end if - ? "RESULT: "; overrallResult -end sub -sub RBS_LOGGER_PrintSuiteStatistic(statSuiteObj as object, hasFailures) - m.PrintSuiteStart(statSuiteObj.Name) - for each testCase in statSuiteObj.Tests - if (not hasFailures or ((not m.config.showOnlyFailures) or testCase.Result <> "Success")) - m.PrintTestStatistic(testCase) - end if - end for - ? " |" -end sub -sub RBS_LOGGER_PrintTestStatistic(testCase as object) - metaTestCase = testCase.metaTestCase - if (LCase(testCase.Result) <> "success") - testChar = "-" - assertIndex = metaTestCase.testResult.failedAssertIndex - locationLine = StrI(RBS_TC_GetAssertLine(metaTestCase,assertIndex)).trim() - else - testChar = "|" - locationLine = StrI(metaTestCase.lineNumber).trim() - end if - locationText = "pkg:/" + testCase.filePath.trim() + "(" + locationLine + ")" - insetText = "" - if (metaTestcase.isParamTest <> true) - messageLine = RBS_LOGGER_FillText(" " + testChar + " |--" + metaTestCase.Name + " : ", ".", 80) - ? messageLine ; testCase.Result ; " (" + stri(metaTestCase.time).trim() +"ms)" - else if ( metaTestcase.paramTestIndex = 0) - name = metaTestCase.Name - if (len(name) > 1 and right(name, 1) = "0") - name = left(name, len(name) - 1) - end if - ? " " + testChar + " |--" + name+ " : " - end if - if (metaTestcase.isParamTest = true) - insetText = " " - messageLine = RBS_LOGGER_FillText(" " + testChar + insetText + " |--" + formatJson(metaTestCase.rawParams) + " : ", ".", 80) - ? messageLine ; testCase.Result ; " (" + stri(metaTestCase.time).trim() +"ms)" - end if - if LCase(testCase.Result) <> "success" - ? " | "; insettext ;" |--Location: "; locationText - if (metaTestcase.isParamTest = true) - ? " | "; insettext ;" |--Param Line: "; StrI(metaTestCase.paramlineNumber).trim() - end if - ? " | "; insettext ;" |--Error Message: "; testCase.Error.Message - end if -end sub -function RBS_LOGGER_FillText(text as string, fillChar = " ", numChars = 40) as string - if (len(text) >= numChars) - text = left(text, numChars - 5) + "..." + fillChar + fillChar - else - numToFill= numChars - len(text) -1 - for i = 0 to numToFill - text += fillChar - end for - end if - return text -end function -sub RBS_LOGGER_PrintStart() - ? "" - ? "[START TEST REPORT]" - ? "" -end sub -sub RBS_LOGGER_PrintEnd() - ? "" - ? "[END TEST REPORT]" - ? "" -end sub -sub RBS_LOGGER_PrintSuiteSetUp(sName as string) - if m.verbosity = m.verbosityLevel.verbose - ? "=================================================================" - ? "=== SetUp "; sName; " suite." - ? "=================================================================" - end if -end sub -sub RBS_LOGGER_PrintMetaSuiteStart(metaTestSuite) - ? metaTestSuite.name; " " ; "pkg:/" ; metaTestSuite.filePath + "(1)" -end sub -sub RBS_LOGGER_PrintSuiteStart(sName as string) - ? " |-" ; sName -end sub -sub RBS_LOGGER_PrintSuiteTearDown(sName as string) - if m.verbosity = m.verbosityLevel.verbose - ? "=================================================================" - ? "=== TearDown "; sName; " suite." - ? "=================================================================" - end if -end sub -sub RBS_LOGGER_PrintTestSetUp(tName as string) - if m.verbosity = m.verbosityLevel.verbose - ? "----------------------------------------------------------------" - ? "--- SetUp "; tName; " test." - ? "----------------------------------------------------------------" - end if -end sub -sub RBS_LOGGER_PrintTestTearDown(tName as string) - if m.verbosity = m.verbosityLevel.verbose - ? "----------------------------------------------------------------" - ? "--- TearDown "; tName; " test." - ? "----------------------------------------------------------------" - end if -end sub -function UnitTestResult() as object - this = {} - this.messages = CreateObject("roArray", 0, true) - this.isFail = false - this.currentAssertIndex = 0 - this.failedAssertIndex = 0 - this.Reset = RBS_TRes_Reset - this.AddResult = RBS_TRes_AddResult - this.GetResult = RBS_TRes_GetResult - return this -end function -function RBS_TRes_Reset() as void - m.isFail = false - m.messages = CreateObject("roArray", 0, true) -end function -function RBS_TRes_AddResult(message as string) as string - if (message <> "") - m.messages.push(message) - if (not m.isFail) - m.failedAssertIndex = m.currentAssertIndex - end if - m.isFail = true - end if - m.currentAssertIndex++ - return message -end function -function RBS_TRes_GetResult() as string - if (m.isFail) - msg = m.messages.peek() - if (msg <> invalid) - return msg - else - return "unknown test failure" - end if - else - return "" - end if -end function -function RBS_TR_TestRunner(args = {}) as object - this = {} - this.testScene = args.testScene - this.nodeContext = args.nodeContext - config = RBSFM_getRuntimeConfig() - if (config = invalid or not RBS_CMN_IsAssociativeArray(config)) - ? "WARNING : specified config is invalid - using default" - config = { - showOnlyFailures: false - failFast: false - } - end if - if (args.showOnlyFailures <> invalid) - config.showOnlyFailures = args.showOnlyFailures = "true" - end if - if (args.failFast <> invalid) - config.failFast = args.failFast = "true" - end if - this.testUtilsDecoratorMethodName = args.testUtilsDecoratorMethodName - this.config = config - this.config.testsDirectory = config.testsDirectory - this.logger = Logger(this.config) - this.global = args.global - this.Run = RBS_TR_Run - return this -end function -sub RBS_TR_Run() - if type(RBSFM_getTestSuitesForProject) <> "Function" - ? " ERROR! RBSFM_getTestSuitesForProject is not found! That looks like you didn't run the preprocessor as part of your test process. Please refer to the docs." - return - end if - totalStatObj = RBS_STATS_CreateTotalStatistic() - m.runtimeConfig = UnitTestRuntimeConfig() - m.runtimeConfig.global = m.global - totalStatObj.testRunHasFailures = false - for each metaTestSuite in m.runtimeConfig.suites - if (m.runtimeConfig.hasSoloTests = true) - if (metaTestSuite.hasSoloTests <> true) - if (m.config.logLevel = 2) - ? "TestSuite " ; metaTestSuite.name ; " Is filtered because it has no solo tests" - end if - goto skipSuite - end if - else if (m.runtimeConfig.hasSoloSuites) - if (metaTestSuite.isSolo <> true) - if (m.config.logLevel = 2) - ? "TestSuite " ; metaTestSuite.name ; " Is filtered due to solo flag" - end if - goto skipSuite - end if - end if - if (metaTestSuite.isIgnored = true) - if (m.config.logLevel = 2) - ? "Ignoring TestSuite " ; metaTestSuite.name ; " Due to Ignore flag" - end if - totalstatobj.ignored ++ - totalStatObj.IgnoredTestNames.push("|-" + metaTestSuite.name + " [WHOLE SUITE]") - goto skipSuite - end if - if (metaTestSuite.isNodeTest = true and metaTestSuite.nodeTestFileName <> "") - ? " +++++RUNNING NODE TEST" - nodeType = metaTestSuite.nodeTestFileName - ? " node type is " ; nodeType - node = m.testScene.CallFunc("Rooibos_CreateTestNode", nodeType) - if (type(node) = "roSGNode" and node.subType() = nodeType) - args = { - "metaTestSuite": metaTestSuite - "testUtilsDecoratorMethodName": m.testUtilsDecoratorMethodName - "config": m.config - "runtimeConfig": m.runtimeConfig - } - nodeStatResults = node.callFunc("Rooibos_RunNodeTests", args) - RBS_STATS_MergeTotalStatistic(totalStatObj, nodeStatResults) - m.testScene.RemoveChild(node) - else - ? " ERROR!! - could not create node required to execute tests for " ; metaTestSuite.name - ? " Node of type " ; nodeType ; " was not found/could not be instantiated" - end if - else - if (metaTestSuite.hasIgnoredTests) - totalStatObj.IgnoredTestNames.push("|-" + metaTestSuite.name) - end if - RBS_RT_RunItGroups(metaTestSuite, totalStatObj, m.testUtilsDecoratorMethodName, m.config, m.runtimeConfig, m.nodeContext) - end if - skipSuite: - end for - m.logger.PrintStatistic(totalStatObj) - if RBS_CMN_IsFunction(RBS_ReportCodeCoverage) - RBS_ReportCodeCoverage() - end if - RBS_TR_SendHomeKeypress() -end sub -sub RBS_RT_RunItGroups(metaTestSuite, totalStatObj, testUtilsDecoratorMethodName, config, runtimeConfig, nodeContext = invalid) - if (testUtilsDecoratorMethodName <> invalid) - testUtilsDecorator = RBS_CMN_GetFunctionBruteForce(testUtilsDecoratorMethodName) - if (not RBS_CMN_IsFunction(testUtilsDecorator)) - ? "[ERROR] Test utils decorator method `" ; testUtilsDecoratorMethodName ;"` was not in scope! for testSuite: " + metaTestSuite.name - end if - end if - for each itGroup in metaTestSuite.itGroups - testSuite = RBS_ItG_GetRunnableTestSuite(itGroup) - if (nodeContext <> invalid) - testSuite.node = nodeContext - testSuite.global = nodeContext.global - testSuite.top = nodeContext.top - end if - if (RBS_CMN_IsFunction(testUtilsDecorator)) - testUtilsDecorator(testSuite) - end if - totalStatObj.Ignored += itGroup.ignoredTestCases.count() - if (itGroup.isIgnored = true) - if (config.logLevel = 2) - ? "Ignoring itGroup " ; itGroup.name ; " Due to Ignore flag" - end if - totalStatObj.ignored += itGroup.testCases.count() - totalStatObj.IgnoredTestNames.push(" |-" + itGroup.name + " [WHOLE GROUP]") - goto skipItGroup - else - if (itGroup.ignoredTestCases.count() > 0) - totalStatObj.IgnoredTestNames.push(" |-" + itGroup.name) - totalStatObj.ignored += itGroup.ignoredTestCases.count() - for each testCase in itGroup.ignoredTestCases - if (testcase.isParamTest <> true) - totalStatObj.IgnoredTestNames.push(" | |--" + testCase.name) - else if (testcase.paramTestIndex = 0) - testCaseName = testCase.Name - if (len(testCaseName) > 1 and right(testCaseName, 1) = "0") - testCaseName = left(testCaseName, len(testCaseName) - 1) - end if - totalStatObj.IgnoredTestNames.push(" | |--" + testCaseName) - end if - end for - end if - end if - if (runtimeConfig.hasSoloTests) - if (itGroup.hasSoloTests <> true) - if (config.logLevel = 2) - ? "Ignoring itGroup " ; itGroup.name ; " Because it has no solo tests" - end if - goto skipItGroup - end if - else if (runtimeConfig.hasSoloGroups) - if (itGroup.isSolo <> true) - goto skipItGroup - end if - end if - if (testSuite.testCases.Count() = 0) - if (config.logLevel = 2) - ? "Ignoring TestSuite " ; itGroup.name ; " - NO TEST CASES" - end if - goto skipItGroup - end if - if RBS_CMN_IsFunction(testSuite.SetUp) - testSuite.SetUp() - end if - RBS_RT_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, runtimeConfig) - if RBS_CMN_IsFunction(testSuite.TearDown) - testSuite.TearDown() - end if - if (totalStatObj.testRunHasFailures = true and config.failFast = true) - exit for - end if - skipItGroup: - end for -end sub -sub RBS_RT_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, runtimeConfig) - suiteStatObj = RBS_STATS_CreateSuiteStatistic(itGroup.Name) - testSuite.global = runtimeConfig.global - for each testCase in testSuite.testCases - metaTestCase = itGroup.testCaseLookup[testCase.Name] - metaTestCase.time = 0 - if (runtimeConfig.hasSoloTests and not metaTestCase.isSolo) - goto skipTestCase - end if - if RBS_CMN_IsFunction(testSuite.beforeEach) - testSuite.beforeEach() - end if - testTimer = CreateObject("roTimespan") - testCaseTimer = CreateObject("roTimespan") - testStatObj = RBS_STATS_CreateTestStatistic(testCase.Name) - testSuite.testCase = testCase.Func - testStatObj.filePath = metaTestSuite.filePath - testStatObj.metaTestCase = metaTestCase - testSuite.currentResult = UnitTestResult() - testStatObj.metaTestCase.testResult = testSuite.currentResult - if (metaTestCase.isParamsValid) - if (metaTestCase.isParamTest) - testCaseParams = [] - for paramIndex = 0 to metaTestCase.rawParams.count() - paramValue = metaTestCase.rawParams[paramIndex] - if type(paramValue) = "roString" and len(paramValue) >= 8 and left(paramValue, 8) = "#RBSNode" - nodeType = "ContentNode" - paramDirectiveArgs = paramValue.split("|") - if paramDirectiveArgs.count() > 1 - nodeType = paramDirectiveArgs[1] - end if - paramValue = createObject("roSGNode", nodeType) - end if - testCaseParams.push(paramValue) - end for - testCaseTimer.mark() - if (metaTestCase.expectedNumberOfParams = 1) - testSuite.testCase(testCaseParams[0]) - else if (metaTestCase.expectedNumberOfParams = 2) - testSuite.testCase(testCaseParams[0], testCaseParams[1]) - else if (metaTestCase.expectedNumberOfParams = 3) - testSuite.testCase(testCaseParams[0], testCaseParams[1], testCaseParams[2]) - else if (metaTestCase.expectedNumberOfParams = 4) - testSuite.testCase(testCaseParams[0], testCaseParams[1], testCaseParams[2], testCaseParams[3]) - else if (metaTestCase.expectedNumberOfParams = 5) - testSuite.testCase(testCaseParams[0], testCaseParams[1], testCaseParams[2], testCaseParams[3], testCaseParams[4]) - else if (metaTestCase.expectedNumberOfParams = 6) - testSuite.testCase(testCaseParams[0], testCaseParams[1], testCaseParams[2], testCaseParams[3], testCaseParams[4], testCaseParams[5]) - end if - metaTestCase.time = testCaseTimer.totalMilliseconds() - else - testCaseTimer.mark() - testSuite.testCase() - metaTestCase.time = testCaseTimer.totalMilliseconds() - end if - else - testSuite.Fail("Could not parse args for test ") - end if - if testSuite.isAutoAssertingMocks = true - testSuite.AssertMocks() - testSuite.CleanMocks() - testSuite.CleanStubs() - end if - runResult = testSuite.currentResult.GetResult() - if runResult <> "" - testStatObj.Result = "Fail" - testStatObj.Error.Code = 1 - testStatObj.Error.Message = runResult - else - testStatObj.Result = "Success" - end if - testStatObj.Time = testTimer.TotalMilliseconds() - RBS_STATS_AppendTestStatistic(suiteStatObj, testStatObj) - if RBS_CMN_IsFunction(testSuite.afterEach) - testSuite.afterEach() - end if - if testStatObj.Result <> "Success" - totalStatObj.testRunHasFailures = true - end if - if testStatObj.Result = "Fail" and config.failFast = true - exit for - end if - skipTestCase: - end for - suiteStatObj.metaTestSuite = metaTestSuite - RBS_STATS_AppendSuiteStatistic(totalStatObj, suiteStatObj) -end sub -sub RBS_TR_SendHomeKeypress() - ut = CreateObject("roUrlTransfer") - ut.SetUrl("http://localhost:8060/keypress/Home") - ut.PostFromString("") -end sub -function Rooibos_RunNodeTests(args) as object - ? " RUNNING NODE TESTS" - totalStatObj = RBS_STATS_CreateTotalStatistic() - RBS_RT_RunItGroups(args.metaTestSuite, totalStatObj, args.testUtilsDecoratorMethodName, args.config, args.runtimeConfig, m) - return totalStatObj -end function -function Rooibos_CreateTestNode(nodeType) as object - node = createObject("roSGNode", nodeType) - if (type(node) = "roSGNode" and node.subType() = nodeType) - m.top.AppendChild(node) - return node - else - ? " Error creating test node of type " ; nodeType - return invalid - end if -end function \ No newline at end of file diff --git a/docs/Rooibos_TestRunner.brs.html b/docs/Rooibos_TestRunner.brs.html index 97de5042..bfea7b70 100644 --- a/docs/Rooibos_TestRunner.brs.html +++ b/docs/Rooibos_TestRunner.brs.html @@ -183,7 +183,7 @@

Rooibos_TestRunner.brs

end if for each itGroup in metaTestSuite.itGroups - testSuite = RBS_ItG_GetRunnableTestSuite(itGroup) + testSuite = RBS_ItG.GetRunnableTestSuite(itGroup) if (nodeContext <> invalid) testSuite.node = nodeContext testSuite.global = nodeContext.global diff --git a/gulpfile.ts b/gulpfile.ts index e3716bde..81864cb2 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -1,5 +1,6 @@ import { series } from "gulp"; -import { RooibosProcessor, createProcessorConfig, ProcessorConfig } from "rooibos-preprocessor"; +import { RooibosProcessor, createProcessorConfig, ProcessorConfig } from "rooibos-cli"; +import { MaestroProjectProcessor, createMaestroConfig } from 'maestro-cli-roku'; const concat = require('gulp-concat'); const gulp = require('gulp'); @@ -9,6 +10,7 @@ const header = require('gulp-header'); const pkg = require('./package.json'); const distDir = 'dist'; const outDir = 'out'; +const buildDir = 'build'; const distFile = `rooibosDist.brs`; const fullDistPath = path.join(distDir, distFile); const fs = require('fs'); @@ -26,7 +28,6 @@ const args = { retainStagingFolder: true }; - export function clean() { const distPath = path.join(distDir, '**'); console.log('Doing a clean at ' + distPath); @@ -39,6 +40,20 @@ function createDirectories() { .pipe(gulp.dest(outDir)); } +export async function compile(cb) { + let config = createMaestroConfig({ + filePattern: ['**/*.bs', '**/*.brs', '**/*.xml'], + sourcePath: `src`, + outputPath: buildDir, + logLevel: 4, + nonCheckedImports: [ + ] + }); + let processor = new MaestroProjectProcessor(config); + await processor.processFiles(); +} + + function squash() { var banner = [`'/**`, `' * ${pkg.name} - ${pkg.description}`, @@ -48,7 +63,7 @@ function squash() { `' */`, ``].join(`\n`); - return gulp.src('./src/*.brs') + return gulp.src('./build/*.brs') .pipe(concat(distFile)) .pipe(rmLines({ 'filters': [/^\s*'/i, /((\r\n|\n|\r)$)|(^(\r\n|\n|\r))|^\s*$/i] @@ -78,7 +93,8 @@ function copyToTests(cb) { /** * This target is used for CI */ -export async function prepareFrameworkTests(cb) { + + export async function prepareFrameworkTests(cb) { await rokuDeploy.prepublishToStaging(args); let config = createProcessorConfig({ @@ -144,7 +160,7 @@ export function updateVersion(cb) { cb(); } -exports.build = series(clean, createDirectories, squash, copyToSamples, copyToTests); +exports.build = series(clean, createDirectories, compile, squash, copyToSamples, copyToTests); exports.runFrameworkTests = series(exports.build, prepareFrameworkTests, zipFrameworkTests, deployFrameworkTests) exports.prePublishFrameworkTests = series(exports.build, prepareFrameworkTests) exports.prePublishFrameworkCodeCoverage = series(exports.build, prepareCodeCoverageTests) diff --git a/package-lock.json b/package-lock.json index 24284d3d..4655c7e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -279,7 +279,7 @@ } }, "arr-union": { - "version": "3.1.1", + "version": "3.1.0", "resolved": "https://registry.npmjs.org/arr-union/-/arr-union-3.1.1.tgz", "integrity": "sha1-45sJrqne+Gao8gbiiK9jkZuuOcQ=", "dev": true @@ -989,20 +989,6 @@ } } }, - "brs": { - "version": "0.14.0", - "resolved": "https://registry.npmjs.org/brs/-/brs-0.14.0.tgz", - "integrity": "sha512-AeUGgzjzJ77uGfjaSZ5scG/Ekfzdiow+UDvZrlaSyso5N2VSXCN1V9NAh9Bz2F1NbwumTlmKCbglIEZ7U5zv2g==", - "dev": true, - "requires": { - "commander": "^2.12.2", - "long": "^3.2.0", - "luxon": "^1.8.3", - "memory-fs": "^0.4.1", - "nanomatch": "^1.2.13", - "p-settle": "^2.1.0" - } - }, "buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.2.1.tgz", @@ -1119,7 +1105,7 @@ "async-each": "^1.0.0", "braces": "^2.3.0", "fsevents": "^1.2.2", - "glob-parent": "^3.1.1", + "glob-parent": "^3.1.0", "inherits": "^2.0.1", "is-binary-path": "^1.0.0", "is-glob": "^4.0.0", @@ -1136,7 +1122,7 @@ "integrity": "sha512-qOhPa/Fj7s6TY8H8esGu5QNpMMQxz79h+urzrNYN6mn+9BnxlDGf5QZ+XeCDsxSjPqsSR56XOZOJmpeurnLMeg==", "dev": true, "requires": { - "arr-union": "^3.1.1", + "arr-union": "^3.1.0", "define-property": "^0.2.5", "isobject": "^3.0.0", "static-extend": "^0.1.1" @@ -2016,13 +2002,13 @@ "dev": true, "requires": { "detect-file": "^1.0.0", - "is-glob": "^3.1.1", + "is-glob": "^3.1.0", "micromatch": "^3.0.4", "resolve-dir": "^1.0.1" }, "dependencies": { "is-glob": { - "version": "3.1.1", + "version": "3.1.0", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-3.1.1.tgz", "integrity": "sha1-e6WuJCF4BKxwcHuWkiVnSGzD6Eo=", "dev": true, @@ -2731,7 +2717,7 @@ } }, "glob-all": { - "version": "3.1.1", + "version": "3.1.0", "resolved": "https://registry.npmjs.org/glob-all/-/glob-all-3.1.1.tgz", "integrity": "sha1-iRPd+17hrHgSZWJBsD1SF8ZLAqs=", "dev": true, @@ -2798,17 +2784,17 @@ } }, "glob-parent": { - "version": "3.1.1", + "version": "3.1.0", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-3.1.1.tgz", "integrity": "sha1-nmr2KZ2NO9K9QEMIMr0RPfkGxa4=", "dev": true, "requires": { - "is-glob": "^3.1.1", + "is-glob": "^3.1.0", "path-dirname": "^1.0.0" }, "dependencies": { "is-glob": { - "version": "3.1.1", + "version": "3.1.0", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-3.1.1.tgz", "integrity": "sha1-e6WuJCF4BKxwcHuWkiVnSGzD6Eo=", "dev": true, @@ -2826,7 +2812,7 @@ "requires": { "extend": "^3.0.0", "glob": "^7.1.1", - "glob-parent": "^3.1.1", + "glob-parent": "^3.1.0", "is-negated-glob": "^1.0.0", "ordered-read-streams": "^1.0.0", "pumpify": "^1.3.5", @@ -3891,7 +3877,7 @@ "dev": true }, "lodash.isarguments": { - "version": "3.1.1", + "version": "3.1.0", "resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.1.tgz", "integrity": "sha1-L1c9hcaiQon/AGY7SRwdM4/zRYo=", "dev": true @@ -3987,6 +3973,27 @@ "integrity": "sha512-+xo7Pj54xwyEzlMdXzDqm60Ewqbn0QqACwfIo6so9M1idUtYQrD7/PHjEFQQmLCBu8wUe2IDC2jrcJJ3Buk4Pw==", "dev": true }, + "maestro-cli-roku": { + "version": "file:../../maestro-cli", + "dev": true, + "requires": { + "adm-zip": "^0.4.13", + "brightscript-language": "^0.2.8", + "commander": "^3.0.1", + "compare-directories": "^0.1.0", + "debug": "^4.1.1", + "dir-compare": "^1.4.0", + "fs-extra": "^5.0.0", + "glob-all": "^3.1.0", + "lodash": "^4.17.15", + "make-dir": "^3.0.0", + "os": "^0.1.1", + "replace-ext": "^1.0.0", + "request-promise": "^4.2.4", + "sax": "^1.2.4", + "splice-string": "^2.0.0" + } + }, "make-error": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz", @@ -5040,6 +5047,27 @@ "uuid": "^3.3.2" } }, + "request-promise": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/request-promise/-/request-promise-4.2.4.tgz", + "integrity": "sha512-8wgMrvE546PzbR5WbYxUQogUnUDfM0S7QIFZMID+J73vdFARkFy+HElj4T+MWYhpXwlLp0EQ8Zoj8xUA0he4Vg==", + "dev": true, + "requires": { + "bluebird": "^3.5.0", + "request-promise-core": "1.1.2", + "stealthy-require": "^1.1.1", + "tough-cookie": "^2.3.3" + } + }, + "request-promise-core": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.2.tgz", + "integrity": "sha512-UHYyq1MO8GsefGEt7EprS8UrXsm1TxEvFUX1IMTuSLU2Rh7fTIdFtl8xD7JiEYiWU2dl+NYAjCTksTehQUxPag==", + "dev": true, + "requires": { + "lodash": "^4.17.11" + } + }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -5126,31 +5154,61 @@ "requires": { "archiver": "^3.0.0", "fs-extra": "^5.0.0", - "glob-all": "^3.1.1", + "glob-all": "^3.1.0", "path": "^0.12.7", "q": "^1.5.1", "request": "^2.88.0" } }, - "rooibos-preprocessor": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/rooibos-preprocessor/-/rooibos-preprocessor-3.1.1.tgz", - "integrity": "sha512-kfQz5lZFiKciNjobrz1wawTO3joCl9B75706jPS2JcH1MlfoGqfw1I5M44dkrmTqJmI7ifI3M8Ng2I2XfgxNdw==", + "rooibos-cli": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/rooibos-cli/-/rooibos-cli-1.0.1.tgz", + "integrity": "sha512-K4afoLW4lwfD8iQCPxputg5l+MfUS6O/leXJ45Dqt9YP5Mac+26qsQHBezN7z10vppwFIggafo6P+6lzD5Yz/A==", "dev": true, "requires": { "babel-cli": "^6.26.0", "brs": "^0.14.0", - "commander": "^2.20.0", + "commander": "^3.0.1", "debug": "^4.1.1", "es2015": "0.0.0", "fs-extra": "^5.0.0", - "glob-all": "^3.1.1", - "lodash": "^4.17.14", + "glob-all": "^3.1.0", + "lodash": "^4.17.15", "replace-ext": "^1.0.0", + "request": "^2.88.0", + "request-promise": "^4.2.4", "splice-string": "^2.0.0", "typescript": "^3.2.2" }, "dependencies": { + "brs": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/brs/-/brs-0.14.0.tgz", + "integrity": "sha512-AeUGgzjzJ77uGfjaSZ5scG/Ekfzdiow+UDvZrlaSyso5N2VSXCN1V9NAh9Bz2F1NbwumTlmKCbglIEZ7U5zv2g==", + "dev": true, + "requires": { + "commander": "^2.12.2", + "long": "^3.2.0", + "luxon": "^1.8.3", + "memory-fs": "^0.4.1", + "nanomatch": "^1.2.13", + "p-settle": "^2.1.0" + }, + "dependencies": { + "commander": { + "version": "2.20.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", + "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", + "dev": true + } + } + }, + "commander": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-3.0.1.tgz", + "integrity": "sha512-UNgvDd+csKdc9GD4zjtkHKQbT8Aspt2jCBqNSPp53vAS0L1tS9sXB2TCEOPHJ7kt9bN/niWkYj8T3RQSoMXdSQ==", + "dev": true + }, "debug": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", @@ -5161,9 +5219,9 @@ } }, "lodash": { - "version": "4.17.14", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.14.tgz", - "integrity": "sha512-mmKYbW3GLuJeX+iGP+Y7Gp1AiGHGbXHCOh/jZmrawMmsE7MS4znI3RL2FsjbqOyMayHInjOeykW7PEajUk1/xw==", + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", "dev": true }, "ms": { @@ -5306,7 +5364,7 @@ "map-cache": "^0.2.2", "source-map": "^0.5.6", "source-map-resolve": "^0.5.0", - "use": "^3.1.1" + "use": "^3.1.0" }, "dependencies": { "define-property": { @@ -5448,7 +5506,7 @@ "dev": true }, "spdx-correct": { - "version": "3.1.1", + "version": "3.1.0", "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.1.tgz", "integrity": "sha512-lr2EZCctC2BNR7j7WzJ2FpDznxky1sjfxvvYEyzxNyb6lZXHODmEoJeFu4JupYlkfha1KZpJyoqiJ7pgA1qq8Q==", "dev": true, @@ -5489,7 +5547,7 @@ } }, "split-string": { - "version": "3.1.1", + "version": "3.1.0", "resolved": "https://registry.npmjs.org/split-string/-/split-string-3.1.1.tgz", "integrity": "sha512-NzNVhJDYpwceVVii8/Hu6DKfD2G+NrQHlS/V/qgv763EYudVwEcMQNxd2lh+0VrUByXN/oJkl5grOhYWvQUYiw==", "dev": true, @@ -5551,6 +5609,12 @@ } } }, + "stealthy-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz", + "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=", + "dev": true + }, "stream-exhaust": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/stream-exhaust/-/stream-exhaust-1.0.2.tgz", @@ -5771,7 +5835,7 @@ "integrity": "sha512-MosTrinKmaAcWgO8tqMjMJB22h+sp3Rd1i4fdoWY4mhBDekOwIAKI/bzmRi7IcbCmjquccYg2gcF6NBkLgr0Tw==", "requires": { "arg": "^4.1.0", - "diff": "^3.1.1", + "diff": "^3.1.0", "make-error": "^1.1.1", "source-map-support": "^0.5.6", "yn": "^3.0.0" @@ -5862,7 +5926,7 @@ "integrity": "sha1-XHHDTLW61dzr4+oM0IIHulqhrqQ=", "dev": true, "requires": { - "arr-union": "^3.1.1", + "arr-union": "^3.1.0", "get-value": "^2.0.6", "is-extendable": "^0.1.1", "set-value": "^0.4.3" diff --git a/package.json b/package.json index a17b81c0..a3df8334 100644 --- a/package.json +++ b/package.json @@ -20,13 +20,17 @@ "gulpclass": "^0.2.0", "ink-docstrap": "1.3.0", "jsdoc": "3.5.5", + "maestro-cli-roku": "file:../../maestro-cli", "minami": "^1.2.3", "roku-deploy": "^2.0.0", - "rooibos-preprocessor": "^3.1.1", + "rooibos-cli": "^1.0.1", "typescript": "^3.3.1", "vinyl-paths": "^2.1.0" }, - "scripts": {}, + "scripts": { + "use-live-cli": "npm install maestro-cli-roku --save-dev", + "use-local-cli": "npm install ../../maestro-cli --save-dev" + }, "repository": { "type": "git", "url": "git+https://github.com/georgejecook/rooibos.git" diff --git a/samples/example/source/tests/rooibos/rooibosDist.brs b/samples/example/source/tests/rooibos/rooibosDist.brs index 6d8b4c6f..c188b535 100644 --- a/samples/example/source/tests/rooibos/rooibosDist.brs +++ b/samples/example/source/tests/rooibos/rooibosDist.brs @@ -4,153 +4,10 @@ ' * @link https://github.com/georgejecook/rooibos#readme ' * @license MIT ' */ -function Rooibos__Init(preTestSetup = invalid, testUtilsDecoratorMethodName = invalid, testSceneName = invalid, nodeContext = invalid) as void - args = {} - if createObject("roAPPInfo").IsDev() <> true then - ? " not running in dev mode! - rooibos tests only support sideloaded builds - aborting" - return - end if - args.testUtilsDecoratorMethodName = testUtilsDecoratorMethodName - args.nodeContext = nodeContext - screen = CreateObject("roSGScreen") - m.port = CreateObject("roMessagePort") - screen.setMessagePort(m.port) - if testSceneName = invalid - testSceneName = "TestsScene" - end if - ? "Starting test using test scene with name TestsScene" ; testSceneName - scene = screen.CreateScene(testSceneName) - scene.id = "ROOT" - screen.show() - m.global = screen.getGlobalNode() - m.global.addFields({ "testsScene": scene }) - if (preTestSetup <> invalid) - preTestSetup(screen) - end if - testId = args.TestId - if (testId = invalid) - testId = "UNDEFINED_TEST_ID" - end if - ? "#########################################################################" - ? "#TEST START : ###" ; testId ; "###" - args.testScene = scene - args.global = m.global - rooibosVersion = "3.1.1" - requiredRooibosPreprocessorVersion = "1.0.0" - if not RBS_CMN_isFunction(RBSFM_getPreprocessorVersion) - versionError = "You are using a rooibos-preprocessor (i.e. rooibos-cli) version older than 1.0.0 - please update to " + requiredRooibosPreprocessorVersion - else - if RBSFM_getPreprocessorVersion() = requiredRooibosPreprocessorVersion - versionError = "" - else - versionError = "Your rooibos-preprocessor (i.e. rooibos-cli) version '" + RBSFM_getPreprocessorVersion() + "' is not compatible with rooibos version " + rooibosVersion + ". Please upgrade your rooibos-cli to version " + requiredRooibosPreprocessorVersion - end if - end if - if versionError = "" - ? "######################################################" - ? "" - ? "# rooibos framework version: " ; rooibosVersion - ? "# tests parsed with rooibosC version: " ; rooibosVersion - ? "######################################################" - ? "" - runner = RBS_TR_TestRunner(args) - runner.Run() - while(true) - msg = wait(0, m.port) - msgType = type(msg) - if msgType = "roSGScreenEvent" - if msg.isScreenClosed() - return - end if - end if - end while - else - ? "" - ? "#########################################################" - ? "ERROR - VERSION MISMATCH" - ? versionError - ? "#########################################################" - end if -end function -function BaseTestSuite() as object - this = {} - this.Name = "BaseTestSuite" - this.invalidValue = "#ROIBOS#INVALID_VALUE" ' special value used in mock arguments - this.ignoreValue = "#ROIBOS#IGNORE_VALUE" ' special value used in mock arguments - this.allowNonExistingMethodsOnMocks = true - this.isAutoAssertingMocks = true - this.TestCases = [] - this.AddTest = RBS_BTS_AddTest - this.CreateTest = RBS_BTS_CreateTest - this.GetLegacyCompatibleReturnValue = RBS_BTS_GetLegacyCompatibleReturnValue - this.Fail = RBS_BTS_Fail - this.AssertFalse = RBS_BTS_AssertFalse - this.AssertTrue = RBS_BTS_AssertTrue - this.AssertEqual = RBS_BTS_AssertEqual - this.AssertLike = RBS_BTS_AssertLike - this.AssertNotEqual = RBS_BTS_AssertNotEqual - this.AssertInvalid = RBS_BTS_AssertInvalid - this.AssertNotInvalid = RBS_BTS_AssertNotInvalid - this.AssertAAHasKey = RBS_BTS_AssertAAHasKey - this.AssertAANotHasKey = RBS_BTS_AssertAANotHasKey - this.AssertAAHasKeys = RBS_BTS_AssertAAHasKeys - this.AssertAANotHasKeys = RBS_BTS_AssertAANotHasKeys - this.AssertArrayContains = RBS_BTS_AssertArrayContains - this.AssertArrayNotContains = RBS_BTS_AssertArrayNotContains - this.AssertArrayContainsSubset = RBS_BTS_AssertArrayContainsSubset - this.AssertArrayContainsAAs = RBS_BTS_AssertArrayContainsAAs - this.AssertArrayNotContainsSubset = RBS_BTS_AssertArrayNotContainsSubset - this.AssertArrayCount = RBS_BTS_AssertArrayCount - this.AssertArrayNotCount = RBS_BTS_AssertArrayNotCount - this.AssertEmpty = RBS_BTS_AssertEmpty - this.AssertNotEmpty = RBS_BTS_AssertNotEmpty - this.AssertArrayContainsOnlyValuesOfType = RBS_BTS_AssertArrayContainsOnlyValuesOfType - this.AssertType = RBS_BTS_AssertType - this.AssertSubType = RBS_BTS_AssertSubType - this.AssertNodeCount = RBS_BTS_AssertNodeCount - this.AssertNodeNotCount = RBS_BTS_AssertNodeNotCount - this.AssertNodeEmpty = RBS_BTS_AssertNodeEmpty - this.AssertNodeNotEmpty = RBS_BTS_AssertNodenotEmpty - this.AssertNodeContains = RBS_BTS_AssertNodeContains - this.AssertNodeNotContains = RBS_BTS_AssertNodeNotContains - this.AssertNodeContainsFields = RBS_BTS_AssertNodeContainsFields - this.AssertNodeNotContainsFields = RBS_BTS_AssertNodeNotContainsFields - this.AssertAAContainsSubset = RBS_BTS_AssertAAContainsSubset - this.EqValues = RBS_BTS_EqValues - this.EqAssocArrays = RBS_BTS_EqAssocArray - this.EqArray = RBS_BTS_EqArray - this.Stub = RBS_BTS_Stub - this.Mock = RBS_BTS_Mock - this.AssertMocks = RBS_BTS_AssertMocks - this.CreateFake = RBS_BTS_CreateFake - this.CombineFakes = RBS_BTS_CombineFakes - this.MockFail = RBS_BTS_MockFail - this.CleanMocks = RBS_BTS_CleanMocks - this.CleanStubs = RBS_BTS_CleanStubs - this.ExpectOnce = RBS_BTS_ExpectOnce - this.ExpectNone = RBS_BTS_ExpectNone - this.Expect = RBS_BTS_Expect - this.ExpectOnceOrNone = RBS_BTS_ExpectOnceOrNone - this.MockCallback0 = RBS_BTS_MockCallback0 - this.MockCallback1 = RBS_BTS_MockCallback1 - this.MockCallback2 = RBS_BTS_MockCallback2 - this.MockCallback3 = RBS_BTS_MockCallback3 - this.MockCallback4 = RBS_BTS_MockCallback4 - this.MockCallback5 = RBS_BTS_MockCallback5 - this.StubCallback0 = RBS_BTS_StubCallback0 - this.StubCallback1 = RBS_BTS_StubCallback1 - this.StubCallback2 = RBS_BTS_StubCallback2 - this.StubCallback3 = RBS_BTS_StubCallback3 - this.StubCallback4 = RBS_BTS_StubCallback4 - this.StubCallback5 = RBS_BTS_StubCallback5 - this.pathAsArray_ = RBS_BTS_rodash_pathsAsArray_ - this.g = RBS_BTS_rodash_get_ - return this -end function -sub RBS_BTS_AddTest(name, func,funcName, setup = invalid, teardown = invalid) + function RBS_BTS_AddTest(name, func, funcName, setup = invalid, teardown = invalid) m.testCases.Push(m.createTest(name, func, setup, teardown)) -end sub -function RBS_BTS_CreateTest(name, func, funcName, setup = invalid, teardown = invalid ) as object +end function + function RBS_BTS_CreateTest(name, func, funcName, setup = invalid, teardown = invalid) as object if (func = invalid) ? " ASKED TO CREATE TEST WITH INVALID FUNCITON POINTER FOR FUNCTION " ; funcName end if @@ -162,12 +19,12 @@ function RBS_BTS_CreateTest(name, func, funcName, setup = invalid, teardown = in TearDown: teardown } end function -function RBS_BTS_Fail(msg = "Error" ) as dynamic + function RBS_BTS_Fail(msg = "Error") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end function -function RBS_BTS_GetLegacyCompatibleReturnValue(value) as object + function RBS_BTS_GetLegacyCompatibleReturnValue(value) as object if (value = true) if (m.isLegacy = true) return "" @@ -182,30 +39,30 @@ function RBS_BTS_GetLegacyCompatibleReturnValue(value) as object end if end if end function -function RBS_BTS_AssertFalse(expr , msg = "Expression evaluates to true" ) as dynamic + function RBS_BTS_AssertFalse(expr , msg = "Expression evaluates to true") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if not RBS_CMN_IsBoolean(expr) or expr + if not RBS_CMN_IsBoolean(expr) or expr m.currentResult.AddResult(msg) return m.fail(msg) end if m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertTrue(expr , msg = "Expression evaluates to false" ) as dynamic + function RBS_BTS_AssertTrue(expr , msg = "Expression evaluates to false") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if not RBS_CMN_IsBoolean(expr) or not expr then + if not RBS_CMN_IsBoolean(expr) or not expr then m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertEqual(first , second , msg = "" ) as dynamic + function RBS_BTS_AssertEqual(first , second , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if not m.eqValues(first, second) if msg = "" - first_as_string = RBS_CMN_AsString(first) - second_as_string = RBS_CMN_AsString(second) + first_as_string = RBS_CMN_AsString(first) + second_as_string = RBS_CMN_AsString(second) msg = first_as_string + " != " + second_as_string end if m.currentResult.AddResult(msg) @@ -214,12 +71,12 @@ function RBS_BTS_AssertEqual(first , second , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertLike(first , second , msg = "" ) as dynamic + function RBS_BTS_AssertLike(first , second , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if first <> second if msg = "" - first_as_string = RBS_CMN_AsString(first) - second_as_string = RBS_CMN_AsString(second) + first_as_string = RBS_CMN_AsString(first) + second_as_string = RBS_CMN_AsString(second) msg = first_as_string + " != " + second_as_string end if m.currentResult.AddResult(msg) @@ -228,12 +85,12 @@ function RBS_BTS_AssertLike(first , second , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertNotEqual(first , second , msg = "" ) as dynamic + function RBS_BTS_AssertNotEqual(first , second , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if m.eqValues(first, second) if msg = "" - first_as_string = RBS_CMN_AsString(first) - second_as_string = RBS_CMN_AsString(second) + first_as_string = RBS_CMN_AsString(first) + second_as_string = RBS_CMN_AsString(second) msg = first_as_string + " == " + second_as_string end if m.currentResult.AddResult(msg) @@ -242,11 +99,11 @@ function RBS_BTS_AssertNotEqual(first , second , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertInvalid(value , msg = "" ) as dynamic + function RBS_BTS_AssertInvalid(value , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if value <> invalid if msg = "" - expr_as_string = RBS_CMN_AsString(value) + expr_as_string = RBS_CMN_AsString(value) msg = expr_as_string + " <> Invalid" end if m.currentResult.AddResult(msg) @@ -255,11 +112,11 @@ function RBS_BTS_AssertInvalid(value , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertNotInvalid(value , msg = "" ) as dynamic + function RBS_BTS_AssertNotInvalid(value , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if value = invalid if msg = "" - expr_as_string = RBS_CMN_AsString(value) + expr_as_string = RBS_CMN_AsString(value) msg = expr_as_string + " = Invalid" end if m.currentResult.AddResult(msg) @@ -268,9 +125,9 @@ function RBS_BTS_AssertNotInvalid(value , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertAAHasKey(array , key , msg = "" ) as dynamic + function RBS_BTS_AssertAAHasKey(array , key , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) + if RBS_CMN_IsAssociativeArray(array) if not array.DoesExist(key) if msg = "" msg = "Array doesn't have the '" + key + "' key." @@ -286,9 +143,9 @@ function RBS_BTS_AssertAAHasKey(array , key , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertAANotHasKey(array , key , msg = "" ) as dynamic + function RBS_BTS_AssertAANotHasKey(array , key , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) + if RBS_CMN_IsAssociativeArray(array) if array.DoesExist(key) if msg = "" msg = "Array has the '" + key + "' key." @@ -304,9 +161,9 @@ function RBS_BTS_AssertAANotHasKey(array , key , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertAAHasKeys(array , keys , msg = "" ) as dynamic + function RBS_BTS_AssertAAHasKeys(array , keys , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsArray(keys) + if RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsArray(keys) for each key in keys if not array.DoesExist(key) if msg = "" @@ -324,9 +181,9 @@ function RBS_BTS_AssertAAHasKeys(array , keys , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertAANotHasKeys(array , keys , msg = "" ) as dynamic + function RBS_BTS_AssertAANotHasKeys(array , keys , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsArray(keys) + if RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsArray(keys) for each key in keys if array.DoesExist(key) if msg = "" @@ -344,11 +201,11 @@ function RBS_BTS_AssertAANotHasKeys(array , keys , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertArrayContains(array , value , key = invalid , msg = "" ) as dynamic + function RBS_BTS_AssertArrayContains(array , value , key = invalid , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) - if not RBS_CMN_ArrayContains(array, value, key) - msg = "Array doesn't have the '" + RBS_CMN_AsString(value) + "' value." + if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) + if not RBS_CMN_ArrayContains(array, value, key) + msg = "Array doesn't have the '" + RBS_CMN_AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -360,18 +217,18 @@ function RBS_BTS_AssertArrayContains(array , value , key = invalid , msg = "" ) m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertArrayContainsAAs(array , values , msg = "" ) as dynamic + function RBS_BTS_AssertArrayContainsAAs(array , values , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if not RBS_CMN_IsArray(values) + if not RBS_CMN_IsArray(values) msg = "values to search for are not an Array." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if - if RBS_CMN_IsArray(array) + if RBS_CMN_IsArray(array) for each value in values isMatched = false - if not RBS_CMN_IsAssociativeArray(value) - msg = "Value to search for was not associativeArray "+ RBS_CMN_AsString(value) + if not RBS_CMN_IsAssociativeArray(value) + msg = "Value to search for was not associativeArray " + RBS_CMN_AsString(value) m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -393,7 +250,7 @@ function RBS_BTS_AssertArrayContainsAAs(array , values , msg = "" ) as dynamic end if end for ' items in array if not isMatched - msg = "array missing value: "+ RBS_CMN_AsString(value) + msg = "array missing value: " + RBS_CMN_AsString(value) m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -406,11 +263,11 @@ function RBS_BTS_AssertArrayContainsAAs(array , values , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertArrayNotContains(array , value , key = invalid , msg = "" ) as dynamic + function RBS_BTS_AssertArrayNotContains(array , value , key = invalid , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) - if RBS_CMN_ArrayContains(array, value, key) - msg = "Array has the '" + RBS_CMN_AsString(value) + "' value." + if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) + if RBS_CMN_ArrayContains(array, value, key) + msg = "Array has the '" + RBS_CMN_AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -422,10 +279,10 @@ function RBS_BTS_AssertArrayNotContains(array , value , key = invalid , msg = "" m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertArrayContainsSubset(array , subset , msg = "" ) as dynamic + function RBS_BTS_AssertArrayContainsSubset(array , subset , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if (RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsAssociativeArray(subset)) or (RBS_CMN_IsArray(array) and RBS_CMN_IsArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) + if (RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsAssociativeArray(subset)) or (RBS_CMN_IsArray(array) and RBS_CMN_IsArray(subset)) + isAA = RBS_CMN_IsAssociativeArray(subset) for each item in subset key = invalid value = item @@ -433,8 +290,8 @@ function RBS_BTS_AssertArrayContainsSubset(array , subset , msg = "" ) as dynami key = item value = subset[key] end if - if not RBS_CMN_ArrayContains(array, value, key) - msg = "Array doesn't have the '" + RBS_CMN_AsString(value) + "' value." + if not RBS_CMN_ArrayContains(array, value, key) + msg = "Array doesn't have the '" + RBS_CMN_AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -447,10 +304,10 @@ function RBS_BTS_AssertArrayContainsSubset(array , subset , msg = "" ) as dynami m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertArrayNotContainsSubset(array , subset , msg = "" ) as dynamic + function RBS_BTS_AssertArrayNotContainsSubset(array , subset , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if (RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsAssociativeArray(subset)) or (RBS_CMN_IsArray(array) and RBS_CMN_IsArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) + if (RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsAssociativeArray(subset)) or (RBS_CMN_IsArray(array) and RBS_CMN_IsArray(subset)) + isAA = RBS_CMN_IsAssociativeArray(subset) for each item in subset key = invalid value = item @@ -458,8 +315,8 @@ function RBS_BTS_AssertArrayNotContainsSubset(array , subset , msg = "" ) as dyn key = item value = item[key] end if - if RBS_CMN_ArrayContains(array, value, key) - msg = "Array has the '" + RBS_CMN_AsString(value) + "' value." + if RBS_CMN_ArrayContains(array, value, key) + msg = "Array has the '" + RBS_CMN_AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -472,11 +329,11 @@ function RBS_BTS_AssertArrayNotContainsSubset(array , subset , msg = "" ) as dyn m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertArrayCount(array , count , msg = "" ) as dynamic + function RBS_BTS_AssertArrayCount(array , count , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) + if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) if array.Count() <> count - msg = "Array items count " + RBS_CMN_AsString(array.Count()) + " <> " + RBS_CMN_AsString(count) + "." + msg = "Array items count " + RBS_CMN_AsString(array.Count()) + " <> " + RBS_CMN_AsString(count) + "." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -488,11 +345,11 @@ function RBS_BTS_AssertArrayCount(array , count , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertArrayNotCount(array , count , msg = "" ) as dynamic + function RBS_BTS_AssertArrayNotCount(array , count , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) + if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) if array.Count() = count - msg = "Array items count = " + RBS_CMN_AsString(count) + "." + msg = "Array items count = " + RBS_CMN_AsString(count) + "." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -504,9 +361,9 @@ function RBS_BTS_AssertArrayNotCount(array , count , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertEmpty(item , msg = "" ) as dynamic + function RBS_BTS_AssertEmpty(item , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(item) or RBS_CMN_IsArray(item) + if RBS_CMN_IsAssociativeArray(item) or RBS_CMN_IsArray(item) if item.Count() > 0 msg = "Array is not empty." m.currentResult.AddResult(msg) @@ -526,15 +383,15 @@ function RBS_BTS_AssertEmpty(item , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertNotEmpty(item , msg = "" ) as dynamic + function RBS_BTS_AssertNotEmpty(item , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(item) or RBS_CMN_IsArray(item) + if RBS_CMN_IsAssociativeArray(item) or RBS_CMN_IsArray(item) if item.Count() = 0 msg = "Array is empty." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if - else if RBS_CMN_IsString(item) + else if RBS_CMN_IsString(item) if (item = "") msg = "Input value is empty." m.currentResult.AddResult(msg) @@ -548,20 +405,20 @@ function RBS_BTS_AssertNotEmpty(item , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertArrayContainsOnlyValuesOfType(array , typeStr , msg = "" ) as dynamic + function RBS_BTS_AssertArrayContainsOnlyValuesOfType(array , typeStr , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if typeStr <> "String" and typeStr <> "Integer" and typeStr <> "Boolean" and typeStr <> "Array" and typeStr <> "AssociativeArray" msg = "Type must be Boolean, String, Array, Integer, or AssociativeArray" m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) + if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) methodName = "RBS_CMN_Is" + typeStr - typeCheckFunction = RBS_CMN_GetIsTypeFunction(methodName) + typeCheckFunction = m.GetIsTypeFunction(methodName) if (typeCheckFunction <> invalid) for each item in array if not typeCheckFunction(item) - msg = RBS_CMN_AsString(item) + "is not a '" + typeStr + "' type." + msg = RBS_CMN_AsString(item) + "is not a '" + typeStr + "' type." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -579,46 +436,46 @@ function RBS_BTS_AssertArrayContainsOnlyValuesOfType(array , typeStr , msg = "" m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_CMN_GetIsTypeFunction(name) + function RBS_BTS_GetIsTypeFunction(name) if name = "RBS_CMN_IsFunction" - return RBS_CMN_IsFunction + return RBS_CMN_IsFunction else if name = "RBS_CMN_IsXmlElement" - return RBS_CMN_IsXmlElement + return RBS_CMN_IsXmlElement else if name = "RBS_CMN_IsInteger" - return RBS_CMN_IsInteger + return RBS_CMN_IsInteger else if name = "RBS_CMN_IsBoolean" - return RBS_CMN_IsBoolean + return RBS_CMN_IsBoolean else if name = "RBS_CMN_IsFloat" - return RBS_CMN_IsFloat + return RBS_CMN_IsFloat else if name = "RBS_CMN_IsDouble" - return RBS_CMN_IsDouble + return RBS_CMN_IsDouble else if name = "RBS_CMN_IsLongInteger" - return RBS_CMN_IsLongInteger + return RBS_CMN_IsLongInteger else if name = "RBS_CMN_IsNumber" - return RBS_CMN_IsNumber + return RBS_CMN_IsNumber else if name = "RBS_CMN_IsList" - return RBS_CMN_IsList + return RBS_CMN_IsList else if name = "RBS_CMN_IsArray" - return RBS_CMN_IsArray + return RBS_CMN_IsArray else if name = "RBS_CMN_IsAssociativeArray" - return RBS_CMN_IsAssociativeArray + return RBS_CMN_IsAssociativeArray else if name = "RBS_CMN_IsSGNode" - return RBS_CMN_IsSGNode + return RBS_CMN_IsSGNode else if name = "RBS_CMN_IsString" - return RBS_CMN_IsString + return RBS_CMN_IsString else if name = "RBS_CMN_IsDateTime" - return RBS_CMN_IsDateTime + return RBS_CMN_IsDateTime else if name = "RBS_CMN_IsUndefined" - return RBS_CMN_IsUndefined + return RBS_CMN_IsUndefined else return invalid end if end function -function RBS_BTS_AssertType(value , typeStr , msg ="" ) as dynamic + function RBS_BTS_AssertType(value , typeStr , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if type(value) <> typeStr if msg = "" - expr_as_string = RBS_CMN_AsString(value) + expr_as_string = RBS_CMN_AsString(value) msg = expr_as_string + " was not expected type " + typeStr end if m.currentResult.AddResult(msg) @@ -627,19 +484,19 @@ function RBS_BTS_AssertType(value , typeStr , msg ="" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertSubType(value , typeStr , msg ="" ) as dynamic + function RBS_BTS_AssertSubType(value , typeStr , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if type(value) <> "roSGNode" if msg = "" - expr_as_string = RBS_CMN_AsString(value) + expr_as_string = RBS_CMN_AsString(value) msg = expr_as_string + " was not a node, so could not match subtype " + typeStr end if m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) else if (value.subType() <> typeStr) if msg = "" - expr_as_string = RBS_CMN_AsString(value) - msg = expr_as_string + "( type : " + value.subType() +") was not of subType " + typeStr + expr_as_string = RBS_CMN_AsString(value) + msg = expr_as_string + "( type : " + value.subType() + ") was not of subType " + typeStr end if m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) @@ -647,7 +504,7 @@ function RBS_BTS_AssertSubType(value , typeStr , msg ="" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_EqValues(Value1 , Value2 ) as dynamic + function RBS_BTS_EqValues(Value1 , Value2) as dynamic val1Type = type(Value1) val2Type = type(Value2) if val1Type = "" or val2Type = "" or val1Type = "" or val2Type = "" @@ -655,12 +512,12 @@ function RBS_BTS_EqValues(Value1 , Value2 ) as dynamic return false end if if val1Type = "roString" or val1Type = "String" - Value1 = RBS_CMN_AsString(Value1) + Value1 = RBS_CMN_AsString(Value1) else Value1 = box(Value1) end if if val2Type = "roString" or val2Type = "String" - Value2 = RBS_CMN_AsString(Value2) + Value2 = RBS_CMN_AsString(Value2) else Value2 = box(Value2) end if @@ -692,7 +549,7 @@ function RBS_BTS_EqValues(Value1 , Value2 ) as dynamic end if end if end function -function RBS_BTS_EqAssocArray(Value1 , Value2 ) as dynamic + function RBS_BTS_EqAssocArray(Value1 , Value2) as dynamic l1 = Value1.Count() l2 = Value2.Count() if not l1 = l2 @@ -714,8 +571,8 @@ function RBS_BTS_EqAssocArray(Value1 , Value2 ) as dynamic return true end if end function -function RBS_BTS_EqArray(Value1 , Value2 ) as dynamic - if not (RBS_CMN_IsArray(Value1)) or not RBS_CMN_IsArray(Value2) then return false + function RBS_BTS_EqArray(Value1 , Value2) as dynamic + if not (RBS_CMN_IsArray(Value1)) or not RBS_CMN_IsArray(Value2) then return false l1 = Value1.Count() l2 = Value2.Count() if not l1 = l2 @@ -731,11 +588,11 @@ function RBS_BTS_EqArray(Value1 , Value2 ) as dynamic return true end if end function -function RBS_BTS_AssertNodeCount(node , count , msg = "" ) as dynamic + function RBS_BTS_AssertNodeCount(node , count , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if type(node) = "roSGNode" if node.getChildCount() <> count - msg = "node items count <> " + RBS_CMN_AsString(count) + ". Received " + RBS_CMN_AsString(node.getChildCount()) + msg = "node items count <> " + RBS_CMN_AsString(count) + ". Received " + RBS_CMN_AsString(node.getChildCount()) m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -747,11 +604,11 @@ function RBS_BTS_AssertNodeCount(node , count , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertNodeNotCount(node , count , msg = "" ) as dynamic + function RBS_BTS_AssertNodeNotCount(node , count , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if type(node) = "roSGNode" if node.getChildCount() = count - msg = "node items count = " + RBS_CMN_AsString(count) + "." + msg = "node items count = " + RBS_CMN_AsString(count) + "." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -763,7 +620,7 @@ function RBS_BTS_AssertNodeNotCount(node , count , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertNodeEmpty(node , msg = "" ) as dynamic + function RBS_BTS_AssertNodeEmpty(node , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if type(node) = "roSGNode" if node.getChildCount() > 0 @@ -775,7 +632,7 @@ function RBS_BTS_AssertNodeEmpty(node , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertNodeNotEmpty(node , msg = "" ) as dynamic + function RBS_BTS_AssertNodeNotEmpty(node , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if type(node) = "roSGNode" if node.Count() = 0 @@ -787,11 +644,11 @@ function RBS_BTS_AssertNodeNotEmpty(node , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertNodeContains(node , value , msg = "" ) as dynamic + function RBS_BTS_AssertNodeContains(node , value , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(node) = "roSGNode" - if not RBS_CMN_NodeContains(node, value) - msg = "Node doesn't have the '" + RBS_CMN_AsString(value) + "' value." + if type(node) = "roSGNode" + if not RBS_CMN_NodeContains(node, value) + msg = "Node doesn't have the '" + RBS_CMN_AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -803,11 +660,11 @@ function RBS_BTS_AssertNodeContains(node , value , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertNodeContainsOnly(node , msg = "" ) as dynamic + function RBS_BTS_AssertNodeContainsOnly(node , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(node) = "roSGNode" - if not RBS_CMN_NodeContains(node, value) - msg = "Node doesn't have the '" + RBS_CMN_AsString(value) + "' value." + if type(node) = "roSGNode" + if not RBS_CMN_NodeContains(node, value) + msg = "Node doesn't have the '" + RBS_CMN_AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) else if node.getChildCount() <> 1 @@ -823,11 +680,11 @@ function RBS_BTS_AssertNodeContainsOnly(node , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertNodeNotContains(node , value , msg = "" ) as dynamic + function RBS_BTS_AssertNodeNotContains(node , value , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(node) = "roSGNode" - if RBS_CMN_NodeContains(node, value) - msg = "Node has the '" + RBS_CMN_AsString(value) + "' value." + if type(node) = "roSGNode" + if RBS_CMN_NodeContains(node, value) + msg = "Node has the '" + RBS_CMN_AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -839,18 +696,18 @@ function RBS_BTS_AssertNodeNotContains(node , value , msg = "" ) as dynamic m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertNodeContainsFields(node , subset , ignoredFields=invalid, msg = "" ) as dynamic + function RBS_BTS_AssertNodeContainsFields(node , subset , ignoredFields = invalid, msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if ( type(node) = "roSGNode" and RBS_CMN_IsAssociativeArray(subset)) or ( type(node) = "roSGNode" and RBS_CMN_IsArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) - isIgnoredFields = RBS_CMN_IsArray(ignoredFields) + if (type(node) = "roSGNode" and RBS_CMN_IsAssociativeArray(subset)) or (type(node) = "roSGNode" and RBS_CMN_IsArray(subset)) + isAA = RBS_CMN_IsAssociativeArray(subset) + isIgnoredFields = RBS_CMN_IsArray(ignoredFields) for each key in subset if (key <> "") - if (not isIgnoredFields or not RBS_CMN_ArrayContains(ignoredFields, key)) + if (not isIgnoredFields or not RBS_CMN_ArrayContains(ignoredFields, key)) subsetValue = subset[key] nodeValue = node[key] if not m.eqValues(nodeValue, subsetValue) - msg = key + ": Expected '" + RBS_CMN_AsString(subsetValue) + "', got '" + RBS_CMN_AsString(nodeValue) + "'" + msg = key + ": Expected '" + RBS_CMN_AsString(subsetValue) + "', got '" + RBS_CMN_AsString(nodeValue) + "'" m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -867,10 +724,10 @@ function RBS_BTS_AssertNodeContainsFields(node , subset , ignoredFields=invalid, m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertNodeNotContainsFields(node , subset , msg = "" ) as dynamic + function RBS_BTS_AssertNodeNotContainsFields(node , subset , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if ( type(node) = "roSGNode" and RBS_CMN_IsAssociativeArray(subset)) or ( type(node) = "roSGNode" and RBS_CMN_IsArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) + if (type(node) = "roSGNode" and RBS_CMN_IsAssociativeArray(subset)) or (type(node) = "roSGNode" and RBS_CMN_IsArray(subset)) + isAA = RBS_CMN_IsAssociativeArray(subset) for each item in subset key = invalid value = item @@ -878,8 +735,8 @@ function RBS_BTS_AssertNodeNotContainsFields(node , subset , msg = "" ) as dynam key = item value = item[key] end if - if RBS_CMN_NodeContains(node, value, key) - msg = "Node has the '" + RBS_CMN_AsString(value) + "' value." + if RBS_CMN_NodeContains(node, value, key) + msg = "Node has the '" + RBS_CMN_AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -892,18 +749,18 @@ function RBS_BTS_AssertNodeNotContainsFields(node , subset , msg = "" ) as dynam m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_AssertAAContainsSubset(array , subset , ignoredFields = invalid, msg = "" ) as dynamic + function RBS_BTS_AssertAAContainsSubset(array , subset , ignoredFields = invalid, msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if (RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsAssociativeArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) - isIgnoredFields = RBS_CMN_IsArray(ignoredFields) + if (RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsAssociativeArray(subset)) + isAA = RBS_CMN_IsAssociativeArray(subset) + isIgnoredFields = RBS_CMN_IsArray(ignoredFields) for each key in subset if (key <> "") - if (not isIgnoredFields or not RBS_CMN_ArrayContains(ignoredFields, key)) + if (not isIgnoredFields or not RBS_CMN_ArrayContains(ignoredFields, key)) subsetValue = subset[key] arrayValue = array[key] if not m.eqValues(arrayValue, subsetValue) - msg = key + ": Expected '" + RBS_CMN_AsString(subsetValue) + "', got '" + RBS_CMN_AsString(arrayValue) + "'" + msg = key + ": Expected '" + RBS_CMN_AsString(subsetValue) + "', got '" + RBS_CMN_AsString(arrayValue) + "'" m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -919,12 +776,12 @@ function RBS_BTS_AssertAAContainsSubset(array , subset , ignoredFields = invalid m.currentResult.AddResult("") return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_BTS_Stub(target, methodName, returnValue = invalid, allowNonExistingMethods = false) as object + function RBS_BTS_Stub(target, methodName, returnValue = invalid, allowNonExistingMethods = false) as object if (type(target) <> "roAssociativeArray") m.Fail("could not create Stub provided target was null") return {} end if - if (m.stubs =invalid) + if (m.stubs = invalid) m.__stubId = -1 m.stubs = {} end if @@ -949,32 +806,32 @@ function RBS_BTS_Stub(target, methodName, returnValue = invalid, allowNonExistin end if return fake end function -function RBS_BTS_ExpectOnce(target, methodName, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object + function RBS_BTS_ExpectOnce(target, methodName, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object return m.Mock(target, methodName, 1, expectedArgs, returnValue, allowNonExistingMethods) end function -function RBS_BTS_ExpectOnceOrNone(target, methodName, isExpected, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object + function RBS_BTS_ExpectOnceOrNone(target, methodName, isExpected, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object if isExpected return m.ExpectOnce(target, methodName, expectedArgs, returnValue, allowNonExistingMethods) else return m.ExpectNone(target, methodName, allowNonExistingMethods) end if end function -function RBS_BTS_ExpectNone(target, methodName, allowNonExistingMethods = false) as object + function RBS_BTS_ExpectNone(target, methodName, allowNonExistingMethods = false) as object return m.Mock(target, methodName, 0, invalid, invalid, allowNonExistingMethods) end function -function RBS_BTS_Expect(target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object + function RBS_BTS_Expect(target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object return m.Mock(target, methodName, expectedInvocations, expectedArgs, returnValue, allowNonExistingMethods) end function -function RBS_BTS_Mock(target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object - if not RBS_CMN_IsAssociativeArray(target) + function RBS_BTS_Mock(target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object + if not RBS_CMN_IsAssociativeArray(target) m.Fail("mock args: target was not an AA") - else if not RBS_CMN_IsString(methodName) + else if not RBS_CMN_IsString(methodName) m.Fail("mock args: methodName was not a string") - else if not RBS_CMN_IsNumber(expectedInvocations) + else if not RBS_CMN_IsNumber(expectedInvocations) m.Fail("mock args: expectedInvocations was not an int") - else if not RBS_CMN_IsArray(expectedArgs) and RBS_CMN_IsValid(expectedArgs) + else if not RBS_CMN_IsArray(expectedArgs) and RBS_CMN_IsValid(expectedArgs) m.Fail("mock args: expectedArgs was not invalid or an array of args") - else if RBS_CMN_IsUndefined(expectedArgs) + else if RBS_CMN_IsUndefined(expectedArgs) m.Fail("mock args: expectedArgs undefined") end if if m.currentResult.isFail @@ -993,7 +850,7 @@ function RBS_BTS_Mock(target, methodName, expectedInvocations = 1, expectedArgs end if for i = 0 to m.__mockId id = stri(i).trim() - mock = m.mocks[id] + mock = m.mocks[id] if mock <> invalid and mock.methodName = methodName and mock.target.__rooibosTargetId = target.__rooibosTargetId fake = mock exit for @@ -1012,7 +869,7 @@ function RBS_BTS_Mock(target, methodName, expectedInvocations = 1, expectedArgs allowNonExisting = m.allowNonExistingMethodsOnMocks = true or allowNonExistingMethods isMethodPresent = type(target[methodName]) = "Function" or type(target[methodName]) = "roFunction" if (isMethodPresent or allowNonExisting) - target[methodName] = m["MockCallback" + id] + target[methodName] = m["MockCallback" + id] target.__mocks = m.mocks if (not isMethodPresent) ? "WARNING - mocking call " ; methodName; " which did not exist on target object" @@ -1025,9 +882,9 @@ function RBS_BTS_Mock(target, methodName, expectedInvocations = 1, expectedArgs end if return fake end function -function RBS_BTS_CreateFake(id, target, methodName, expectedInvocations = 1, expectedArgs =invalid, returnValue=invalid ) as object + function RBS_BTS_CreateFake(id, target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid) as object expectedArgsValues = [] - hasArgs = RBS_CMN_IsArray(expectedArgs) + hasArgs = RBS_CMN_IsArray(expectedArgs) if (hasArgs) defaultValue = m.invalidValue else @@ -1037,7 +894,7 @@ function RBS_BTS_CreateFake(id, target, methodName, expectedInvocations = 1, exp for i = 0 to 9 if (hasArgs and expectedArgs.count() > i) value = expectedArgs[i] - if not RBS_CMN_IsUndefined(value) + if not RBS_CMN_IsUndefined(value) expectedArgsValues.push(expectedArgs[i]) else expectedArgsValues.push("#ERR-UNDEFINED!") @@ -1056,20 +913,20 @@ function RBS_BTS_CreateFake(id, target, methodName, expectedInvocations = 1, exp invokedArgs: [invalid, invalid, invalid, invalid, invalid, invalid, invalid, invalid, invalid], expectedArgs: expectedArgsValues, expectedInvocations: expectedInvocations, - callback: function (arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic + callback: function(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic if (m.allInvokedArgs = invalid) m.allInvokedArgs = [] end if - m.invokedArgs = [arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ] - m.allInvokedArgs.push ([arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ]) + m.invokedArgs = [arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9] + m.allInvokedArgs.push ([arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9]) m.isCalled = true m.invocations++ if (type(m.returnValue) = "roAssociativeArray" and m.returnValue.doesExist("multiResult")) returnValues = m.returnValue["multiResult"] - returnIndex = m.invocations -1 + returnIndex = m.invocations - 1 if (type(returnValues) = "roArray" and returnValues.count() > 0) if returnValues.count() <= m.invocations - returnIndex = returnValues.count() -1 + returnIndex = returnValues.count() - 1 print "Multi return values all used up - repeating last value" end if return returnValues[returnIndex] @@ -1084,7 +941,7 @@ function RBS_BTS_CreateFake(id, target, methodName, expectedInvocations = 1, exp } return fake end function -function RBS_BTS_CombineFakes(fake, otherFake) + function RBS_BTS_CombineFakes(fake, otherFake) if type(fake.expectedArgs) <> "roAssociativeArray" or not fake.expectedArgs.doesExist("multiInvoke") currentExpectedArgsArgs = fake.expectedArgs fake.expectedArgs = { @@ -1101,8 +958,8 @@ function RBS_BTS_CombineFakes(fake, otherFake) fake.returnValue.multiResult.push(otherFake.returnValue) fake.expectedInvocations++ end function -function RBS_BTS_AssertMocks() as void - if (m.__mockId = invalid or not RBS_CMN_IsAssociativeArray(m.mocks)) + function RBS_BTS_AssertMocks() as void + if (m.__mockId = invalid or not RBS_CMN_IsAssociativeArray(m.mocks)) return end if lastId = int(m.__mockId) @@ -1113,8 +970,8 @@ function RBS_BTS_AssertMocks() as void m.MockFail(methodName, "Wrong number of calls. (" + stri(mock.invocations).trim() + " / " + stri(mock.expectedInvocations).trim() + ")") m.CleanMocks() return - else if mock.expectedInvocations > 0 and (RBS_CMN_IsArray(mock.expectedArgs) or (type(mock.expectedArgs) = "roAssociativeArray" and RBS_CMN_IsArray(mock.expectedArgs.multiInvoke))) - isMultiArgsSupported = type(mock.expectedArgs) = "roAssociativeArray" and RBS_CMN_IsArray(mock.expectedArgs.multiInvoke) + else if mock.expectedInvocations > 0 and (RBS_CMN_IsArray(mock.expectedArgs) or (type(mock.expectedArgs) = "roAssociativeArray" and RBS_CMN_IsArray(mock.expectedArgs.multiInvoke))) + isMultiArgsSupported = type(mock.expectedArgs) = "roAssociativeArray" and RBS_CMN_IsArray(mock.expectedArgs.multiInvoke) for invocationIndex = 0 to mock.invocations - 1 invokedArgs = mock.allInvokedArgs[invocationIndex] if isMultiArgsSupported @@ -1122,10 +979,10 @@ function RBS_BTS_AssertMocks() as void else expectedArgs = mock.expectedArgs end if - for i = 0 to expectedArgs.count() -1 + for i = 0 to expectedArgs.count() - 1 value = invokedArgs[i] expected = expectedArgs[i] - didNotExpectArg = RBS_CMN_IsString(expected) and expected = m.invalidValue + didNotExpectArg = RBS_CMN_IsString(expected) and expected = m.invalidValue if (didNotExpectArg) expected = invalid end if @@ -1133,7 +990,7 @@ function RBS_BTS_AssertMocks() as void if (expected = invalid) expected = "[INVALID]" end if - m.MockFail(methodName, "on Invocation #" + stri(invocationIndex).trim() + ", expected arg #" + stri(i).trim() + " to be '" + RBS_CMN_AsString(expected) + "' got '" + RBS_CMN_AsString(value) + "')") + m.MockFail(methodName, "on Invocation #" + stri(invocationIndex).trim() + ", expected arg #" + stri(i).trim() + " to be '" + RBS_CMN_AsString(expected) + "' got '" + RBS_CMN_AsString(value) + "')") m.CleanMocks() return end if @@ -1143,150 +1000,239 @@ function RBS_BTS_AssertMocks() as void end for m.CleanMocks() end function -function RBS_BTS_CleanMocks() as void - if m.mocks = invalid return - for each id in m.mocks - mock = m.mocks[id] - mock.target.__mocks = invalid - end for - m.mocks = invalid - end function - function RBS_BTS_CleanStubs() as void - if m.stubs = invalid return - for each id in m.stubs - stub = m.stubs[id] - stub.target.__stubs = invalid - end for - m.stubs = invalid - end function - function RBS_BTS_MockFail(methodName, message) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - m.currentResult.AddResult("mock failure on '" + methodName + "' : " + message) - return m.GetLegacyCompatibleReturnValue(false) - end function - function RBS_BTS_StubCallback0(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["0"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_StubCallback1(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["1"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_StubCallback2(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["2"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_StubCallback3(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["3"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_StubCallback4(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["4"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_StubCallback5(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["5"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_MockCallback0(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["0"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_MockCallback1(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["1"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_MockCallback2(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["2"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_MockCallback3(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["3"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_MockCallback4(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["4"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_MockCallback5(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["5"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_rodash_pathsAsArray_(path) - pathRE = CreateObject("roRegex", "\[([0-9]+)\]", "i") - segments = [] - if type(path) = "String" or type(path) = "roString" - dottedPath = pathRE.replaceAll(path, ".\1") - stringSegments = dottedPath.tokenize(".") - for each s in stringSegments - if (Asc(s) >= 48) and (Asc(s) <= 57) - segments.push(s.toInt()) - else - segments.push(s) - end if - end for - else if type(path) = "roList" or type(path) = "roArray" - stringPath = "" - for each s in path - stringPath = stringPath + "." + Box(s).toStr() - end for - segments = m.pathAsArray_(stringPath) + function RBS_BTS_CleanMocks() as void + if m.mocks = invalid then return + for each id in m.mocks + mock = m.mocks[id] + mock.target.__mocks = invalid + end for + m.mocks = invalid +end function + function RBS_BTS_CleanStubs() as void + if m.stubs = invalid then return + for each id in m.stubs + stub = m.stubs[id] + stub.target.__stubs = invalid + end for + m.stubs = invalid +end function + function RBS_BTS_MockFail(methodName, message) as dynamic + if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed + m.currentResult.AddResult("mock failure on '" + methodName + "' : " + message) + return m.GetLegacyCompatibleReturnValue(false) +end function + function RBS_BTS_StubCallback0(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__Stubs["0"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function + function RBS_BTS_StubCallback1(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__Stubs["1"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function + function RBS_BTS_StubCallback2(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__Stubs["2"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function + function RBS_BTS_StubCallback3(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__Stubs["3"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function + function RBS_BTS_StubCallback4(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__Stubs["4"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function + function RBS_BTS_StubCallback5(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__Stubs["5"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function + function RBS_BTS_MockCallback0(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__mocks["0"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function + function RBS_BTS_MockCallback1(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__mocks["1"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function + function RBS_BTS_MockCallback2(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__mocks["2"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function + function RBS_BTS_MockCallback3(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__mocks["3"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function + function RBS_BTS_MockCallback4(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__mocks["4"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function + function RBS_BTS_MockCallback5(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__mocks["5"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function + function RBS_BTS_pathAsArray_(path) + pathRE = CreateObject("roRegex", "\[([0-9]+)\]", "i") + segments = [] + if type(path) = "String" or type(path) = "roString" + dottedPath = pathRE.replaceAll(path, ".\1") + stringSegments = dottedPath.tokenize(".") + for each s in stringSegments + if (Asc(s) >= 48) and (Asc(s) <= 57) + segments.push(s.toInt()) else - segments = invalid - end if - return segments - end function - function RBS_BTS_rodash_get_(aa, path, default=invalid) - if type(aa) <> "roAssociativeArray" and type(aa) <> "roArray" and type(aa) <> "roSGNode" then return default - segments = m.pathAsArray_(path) - if (Type(path) = "roInt" or Type(path) = "roInteger" or Type(path) = "Integer") - path = stri(path).trim() + segments.push(s) end if - if segments = invalid then return default - result = invalid - while segments.count() > 0 - key = segments.shift() - if (type(key) = "roInteger") 'it's a valid index - if (aa <> invalid and GetInterface(aa, "ifArray") <> invalid) - value = aa[key] - else if (aa <> invalid and GetInterface(aa, "ifSGNodeChildren") <> invalid) - value = aa.getChild(key) - else if (aa <> invalid and GetInterface(aa, "ifAssociativeArray") <> invalid) - key = tostr(key) - if not aa.doesExist(key) - exit while - end if - value = aa.lookup(key) - else - value = invalid - end if - else - if not aa.doesExist(key) - exit while - end if - value = aa.lookup(key) - end if - if segments.count() = 0 - result = value - exit while - end if - if type(value) <> "roAssociativeArray" and type(value) <> "roArray" and type(value) <> "roSGNode" + end for + else if type(path) = "roList" or type(path) = "roArray" + stringPath = "" + for each s in path + stringPath = stringPath + "." + Box(s).toStr() + end for + segments = m.pathAsArray_(stringPath) + else + segments = invalid + end if + return segments +end function + function RBS_BTS_g(aa, path, default = invalid) + if type(aa) <> "roAssociativeArray" and type(aa) <> "roArray" and type(aa) <> "roSGNode" then return default + segments = m.pathAsArray_(path) + if (Type(path) = "roInt" or Type(path) = "roInteger" or Type(path) = "Integer") + path = stri(path).trim() + end if + if segments = invalid then return default + result = invalid + while segments.count() > 0 + key = segments.shift() + if (type(key) = "roInteger") 'it's a valid index + if (aa <> invalid and GetInterface(aa, "ifArray") <> invalid) + value = aa[key] + else if (aa <> invalid and GetInterface(aa, "ifSGNodeChildren") <> invalid) + value = aa.getChild(key) + else if (aa <> invalid and GetInterface(aa, "ifAssociativeArray") <> invalid) + key = tostr(key) + if not aa.doesExist(key) exit while end if - aa = value - end while - if result = invalid then return default - return result - end function + value = aa.lookup(key) + else + value = invalid + end if + else + if not aa.doesExist(key) + exit while + end if + value = aa.lookup(key) + end if + if segments.count() = 0 + result = value + exit while + end if + if type(value) <> "roAssociativeArray" and type(value) <> "roArray" and type(value) <> "roSGNode" + exit while + end if + aa = value + end while + if result = invalid then return default + return result +end function + function __BaseTestSuite_builder() + instance = {} + BaseTestSuite_instance = { + __className: "BaseTestSuite" + __BaseTestSuite: RBS_BTS_BaseTestSuite_new_ + AddTest: RBS_BTS_AddTest + CreateTest: RBS_BTS_CreateTest + Fail: RBS_BTS_Fail + GetLegacyCompatibleReturnValue: RBS_BTS_GetLegacyCompatibleReturnValue + AssertFalse: RBS_BTS_AssertFalse + AssertTrue: RBS_BTS_AssertTrue + AssertEqual: RBS_BTS_AssertEqual + AssertLike: RBS_BTS_AssertLike + AssertNotEqual: RBS_BTS_AssertNotEqual + AssertInvalid: RBS_BTS_AssertInvalid + AssertNotInvalid: RBS_BTS_AssertNotInvalid + AssertAAHasKey: RBS_BTS_AssertAAHasKey + AssertAANotHasKey: RBS_BTS_AssertAANotHasKey + AssertAAHasKeys: RBS_BTS_AssertAAHasKeys + AssertAANotHasKeys: RBS_BTS_AssertAANotHasKeys + AssertArrayContains: RBS_BTS_AssertArrayContains + AssertArrayContainsAAs: RBS_BTS_AssertArrayContainsAAs + AssertArrayNotContains: RBS_BTS_AssertArrayNotContains + AssertArrayContainsSubset: RBS_BTS_AssertArrayContainsSubset + AssertArrayNotContainsSubset: RBS_BTS_AssertArrayNotContainsSubset + AssertArrayCount: RBS_BTS_AssertArrayCount + AssertArrayNotCount: RBS_BTS_AssertArrayNotCount + AssertEmpty: RBS_BTS_AssertEmpty + AssertNotEmpty: RBS_BTS_AssertNotEmpty + AssertArrayContainsOnlyValuesOfType: RBS_BTS_AssertArrayContainsOnlyValuesOfType + GetIsTypeFunction: RBS_BTS_GetIsTypeFunction + AssertType: RBS_BTS_AssertType + AssertSubType: RBS_BTS_AssertSubType + EqValues: RBS_BTS_EqValues + EqAssocArray: RBS_BTS_EqAssocArray + EqArray: RBS_BTS_EqArray + AssertNodeCount: RBS_BTS_AssertNodeCount + AssertNodeNotCount: RBS_BTS_AssertNodeNotCount + AssertNodeEmpty: RBS_BTS_AssertNodeEmpty + AssertNodeNotEmpty: RBS_BTS_AssertNodeNotEmpty + AssertNodeContains: RBS_BTS_AssertNodeContains + AssertNodeContainsOnly: RBS_BTS_AssertNodeContainsOnly + AssertNodeNotContains: RBS_BTS_AssertNodeNotContains + AssertNodeContainsFields: RBS_BTS_AssertNodeContainsFields + AssertNodeNotContainsFields: RBS_BTS_AssertNodeNotContainsFields + AssertAAContainsSubset: RBS_BTS_AssertAAContainsSubset + Stub: RBS_BTS_Stub + ExpectOnce: RBS_BTS_ExpectOnce + ExpectOnceOrNone: RBS_BTS_ExpectOnceOrNone + ExpectNone: RBS_BTS_ExpectNone + Expect: RBS_BTS_Expect + Mock: RBS_BTS_Mock + CreateFake: RBS_BTS_CreateFake + CombineFakes: RBS_BTS_CombineFakes + AssertMocks: RBS_BTS_AssertMocks + CleanMocks: RBS_BTS_CleanMocks + CleanStubs: RBS_BTS_CleanStubs + MockFail: RBS_BTS_MockFail + StubCallback0: RBS_BTS_StubCallback0 + StubCallback1: RBS_BTS_StubCallback1 + StubCallback2: RBS_BTS_StubCallback2 + StubCallback3: RBS_BTS_StubCallback3 + StubCallback4: RBS_BTS_StubCallback4 + StubCallback5: RBS_BTS_StubCallback5 + MockCallback0: RBS_BTS_MockCallback0 + MockCallback1: RBS_BTS_MockCallback1 + MockCallback2: RBS_BTS_MockCallback2 + MockCallback3: RBS_BTS_MockCallback3 + MockCallback4: RBS_BTS_MockCallback4 + MockCallback5: RBS_BTS_MockCallback5 + pathAsArray_: RBS_BTS_pathAsArray_ + g: RBS_BTS_g + Name: "BaseTestSuite" + invalidValue: "#ROIBOS#INVALID_VALUE" ' special value used in mock arguments + ignoreValue: "#ROIBOS#IGNORE_VALUE" ' special value used in mock arguments + allowNonExistingMethodsOnMocks: true + isAutoAssertingMocks: true + TestCases: [] + } + instance.append(BaseTestSuite_instance) + return instance + end function + function BaseTestSuite() + instance = __BaseTestSuite_builder() + instance.__BaseTestSuite() + return instance + end function + function RBS_BTS_BaseTestSuite_new_() + end function function RBS_CMN_IsXmlElement(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifXMLElement") <> invalid + return RBS_CMN_IsValid(value) and GetInterface(value, "ifXMLElement") <> invalid end function function RBS_CMN_IsFunction(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifFunction") <> invalid + return RBS_CMN_IsValid(value) and GetInterface(value, "ifFunction") <> invalid end function function RBS_CMN_GetFunction(filename, functionName) as object - if (not RBS_CMN_IsNotEmptyString(functionName)) then return invalid - if (not RBS_CMN_IsNotEmptyString(filename)) then return invalid + if (not RBS_CMN_IsNotEmptyString(functionName)) then return invalid + if (not RBS_CMN_IsNotEmptyString(filename)) then return invalid mapFunction = RBSFM_getFunctionsForFile(filename) if mapFunction <> invalid map = mapFunction() @@ -1300,7 +1246,7 @@ function RBS_CMN_GetFunction(filename, functionName) as object return invalid end function function RBS_CMN_GetFunctionBruteForce(functionName) as object - if (not RBS_CMN_IsNotEmptyString(functionName)) then return invalid + if (not RBS_CMN_IsNotEmptyString(functionName)) then return invalid filenames = RBSFM_getFilenames() for i = 0 to filenames.count() - 1 filename = filenames[i] @@ -1318,46 +1264,46 @@ function RBS_CMN_GetFunctionBruteForce(functionName) as object return invalid end function function RBS_CMN_IsBoolean(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifBoolean") <> invalid + return RBS_CMN_IsValid(value) and GetInterface(value, "ifBoolean") <> invalid end function function RBS_CMN_IsInteger(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifInt") <> invalid and (Type(value) = "roInt" or Type(value) = "roInteger" or Type(value) = "Integer") + return RBS_CMN_IsValid(value) and GetInterface(value, "ifInt") <> invalid and (Type(value) = "roInt" or Type(value) = "roInteger" or Type(value) = "Integer") end function function RBS_CMN_IsFloat(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifFloat") <> invalid + return RBS_CMN_IsValid(value) and GetInterface(value, "ifFloat") <> invalid end function function RBS_CMN_IsDouble(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifDouble") <> invalid + return RBS_CMN_IsValid(value) and GetInterface(value, "ifDouble") <> invalid end function function RBS_CMN_IsLongInteger(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifLongInt") <> invalid + return RBS_CMN_IsValid(value) and GetInterface(value, "ifLongInt") <> invalid end function function RBS_CMN_IsNumber(value) as boolean - return RBS_CMN_IsLongInteger(value) or RBS_CMN_IsDouble(value) or RBS_CMN_IsInteger(value) or RBS_CMN_IsFloat(value) + return RBS_CMN_IsLongInteger(value) or RBS_CMN_IsDouble(value) or RBS_CMN_IsInteger(value) or RBS_CMN_IsFloat(value) end function function RBS_CMN_IsList(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifList") <> invalid + return RBS_CMN_IsValid(value) and GetInterface(value, "ifList") <> invalid end function function RBS_CMN_IsArray(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifArray") <> invalid + return RBS_CMN_IsValid(value) and GetInterface(value, "ifArray") <> invalid end function function RBS_CMN_IsAssociativeArray(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifAssociativeArray") <> invalid + return RBS_CMN_IsValid(value) and GetInterface(value, "ifAssociativeArray") <> invalid end function function RBS_CMN_IsSGNode(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifSGNodeChildren") <> invalid + return RBS_CMN_IsValid(value) and GetInterface(value, "ifSGNodeChildren") <> invalid end function function RBS_CMN_IsString(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifString") <> invalid + return RBS_CMN_IsValid(value) and GetInterface(value, "ifString") <> invalid end function function RBS_CMN_IsNotEmptyString(value) as boolean - return RBS_CMN_IsString(value) and len(value) > 0 + return RBS_CMN_IsString(value) and len(value) > 0 end function function RBS_CMN_IsDateTime(value) as boolean - return RBS_CMN_IsValid(value) and (GetInterface(value, "ifDateTime") <> invalid or Type(value) = "roDateTime") + return RBS_CMN_IsValid(value) and (GetInterface(value, "ifDateTime") <> invalid or Type(value) = "roDateTime") end function function RBS_CMN_IsValid(value) as boolean - return not RBS_CMN_IsUndefined(value) and value <> invalid + return not RBS_CMN_IsUndefined(value) and value <> invalid end function function RBS_CMN_IsUndefined(value) as boolean return type(value) = "" or Type(value) = "" @@ -1370,13 +1316,13 @@ function RBS_CMN_ValidStr(obj) as string end if end function function RBS_CMN_AsString(input) as string - if RBS_CMN_IsValid(input) = false + if RBS_CMN_IsValid(input) = false return "" - else if RBS_CMN_IsString(input) + else if RBS_CMN_IsString(input) return input - else if RBS_CMN_IsInteger(input) or RBS_CMN_IsLongInteger(input) or RBS_CMN_IsBoolean(input) + else if RBS_CMN_IsInteger(input) or RBS_CMN_IsLongInteger(input) or RBS_CMN_IsBoolean(input) return input.ToStr() - else if RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) + else if RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) return Str(input).Trim() else if type(input) = "roSGNode" return "Node(" + input.subType() + ")" @@ -1389,7 +1335,7 @@ function RBS_CMN_AsString(input) as string end if for each key in input if key <> "__mocks" and key <> "__stubs" - text += key + ":" + RBS_CMN_AsString(input[key]) + text += key + ":" + RBS_CMN_AsString(input[key]) end if end for text += "}" @@ -1399,69 +1345,69 @@ function RBS_CMN_AsString(input) as string end if end function function RBS_CMN_AsInteger(input) as integer - if RBS_CMN_IsValid(input) = false + if RBS_CMN_IsValid(input) = false return 0 - else if RBS_CMN_IsString(input) + else if RBS_CMN_IsString(input) return input.ToInt() - else if RBS_CMN_IsInteger(input) + else if RBS_CMN_IsInteger(input) return input - else if RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) or RBS_CMN_IsLongInteger(input) + else if RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) or RBS_CMN_IsLongInteger(input) return Int(input) else return 0 end if end function function RBS_CMN_AsLongInteger(input) as longinteger - if RBS_CMN_IsValid(input) = false + if RBS_CMN_IsValid(input) = false return 0 - else if RBS_CMN_IsString(input) - return RBS_CMN_AsInteger(input) - else if RBS_CMN_IsLongInteger(input) or RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) or RBS_CMN_IsInteger(input) + else if RBS_CMN_IsString(input) + return RBS_CMN_AsInteger(input) + else if RBS_CMN_IsLongInteger(input) or RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) or RBS_CMN_IsInteger(input) return input else return 0 end if end function function RBS_CMN_AsFloat(input) as float - if RBS_CMN_IsValid(input) = false + if RBS_CMN_IsValid(input) = false return 0.0 - else if RBS_CMN_IsString(input) + else if RBS_CMN_IsString(input) return input.ToFloat() - else if RBS_CMN_IsInteger(input) + else if RBS_CMN_IsInteger(input) return (input / 1) - else if RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) or RBS_CMN_IsLongInteger(input) + else if RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) or RBS_CMN_IsLongInteger(input) return input else return 0.0 end if end function function RBS_CMN_AsDouble(input) as double - if RBS_CMN_IsValid(input) = false + if RBS_CMN_IsValid(input) = false return 0.0 - else if RBS_CMN_IsString(input) - return RBS_CMN_AsFloat(input) - else if RBS_CMN_IsInteger(input) or RBS_CMN_IsLongInteger(input) or RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) + else if RBS_CMN_IsString(input) + return RBS_CMN_AsFloat(input) + else if RBS_CMN_IsInteger(input) or RBS_CMN_IsLongInteger(input) or RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) return input else return 0.0 end if end function function RBS_CMN_AsBoolean(input) as boolean - if RBS_CMN_IsValid(input) = false + if RBS_CMN_IsValid(input) = false return false - else if RBS_CMN_IsString(input) + else if RBS_CMN_IsString(input) return LCase(input) = "true" - else if RBS_CMN_IsInteger(input) or RBS_CMN_IsFloat(input) + else if RBS_CMN_IsInteger(input) or RBS_CMN_IsFloat(input) return input <> 0 - else if RBS_CMN_IsBoolean(input) + else if RBS_CMN_IsBoolean(input) return input else return false end if end function function RBS_CMN_AsArray(value) as object - if RBS_CMN_IsValid(value) - if not RBS_CMN_IsArray(value) + if RBS_CMN_IsValid(value) + if not RBS_CMN_IsArray(value) return [value] else return value @@ -1470,17 +1416,17 @@ function RBS_CMN_AsArray(value) as object return [] end function function RBS_CMN_IsNullOrEmpty(value) as boolean - if RBS_CMN_IsString(value) + if RBS_CMN_IsString(value) return Len(value) = 0 else - return not RBS_CMN_IsValid(value) + return not RBS_CMN_IsValid(value) end if end function function RBS_CMN_FindElementIndexInArray(array , value , compareAttribute = invalid , caseSensitive = false) as integer - if RBS_CMN_IsArray(array) - for i = 0 to RBS_CMN_AsArray(array).Count() - 1 + if RBS_CMN_IsArray(array) + for i = 0 to RBS_CMN_AsArray(array).Count() - 1 compareValue = array[i] - if compareAttribute <> invalid and RBS_CMN_IsAssociativeArray(compareValue) + if compareAttribute <> invalid and RBS_CMN_IsAssociativeArray(compareValue) compareValue = compareValue.LookupCI(compareAttribute) end if if RBS_BTS_EqValues(compareValue, value) @@ -1516,7 +1462,7 @@ function RBS_ItG_GetTestCases(group) as object end if end function function RBS_ItG_GetRunnableTestSuite(group) as object - testCases = RBS_ItG_GetTestCases(group) + testCases = RBS_ItG_GetTestCases(group) runnableSuite = BaseTestSuite() runnableSuite.name = group.name runnableSuite.isLegacy = group.isLegacy = true @@ -1528,43 +1474,31 @@ function RBS_ItG_GetRunnableTestSuite(group) as object if (testCase.isSolo = true) name += " [SOLO] " end if - testFunction = RBS_CMN_GetFunction(group.filename, testCase.funcName) + testFunction = RBS_CMN_GetFunction(group.filename, testCase.funcName) runnableSuite.addTest(name, testFunction, testCase.funcName) group.testCaseLookup[name] = testCase end for - runnableSuite.SetUp = RBS_CMN_GetFunction(group.filename, group.setupFunctionName) + runnableSuite.SetUp = RBS_CMN_GetFunction(group.filename, group.setupFunctionName) runnableSuite.TearDown = RBS_CMN_GetFunction(group.filename, group.teardownFunctionName) runnableSuite.BeforeEach = RBS_CMN_GetFunction(group.filename, group.beforeEachFunctionName) runnableSuite.AfterEach = RBS_CMN_GetFunction(group.filename, group.afterEachFunctionName) return runnableSuite end function -function ItemGenerator(scheme as object) as object - this = {} - this.getItem = RBS_IG_GetItem - this.getAssocArray = RBS_IG_GetAssocArray - this.getArray = RBS_IG_GetArray - this.getSimpleType = RBS_IG_GetSimpleType - this.getInteger = RBS_IG_GetInteger - this.getFloat = RBS_IG_GetFloat - this.getString = RBS_IG_GetString - this.getBoolean = RBS_IG_GetBoolean - if not RBS_CMN_IsValid(scheme) - return invalid - end if - return this.getItem(scheme) + function RBS_IG_new() + m.isValid = RBS_CMN_IsValid(scheme) end function -function RBS_IG_GetItem(scheme as object) as object + function RBS_IG_GetItem(scheme as object) as object item = invalid - if RBS_CMN_IsAssociativeArray(scheme) + if RBS_CMN_IsAssociativeArray(scheme) item = m.getAssocArray(scheme) - else if RBS_CMN_IsArray(scheme) + else if RBS_CMN_IsArray(scheme) item = m.getArray(scheme) - else if RBS_CMN_IsString(scheme) + else if RBS_CMN_IsString(scheme) item = m.getSimpleType(lCase(scheme)) end if return item end function -function RBS_IG_GetAssocArray(scheme as object) as object + function RBS_IG_GetAssocArray(scheme as object) as object item = {} for each key in scheme if not item.DoesExist(key) @@ -1573,14 +1507,14 @@ function RBS_IG_GetAssocArray(scheme as object) as object end for return item end function -function RBS_IG_GetArray(scheme as object) as object + function RBS_IG_GetArray(scheme as object) as object item = [] for each key in scheme item.Push(m.getItem(key)) end for return item end function -function RBS_IG_GetSimpleType(typeStr as string) as object + function RBS_IG_GetSimpleType(typeStr as string) as object item = invalid if typeStr = "integer" or typeStr = "int" or typeStr = "roint" item = m.getInteger() @@ -1593,16 +1527,16 @@ function RBS_IG_GetSimpleType(typeStr as string) as object end if return item end function -function RBS_IG_GetBoolean() as boolean - return RBS_CMN_AsBoolean(Rnd(2) \ Rnd(2)) + function RBS_IG_GetBoolean() as boolean + return RBS_CMN_AsBoolean(Rnd(2) \ Rnd(2)) end function -function RBS_IG_GetInteger(seed = 100 as integer) as integer + function RBS_IG_GetInteger(seed = 100 as integer) as integer return Rnd(seed) end function -function RBS_IG_GetFloat() as float + function RBS_IG_GetFloat() as float return Rnd(0) end function -function RBS_IG_GetString(seed as integer) as string + function RBS_IG_GetString(seed as integer) as string item = "" if seed > 0 stringLength = Rnd(seed) @@ -1620,19 +1554,128 @@ function RBS_IG_GetString(seed as integer) as string end if return item end function -function UnitTestRuntimeConfig() - this = {} - this.CreateSuites = RBS_CreateSuites - this.hasSoloSuites = false - this.hasSoloGroups = false - this.hasSoloTests = false - this.suites = this.CreateSuites() - return this + function __ItemGenerator_builder() + instance = {} + ItemGenerator_instance = { + __className: "ItemGenerator" + __ItemGenerator: RBS_IG_new + GetItem: RBS_IG_GetItem + GetAssocArray: RBS_IG_GetAssocArray + GetArray: RBS_IG_GetArray + GetSimpleType: RBS_IG_GetSimpleType + GetBoolean: RBS_IG_GetBoolean + GetInteger: RBS_IG_GetInteger + GetFloat: RBS_IG_GetFloat + GetString: RBS_IG_GetString + } + instance.append(ItemGenerator_instance) + return instance + end function + function ItemGenerator() + instance = __ItemGenerator_builder() + instance.__ItemGenerator() + return instance + end function +function Rooibos__Init(preTestSetup = invalid, testUtilsDecoratorMethodName = invalid, testSceneName = invalid, nodeContext = invalid) as void + args = {} + if createObject("roAPPInfo").IsDev() <> true then + ? " not running in dev mode! - rooibos tests only support sideloaded builds - aborting" + return + end if + args.testUtilsDecoratorMethodName = testUtilsDecoratorMethodName + args.nodeContext = nodeContext + screen = CreateObject("roSGScreen") + m.port = CreateObject("roMessagePort") + screen.setMessagePort(m.port) + if testSceneName = invalid + testSceneName = "TestsScene" + end if + ? "Starting test using test scene with name TestsScene" ; testSceneName + scene = screen.CreateScene(testSceneName) + scene.id = "ROOT" + screen.show() + m.global = screen.getGlobalNode() + m.global.addFields({ "testsScene": scene }) + if (preTestSetup <> invalid) + preTestSetup(screen) + end if + testId = args.TestId + if (testId = invalid) + testId = "UNDEFINED_TEST_ID" + end if + ? "#########################################################################" + ? "#TEST START : ###" ; testId ; "###" + args.testScene = scene + args.global = m.global + rooibosVersion = "3.1.1" + requiredRooibosPreprocessorVersion = "1.0.0" + if not RBS_CMN_isFunction(RBSFM_getPreprocessorVersion) + versionError = "You are using a rooibos-preprocessor (i.e. rooibos-cli) version older than 1.0.0 - please update to " + requiredRooibosPreprocessorVersion + else + if Rooibos__versionCompare(RBSFM_getPreprocessorVersion(),requiredRooibosPreprocessorVersion) >= 0 + versionError = "" + else + versionError = "Your rooibos-preprocessor (i.e. rooibos-cli) version '" + RBSFM_getPreprocessorVersion() + "' is not compatible with rooibos version " + rooibosVersion + ". Please upgrade your rooibos-cli to version " + requiredRooibosPreprocessorVersion + end if + end if + if versionError = "" + ? "######################################################" + ? "" + ? "# rooibos framework version: " ; rooibosVersion + ? "# tests parsed with rooibosC version: " ; rooibosVersion + ? "######################################################" + ? "" + runner = TestRunner(args) + runner.Run() + while(true) + msg = wait(0, m.port) + msgType = type(msg) + if msgType = "roSGScreenEvent" + if msg.isScreenClosed() + return + end if + end if + end while + else + ? "" + ? "#########################################################" + ? "ERROR - VERSION MISMATCH" + ? versionError + ? "#########################################################" + end if +end function +function Rooibos__versionCompare(v1, v2) + v1parts = v1.split(".") + v2parts = v2.split(".") + while v1parts.count() < v2parts.count() + v1parts.push("0") + end while + while v2parts.count() < v1parts.count() + v2parts.push("0") + end while + for i = 0 to v1parts.count() + if (v2parts.count() = i) + return 1 + end if + if (v1parts[i] = v2parts[i]) + else if (v1parts[i] > v2parts[i]) + return 1 + else + return -1 + end if + end for + if (v1parts.count() <> v2parts.count()) + return -1 + end if + return 0 +end function + function RBS_UTRC_new() + m.suites = m.CreateSuites() end function -function RBS_CreateSuites() + function RBS_UTRC_CreateSuites() suites = RBSFM_getTestSuitesForProject() includedSuites = [] - for i = 0 to suites.count() -1 + for i = 0 to suites.count() - 1 suite = suites[i] if (suite.valid) if (suite.isSolo) @@ -1651,6 +1694,24 @@ function RBS_CreateSuites() end for return includedSuites end function + function __UnitTestRuntimeConfig_builder() + instance = {} + UnitTestRuntimeConfig_instance = { + __className: "UnitTestRuntimeConfig" + __UnitTestRuntimeConfig: RBS_UTRC_new + CreateSuites: RBS_UTRC_CreateSuites + hasSoloSuites: false + hasSoloGroups: false + hasSoloTests: false + } + instance.append(UnitTestRuntimeConfig_instance) + return instance + end function + function UnitTestRuntimeConfig() + instance = __UnitTestRuntimeConfig_builder() + instance.__UnitTestRuntimeConfig() + return instance + end function function RBS_STATS_CreateTotalStatistic() as object statTotalItem = { Suites : [] @@ -1703,9 +1764,9 @@ function RBS_STATS_CreateTestStatistic(name as string, result = "Success" as str return statTestItem end function sub RBS_STATS_AppendTestStatistic(statSuiteObj as object, statTestObj as object) - if RBS_CMN_IsAssociativeArray(statSuiteObj) and RBS_CMN_IsAssociativeArray(statTestObj) + if RBS_CMN_IsAssociativeArray(statSuiteObj) and RBS_CMN_IsAssociativeArray(statTestObj) statSuiteObj.Tests.Push(statTestObj) - if RBS_CMN_IsInteger(statTestObj.time) + if RBS_CMN_IsInteger(statTestObj.time) statSuiteObj.Time = statSuiteObj.Time + statTestObj.Time end if statSuiteObj.Total = statSuiteObj.Total + 1 @@ -1719,75 +1780,89 @@ sub RBS_STATS_AppendTestStatistic(statSuiteObj as object, statTestObj as object) end if end sub sub RBS_STATS_AppendSuiteStatistic(statTotalObj as object, statSuiteObj as object) - if RBS_CMN_IsAssociativeArray(statTotalObj) and RBS_CMN_IsAssociativeArray(statSuiteObj) + if RBS_CMN_IsAssociativeArray(statTotalObj) and RBS_CMN_IsAssociativeArray(statSuiteObj) statTotalObj.Suites.Push(statSuiteObj) statTotalObj.Time = statTotalObj.Time + statSuiteObj.Time - if RBS_CMN_IsInteger(statSuiteObj.Total) + if RBS_CMN_IsInteger(statSuiteObj.Total) statTotalObj.Total = statTotalObj.Total + statSuiteObj.Total end if - if RBS_CMN_IsInteger(statSuiteObj.Correct) + if RBS_CMN_IsInteger(statSuiteObj.Correct) statTotalObj.Correct = statTotalObj.Correct + statSuiteObj.Correct end if - if RBS_CMN_IsInteger(statSuiteObj.Fail) + if RBS_CMN_IsInteger(statSuiteObj.Fail) statTotalObj.Fail = statTotalObj.Fail + statSuiteObj.Fail end if - if RBS_CMN_IsInteger(statSuiteObj.Crash) + if RBS_CMN_IsInteger(statSuiteObj.Crash) statTotalObj.Crash = statTotalObj.Crash + statSuiteObj.Crash end if end if end sub -function UnitTestCase(name as string, func as dynamic, funcName as string, isSolo as boolean, isIgnored as boolean, lineNumber as integer, params = invalid, paramTestIndex =0, paramLineNumber = 0) - this = {} - this.isSolo = isSolo - this.func = func - this.funcName = funcName - this.isIgnored = isIgnored - this.name = name - this.lineNumber = lineNumber - this.paramLineNumber = paramLineNumber - this.assertIndex = 0 - this.assertLineNumberMap = {} - this.AddAssertLine = RBS_TC_AddAssertLine - this.getTestLineIndex = 0 - this.rawParams = params - this.paramTestIndex = paramTestIndex - this.isParamTest = false - this.time = 0 + function RBS_TC_new(name as string, func as dynamic, funcName as string, isSolo as boolean, isIgnored as boolean, lineNumber as integer, params = invalid, paramTestIndex = 0, paramLineNumber = 0) + m.isSolo = isSolo + m.func = func + m.funcName = funcName + m.isIgnored = isIgnored + m.name = name + m.lineNumber = lineNumber + m.paramLineNumber = paramLineNumber + m.rawParams = params + m.paramTestIndex = paramTestIndex if (params <> invalid) - this.name += stri(this.paramTestIndex) + m.name += stri(m.paramTestIndex) end if return this end function -function RBS_TC_AddAssertLine(lineNumber as integer) + function RBS_TC_AddAssertLine(lineNumber as integer) m.assertLineNumberMap[stri(m.assertIndex).trim()] = lineNumber m.assertIndex++ end function -function RBS_TC_GetAssertLine(testCase, index) + function RBS_TC_GetAssertLine(testCase, index) if (testCase.assertLineNumberMap.doesExist(stri(index).trim())) return testCase.assertLineNumberMap[stri(index).trim()] else return testCase.lineNumber end if end function -function Logger(config) as object - this = {} - this.config = config - this.verbosityLevel = { + function __UnitTestCase_builder() + instance = {} + UnitTestCase_instance = { + __className: "UnitTestCase" + __UnitTestCase: RBS_TC_new + AddAssertLine: RBS_TC_AddAssertLine + GetAssertLine: RBS_TC_GetAssertLine + isSolo: invalid + func: invalid + funcName: invalid + isIgnored: invalid + name: invalid + lineNumber: invalid + paramLineNumber: invalid + assertIndex: 0 + assertLineNumberMap: {} + getTestLineIndex: 0 + rawParams: invalid + paramTestIndex: invalid + isParamTest: false + time: 0 + } + instance.append(UnitTestCase_instance) + return instance + end function + function UnitTestCase(name as string, func as dynamic, funcName as string, isSolo as boolean, isIgnored as boolean, lineNumber as integer, params = invalid, paramTestIndex = 0, paramLineNumber = 0) + instance = __UnitTestCase_builder() + instance.__UnitTestCase(name, func, funcName, isSolo, isIgnored, lineNumber, params, paramTestIndex, paramLineNumber) + return instance + end function + function RBS_LOGGER_new(config) + m.config = config + m.verbosityLevel = { basic : 0 normal : 1 verbose : 2 } - this.verbosity = this.config.logLevel - this.PrintStatistic = RBS_LOGGER_PrintStatistic - this.PrintMetaSuiteStart = RBS_LOGGER_PrintMetaSuiteStart - this.PrintSuiteStatistic = RBS_LOGGER_PrintSuiteStatistic - this.PrintTestStatistic = RBS_LOGGER_PrintTestStatistic - this.PrintStart = RBS_LOGGER_PrintStart - this.PrintEnd = RBS_LOGGER_PrintEnd - this.PrintSuiteStart = RBS_LOGGER_PrintSuiteStart - return this + m.verbosity = m.config.logLevel end function -sub RBS_LOGGER_PrintStatistic(statObj as object) + sub RBS_LOGGER_PrintStatistic(statObj as object) m.PrintStart() previousfile = invalid for each testSuite in statObj.Suites @@ -1802,7 +1877,7 @@ sub RBS_LOGGER_PrintStatistic(statObj as object) ? "" m.PrintEnd() ignoredInfo = RBSFM_getIgnoredTestInfo() - ? "Total = "; RBS_CMN_AsString(statObj.Total); " ; Passed = "; statObj.Correct; " ; Failed = "; statObj.Fail; " ; Ignored = "; ignoredInfo.count + ? "Total = "; RBS_CMN_AsString(statObj.Total); " ; Passed = "; statObj.Correct; " ; Failed = "; statObj.Fail; " ; Ignored = "; ignoredInfo.count ? " Time spent: "; statObj.Time; "ms" ? "" ? "" @@ -1825,7 +1900,7 @@ sub RBS_LOGGER_PrintStatistic(statObj as object) end if ? "RESULT: "; overrallResult end sub -sub RBS_LOGGER_PrintSuiteStatistic(statSuiteObj as object, hasFailures) + sub RBS_LOGGER_PrintSuiteStatistic(statSuiteObj as object, hasFailures) m.PrintSuiteStart(statSuiteObj.Name) for each testCase in statSuiteObj.Tests if (not hasFailures or ((not m.config.showOnlyFailures) or testCase.Result <> "Success")) @@ -1834,7 +1909,7 @@ sub RBS_LOGGER_PrintSuiteStatistic(statSuiteObj as object, hasFailures) end for ? " |" end sub -sub RBS_LOGGER_PrintTestStatistic(testCase as object) + sub RBS_LOGGER_PrintTestStatistic(testCase as object) metaTestCase = testCase.metaTestCase if (LCase(testCase.Result) <> "success") testChar = "-" @@ -1858,7 +1933,7 @@ sub RBS_LOGGER_PrintTestStatistic(testCase as object) end if if (metaTestcase.isParamTest = true) insetText = " " - messageLine = RBS_LOGGER_FillText(" " + testChar + insetText + " |--" + formatJson(metaTestCase.rawParams) + " : ", ".", 80) + messageLine = m.fillText(" " + testChar + insetText + " |--" + formatJson(metaTestCase.rawParams) + " : ", ".", 80) ? messageLine ; testCase.Result ; " (" + stri(metaTestCase.time).trim() +"ms)" end if if LCase(testCase.Result) <> "success" @@ -1869,7 +1944,7 @@ sub RBS_LOGGER_PrintTestStatistic(testCase as object) ? " | "; insettext ;" |--Error Message: "; testCase.Error.Message end if end sub -function RBS_LOGGER_FillText(text as string, fillChar = " ", numChars = 40) as string + function RBS_LOGGER_FillText(text as string, fillChar = " ", numChars = 40) as string if (len(text) >= numChars) text = left(text, numChars - 5) + "..." + fillChar + fillChar else @@ -1880,94 +1955,81 @@ function RBS_LOGGER_FillText(text as string, fillChar = " ", numChars = 40) as s end if return text end function -sub RBS_LOGGER_PrintStart() + sub RBS_LOGGER_PrintStart() ? "" ? "[START TEST REPORT]" ? "" end sub -sub RBS_LOGGER_PrintEnd() + sub RBS_LOGGER_PrintEnd() ? "" ? "[END TEST REPORT]" ? "" end sub -sub RBS_LOGGER_PrintSuiteSetUp(sName as string) + sub RBS_LOGGER_PrintSuiteSetUp(sName as string) if m.verbosity = m.verbosityLevel.verbose ? "=================================================================" ? "=== SetUp "; sName; " suite." ? "=================================================================" end if end sub -sub RBS_LOGGER_PrintMetaSuiteStart(metaTestSuite) + sub RBS_LOGGER_PrintMetaSuiteStart(metaTestSuite) ? metaTestSuite.name; " " ; "pkg:/" ; metaTestSuite.filePath + "(1)" end sub -sub RBS_LOGGER_PrintSuiteStart(sName as string) + sub RBS_LOGGER_PrintSuiteStart(sName as string) ? " |-" ; sName end sub -sub RBS_LOGGER_PrintSuiteTearDown(sName as string) + sub RBS_LOGGER_PrintSuiteTearDown(sName as string) if m.verbosity = m.verbosityLevel.verbose ? "=================================================================" ? "=== TearDown "; sName; " suite." ? "=================================================================" end if end sub -sub RBS_LOGGER_PrintTestSetUp(tName as string) + sub RBS_LOGGER_PrintTestSetUp(tName as string) if m.verbosity = m.verbosityLevel.verbose ? "----------------------------------------------------------------" ? "--- SetUp "; tName; " test." ? "----------------------------------------------------------------" end if end sub -sub RBS_LOGGER_PrintTestTearDown(tName as string) + sub RBS_LOGGER_PrintTestTearDown(tName as string) if m.verbosity = m.verbosityLevel.verbose ? "----------------------------------------------------------------" ? "--- TearDown "; tName; " test." ? "----------------------------------------------------------------" end if end sub -function UnitTestResult() as object - this = {} - this.messages = CreateObject("roArray", 0, true) - this.isFail = false - this.currentAssertIndex = 0 - this.failedAssertIndex = 0 - this.Reset = RBS_TRes_Reset - this.AddResult = RBS_TRes_AddResult - this.GetResult = RBS_TRes_GetResult - return this -end function -function RBS_TRes_Reset() as void - m.isFail = false - m.messages = CreateObject("roArray", 0, true) -end function -function RBS_TRes_AddResult(message as string) as string - if (message <> "") - m.messages.push(message) - if (not m.isFail) - m.failedAssertIndex = m.currentAssertIndex - end if - m.isFail = true - end if - m.currentAssertIndex++ - return message -end function -function RBS_TRes_GetResult() as string - if (m.isFail) - msg = m.messages.peek() - if (msg <> invalid) - return msg - else - return "unknown test failure" - end if - else - return "" - end if -end function -function RBS_TR_TestRunner(args = {}) as object - this = {} - this.testScene = args.testScene - this.nodeContext = args.nodeContext + function __Logger_builder() + instance = {} + Logger_instance = { + __className: "Logger" + __Logger: RBS_LOGGER_new + PrintStatistic: RBS_LOGGER_PrintStatistic + PrintSuiteStatistic: RBS_LOGGER_PrintSuiteStatistic + PrintTestStatistic: RBS_LOGGER_PrintTestStatistic + FillText: RBS_LOGGER_FillText + PrintStart: RBS_LOGGER_PrintStart + PrintEnd: RBS_LOGGER_PrintEnd + PrintSuiteSetUp: RBS_LOGGER_PrintSuiteSetUp + PrintMetaSuiteStart: RBS_LOGGER_PrintMetaSuiteStart + PrintSuiteStart: RBS_LOGGER_PrintSuiteStart + PrintSuiteTearDown: RBS_LOGGER_PrintSuiteTearDown + PrintTestSetUp: RBS_LOGGER_PrintTestSetUp + PrintTestTearDown: RBS_LOGGER_PrintTestTearDown + } + instance.append(Logger_instance) + return instance + end function + function Logger(config) + instance = __Logger_builder() + instance.__Logger(config) + return instance + end function + function RBS_TR_new(args = {}) + m.testScene = args.testScene + m.nodeContext = args.nodeContext config = RBSFM_getRuntimeConfig() - if (config = invalid or not RBS_CMN_IsAssociativeArray(config)) + if (config = invalid or not RBS_CMN_IsAssociativeArray(config)) ? "WARNING : specified config is invalid - using default" config = { showOnlyFailures: false @@ -1980,20 +2042,18 @@ function RBS_TR_TestRunner(args = {}) as object if (args.failFast <> invalid) config.failFast = args.failFast = "true" end if - this.testUtilsDecoratorMethodName = args.testUtilsDecoratorMethodName - this.config = config - this.config.testsDirectory = config.testsDirectory - this.logger = Logger(this.config) - this.global = args.global - this.Run = RBS_TR_Run - return this + m.testUtilsDecoratorMethodName = args.testUtilsDecoratorMethodName + m.config = config + m.config.testsDirectory = config.testsDirectory + m.logger = Logger(m.config) + m.global = args.global end function -sub RBS_TR_Run() + sub RBS_TR_Run() if type(RBSFM_getTestSuitesForProject) <> "Function" ? " ERROR! RBSFM_getTestSuitesForProject is not found! That looks like you didn't run the preprocessor as part of your test process. Please refer to the docs." return end if - totalStatObj = RBS_STATS_CreateTotalStatistic() + totalStatObj = RBS_STATS_CreateTotalStatistic() m.runtimeConfig = UnitTestRuntimeConfig() m.runtimeConfig.global = m.global totalStatObj.testRunHasFailures = false @@ -2034,7 +2094,7 @@ sub RBS_TR_Run() "runtimeConfig": m.runtimeConfig } nodeStatResults = node.callFunc("Rooibos_RunNodeTests", args) - RBS_STATS_MergeTotalStatistic(totalStatObj, nodeStatResults) + RBS_STATS_MergeTotalStatistic(totalStatObj, nodeStatResults) m.testScene.RemoveChild(node) else ? " ERROR!! - could not create node required to execute tests for " ; metaTestSuite.name @@ -2044,25 +2104,25 @@ sub RBS_TR_Run() if (metaTestSuite.hasIgnoredTests) totalStatObj.IgnoredTestNames.push("|-" + metaTestSuite.name) end if - RBS_RT_RunItGroups(metaTestSuite, totalStatObj, m.testUtilsDecoratorMethodName, m.config, m.runtimeConfig, m.nodeContext) + RBS_TR_RunItGroups(metaTestSuite, totalStatObj, m.testUtilsDecoratorMethodName, m.config, m.runtimeConfig, m.nodeContext) end if skipSuite: end for m.logger.PrintStatistic(totalStatObj) - if RBS_CMN_IsFunction(RBS_ReportCodeCoverage) - RBS_ReportCodeCoverage() + if RBS_CMN_IsFunction(RBS_TR_ReportCodeCoverage) + RBS_TR_ReportCodeCoverage() end if RBS_TR_SendHomeKeypress() end sub -sub RBS_RT_RunItGroups(metaTestSuite, totalStatObj, testUtilsDecoratorMethodName, config, runtimeConfig, nodeContext = invalid) + sub RBS_TR_RunItGroups(metaTestSuite, totalStatObj, testUtilsDecoratorMethodName, config, runtimeConfig, nodeContext = invalid) if (testUtilsDecoratorMethodName <> invalid) - testUtilsDecorator = RBS_CMN_GetFunctionBruteForce(testUtilsDecoratorMethodName) - if (not RBS_CMN_IsFunction(testUtilsDecorator)) + testUtilsDecorator = RBS_CMN_GetFunctionBruteForce(testUtilsDecoratorMethodName) + if (not RBS_CMN_IsFunction(testUtilsDecorator)) ? "[ERROR] Test utils decorator method `" ; testUtilsDecoratorMethodName ;"` was not in scope! for testSuite: " + metaTestSuite.name end if end if for each itGroup in metaTestSuite.itGroups - testSuite = RBS_ItG_GetRunnableTestSuite(itGroup) + testSuite = RBS_ItG_GetRunnableTestSuite(itGroup) if (nodeContext <> invalid) testSuite.node = nodeContext testSuite.global = nodeContext.global @@ -2114,11 +2174,11 @@ sub RBS_RT_RunItGroups(metaTestSuite, totalStatObj, testUtilsDecoratorMethodName end if goto skipItGroup end if - if RBS_CMN_IsFunction(testSuite.SetUp) + if RBS_CMN_IsFunction(testSuite.SetUp) testSuite.SetUp() end if - RBS_RT_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, runtimeConfig) - if RBS_CMN_IsFunction(testSuite.TearDown) + RBS_TR_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, runtimeConfig) + if RBS_CMN_IsFunction(testSuite.TearDown) testSuite.TearDown() end if if (totalStatObj.testRunHasFailures = true and config.failFast = true) @@ -2127,8 +2187,8 @@ sub RBS_RT_RunItGroups(metaTestSuite, totalStatObj, testUtilsDecoratorMethodName skipItGroup: end for end sub -sub RBS_RT_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, runtimeConfig) - suiteStatObj = RBS_STATS_CreateSuiteStatistic(itGroup.Name) + sub RBS_TR_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, runtimeConfig) + suiteStatObj = RBS_STATS_CreateSuiteStatistic(itGroup.Name) testSuite.global = runtimeConfig.global for each testCase in testSuite.testCases metaTestCase = itGroup.testCaseLookup[testCase.Name] @@ -2136,12 +2196,12 @@ sub RBS_RT_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, if (runtimeConfig.hasSoloTests and not metaTestCase.isSolo) goto skipTestCase end if - if RBS_CMN_IsFunction(testSuite.beforeEach) + if RBS_CMN_IsFunction(testSuite.beforeEach) testSuite.beforeEach() end if testTimer = CreateObject("roTimespan") testCaseTimer = CreateObject("roTimespan") - testStatObj = RBS_STATS_CreateTestStatistic(testCase.Name) + testStatObj = RBS_STATS_CreateTestStatistic(testCase.Name) testSuite.testCase = testCase.Func testStatObj.filePath = metaTestSuite.filePath testStatObj.metaTestCase = metaTestCase @@ -2199,8 +2259,8 @@ sub RBS_RT_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, testStatObj.Result = "Success" end if testStatObj.Time = testTimer.TotalMilliseconds() - RBS_STATS_AppendTestStatistic(suiteStatObj, testStatObj) - if RBS_CMN_IsFunction(testSuite.afterEach) + RBS_STATS_AppendTestStatistic(suiteStatObj, testStatObj) + if RBS_CMN_IsFunction(testSuite.afterEach) testSuite.afterEach() end if if testStatObj.Result <> "Success" @@ -2214,18 +2274,18 @@ sub RBS_RT_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, suiteStatObj.metaTestSuite = metaTestSuite RBS_STATS_AppendSuiteStatistic(totalStatObj, suiteStatObj) end sub -sub RBS_TR_SendHomeKeypress() + sub RBS_TR_SendHomeKeypress() ut = CreateObject("roUrlTransfer") ut.SetUrl("http://localhost:8060/keypress/Home") ut.PostFromString("") end sub -function Rooibos_RunNodeTests(args) as object +function RBS_TR_Rooibos_RunNodeTests(args) as object ? " RUNNING NODE TESTS" - totalStatObj = RBS_STATS_CreateTotalStatistic() - RBS_RT_RunItGroups(args.metaTestSuite, totalStatObj, args.testUtilsDecoratorMethodName, args.config, args.runtimeConfig, m) + totalStatObj = RBS_STATS_CreateTotalStatistic() + RBS_TR_RunItGroups(args.metaTestSuite, totalStatObj, args.testUtilsDecoratorMethodName, args.config, args.runtimeConfig, m) return totalStatObj end function -function Rooibos_CreateTestNode(nodeType) as object +function RBS_TR_Rooibos_CreateTestNode(nodeType) as object node = createObject("roSGNode", nodeType) if (type(node) = "roSGNode" and node.subType() = nodeType) m.top.AppendChild(node) @@ -2234,4 +2294,72 @@ function Rooibos_CreateTestNode(nodeType) as object ? " Error creating test node of type " ; nodeType return invalid end if -end function \ No newline at end of file +end function + function __TestRunner_builder() + instance = {} + TestRunner_instance = { + __className: "TestRunner" + __TestRunner: RBS_TR_new + Run: RBS_TR_Run + RunItGroups: RBS_TR_RunItGroups + RunTestCases: RBS_TR_RunTestCases + SendHomeKeypress: RBS_TR_SendHomeKeypress + } + instance.append(TestRunner_instance) + return instance + end function + function TestRunner(args = {}) + instance = __TestRunner_builder() + instance.__TestRunner(args) + return instance + end function + function RBS_UTR_Reset() as void + m.isFail = false + m.messages = CreateObject("roArray", 0, true) +end function + function RBS_UTR_AddResult(message as string) as string + if (message <> "") + m.messages.push(message) + if (not m.isFail) + m.failedAssertIndex = m.currentAssertIndex + end if + m.isFail = true + end if + m.currentAssertIndex++ + return message +end function + function RBS_UTR_GetResult() as string + if (m.isFail) + msg = m.messages.peek() + if (msg <> invalid) + return msg + else + return "unknown test failure" + end if + else + return "" + end if +end function + function __UnitTestResult_builder() + instance = {} + UnitTestResult_instance = { + __className: "UnitTestResult" + __UnitTestResult: RBS_UTR_UnitTestResult_new_ + Reset: RBS_UTR_Reset + AddResult: RBS_UTR_AddResult + GetResult: RBS_UTR_GetResult + messages: CreateObject("roArray", 0, true) + isFail: false + currentAssertIndex: 0 + failedAssertIndex: 0 + } + instance.append(UnitTestResult_instance) + return instance + end function + function UnitTestResult() + instance = __UnitTestResult_builder() + instance.__UnitTestResult() + return instance + end function + function RBS_UTR_UnitTestResult_new_() + end function \ No newline at end of file diff --git a/src/Rooibos_BaseTestSuite.brs b/src/BaseTestSuite.bs similarity index 69% rename from src/Rooibos_BaseTestSuite.brs rename to src/BaseTestSuite.bs index 1d2f7605..9b036726 100644 --- a/src/Rooibos_BaseTestSuite.brs +++ b/src/BaseTestSuite.bs @@ -1,112 +1,20 @@ +namespace RBS_BTS + ' /** ' * @module BaseTestSuite ' * @description All brs files that include `'@TestSuite` annotations automatically extend the BaseTestSuite. ' * The base test suite contains all of the assertions, and utility methods required to writey our tests, as well as being responsible for tracking the state of the tests and groups. ' */ +class BaseTestSuite -function BaseTestSuite() as object - - this = {} - this.Name = "BaseTestSuite" - this.invalidValue = "#ROIBOS#INVALID_VALUE" ' special value used in mock arguments - this.ignoreValue = "#ROIBOS#IGNORE_VALUE" ' special value used in mock arguments - this.allowNonExistingMethodsOnMocks = true - this.isAutoAssertingMocks = true - - 'Test Cases methods - this.TestCases = [] - this.AddTest = RBS_BTS_AddTest - this.CreateTest = RBS_BTS_CreateTest - - 'Assertion methods which determine test failure - this.GetLegacyCompatibleReturnValue = RBS_BTS_GetLegacyCompatibleReturnValue - this.Fail = RBS_BTS_Fail - this.AssertFalse = RBS_BTS_AssertFalse - this.AssertTrue = RBS_BTS_AssertTrue - this.AssertEqual = RBS_BTS_AssertEqual - this.AssertLike = RBS_BTS_AssertLike - this.AssertNotEqual = RBS_BTS_AssertNotEqual - this.AssertInvalid = RBS_BTS_AssertInvalid - this.AssertNotInvalid = RBS_BTS_AssertNotInvalid - this.AssertAAHasKey = RBS_BTS_AssertAAHasKey - this.AssertAANotHasKey = RBS_BTS_AssertAANotHasKey - this.AssertAAHasKeys = RBS_BTS_AssertAAHasKeys - this.AssertAANotHasKeys = RBS_BTS_AssertAANotHasKeys - this.AssertArrayContains = RBS_BTS_AssertArrayContains - this.AssertArrayNotContains = RBS_BTS_AssertArrayNotContains - this.AssertArrayContainsSubset = RBS_BTS_AssertArrayContainsSubset - this.AssertArrayContainsAAs = RBS_BTS_AssertArrayContainsAAs - this.AssertArrayNotContainsSubset = RBS_BTS_AssertArrayNotContainsSubset - this.AssertArrayCount = RBS_BTS_AssertArrayCount - this.AssertArrayNotCount = RBS_BTS_AssertArrayNotCount - this.AssertEmpty = RBS_BTS_AssertEmpty - this.AssertNotEmpty = RBS_BTS_AssertNotEmpty - this.AssertArrayContainsOnlyValuesOfType = RBS_BTS_AssertArrayContainsOnlyValuesOfType - this.AssertType = RBS_BTS_AssertType - this.AssertSubType = RBS_BTS_AssertSubType - - 'Node extensions - this.AssertNodeCount = RBS_BTS_AssertNodeCount - this.AssertNodeNotCount = RBS_BTS_AssertNodeNotCount - this.AssertNodeEmpty = RBS_BTS_AssertNodeEmpty - this.AssertNodeNotEmpty = RBS_BTS_AssertNodenotEmpty - - this.AssertNodeContains = RBS_BTS_AssertNodeContains - this.AssertNodeNotContains = RBS_BTS_AssertNodeNotContains - this.AssertNodeContainsFields = RBS_BTS_AssertNodeContainsFields - this.AssertNodeNotContainsFields = RBS_BTS_AssertNodeNotContainsFields - this.AssertAAContainsSubset = RBS_BTS_AssertAAContainsSubset - - 'Type Comparison Functionality - this.EqValues = RBS_BTS_EqValues - this.EqAssocArrays = RBS_BTS_EqAssocArray - this.EqArray = RBS_BTS_EqArray - - 'Mocking and stubbing - - this.Stub = RBS_BTS_Stub - this.Mock = RBS_BTS_Mock - this.AssertMocks = RBS_BTS_AssertMocks - this.CreateFake = RBS_BTS_CreateFake - this.CombineFakes = RBS_BTS_CombineFakes - this.MockFail = RBS_BTS_MockFail - this.CleanMocks = RBS_BTS_CleanMocks - this.CleanStubs = RBS_BTS_CleanStubs - - 'Mocking short hand methods - this.ExpectOnce = RBS_BTS_ExpectOnce - this.ExpectNone = RBS_BTS_ExpectNone - this.Expect = RBS_BTS_Expect - this.ExpectOnceOrNone = RBS_BTS_ExpectOnceOrNone - - - 'note the following callbacks are mapped as we don't have reflection in brightscript - 'and we need context to know what fields are called - 'I avoided using eval, as I don't know what threads tests might run in - 'so dont' want to risk srewing with people's lives - - 'Callback mapping - mocks - this.MockCallback0 = RBS_BTS_MockCallback0 - this.MockCallback1 = RBS_BTS_MockCallback1 - this.MockCallback2 = RBS_BTS_MockCallback2 - this.MockCallback3 = RBS_BTS_MockCallback3 - this.MockCallback4 = RBS_BTS_MockCallback4 - this.MockCallback5 = RBS_BTS_MockCallback5 - - - 'Callback mapping - Stubs - this.StubCallback0 = RBS_BTS_StubCallback0 - this.StubCallback1 = RBS_BTS_StubCallback1 - this.StubCallback2 = RBS_BTS_StubCallback2 - this.StubCallback3 = RBS_BTS_StubCallback3 - this.StubCallback4 = RBS_BTS_StubCallback4 - this.StubCallback5 = RBS_BTS_StubCallback5 - - 'utility functions to make life nicer - this.pathAsArray_ = RBS_BTS_rodash_pathsAsArray_ - this.g = RBS_BTS_rodash_get_ - return this -end function +public Name = "BaseTestSuite" +public invalidValue = "#ROIBOS#INVALID_VALUE" ' special value used in mock arguments +public ignoreValue = "#ROIBOS#IGNORE_VALUE" ' special value used in mock arguments +public allowNonExistingMethodsOnMocks = true +public isAutoAssertingMocks = true + +'Test Cases methods +public TestCases = [] ' /** ' * @memberof module:BaseTestSuite @@ -117,9 +25,9 @@ end function ' * @param {Dynamic} name - A test name. ' * @param {Dynamic} func - A test function name. ' */ -sub RBS_BTS_AddTest(name, func,funcName, setup = invalid, teardown = invalid) +public function AddTest(name, func, funcName, setup = invalid, teardown = invalid) m.testCases.Push(m.createTest(name, func, setup, teardown)) -end sub +end function ' /** ' * @memberof module:BaseTestSuite @@ -130,12 +38,12 @@ end sub ' * @param {Dynamic} name - A test name. ' * @param {Dynamic} func - A test function name. ' */ -function RBS_BTS_CreateTest(name, func, funcName, setup = invalid, teardown = invalid ) as object - +public function CreateTest(name, func, funcName, setup = invalid, teardown = invalid) as object + if (func = invalid) ? " ASKED TO CREATE TEST WITH INVALID FUNCITON POINTER FOR FUNCTION " ; funcName end if - + return { Name: name Func: func @@ -154,7 +62,7 @@ end function ' * @param {Dynamic} [msg=""] - message to display in the test report ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_Fail(msg = "Error" ) as dynamic +public function Fail(msg = "Error") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) @@ -164,7 +72,7 @@ end function '** GetLegacyCompatibleReturnValue '** will return the correct type of return value for a new-style/legacy test '************************************************************* -function RBS_BTS_GetLegacyCompatibleReturnValue(value) as object +public function GetLegacyCompatibleReturnValue(value) as object if (value = true) if (m.isLegacy = true) return "" @@ -190,9 +98,9 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' Default value: "Expression evaluates to true"' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertFalse(expr , msg = "Expression evaluates to true" ) as dynamic +public function AssertFalse(expr , msg = "Expression evaluates to true") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if not RBS_CMN_IsBoolean(expr) or expr + if not RBS_CMN.IsBoolean(expr) or expr m.currentResult.AddResult(msg) return m.fail(msg) end if @@ -210,9 +118,9 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertTrue(expr , msg = "Expression evaluates to false" ) as dynamic +public function AssertTrue(expr , msg = "Expression evaluates to false") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if not RBS_CMN_IsBoolean(expr) or not expr then + if not RBS_CMN.IsBoolean(expr) or not expr then m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -231,12 +139,12 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertEqual(first , second , msg = "" ) as dynamic +public function AssertEqual(first , second , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if not m.eqValues(first, second) if msg = "" - first_as_string = RBS_CMN_AsString(first) - second_as_string = RBS_CMN_AsString(second) + first_as_string = RBS_CMN.AsString(first) + second_as_string = RBS_CMN.AsString(second) msg = first_as_string + " != " + second_as_string end if m.currentResult.AddResult(msg) @@ -257,12 +165,12 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertLike(first , second , msg = "" ) as dynamic +public function AssertLike(first , second , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if first <> second if msg = "" - first_as_string = RBS_CMN_AsString(first) - second_as_string = RBS_CMN_AsString(second) + first_as_string = RBS_CMN.AsString(first) + second_as_string = RBS_CMN.AsString(second) msg = first_as_string + " != " + second_as_string end if m.currentResult.AddResult(msg) @@ -283,12 +191,12 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertNotEqual(first , second , msg = "" ) as dynamic +public function AssertNotEqual(first , second , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if m.eqValues(first, second) if msg = "" - first_as_string = RBS_CMN_AsString(first) - second_as_string = RBS_CMN_AsString(second) + first_as_string = RBS_CMN.AsString(first) + second_as_string = RBS_CMN.AsString(second) msg = first_as_string + " == " + second_as_string end if m.currentResult.AddResult(msg) @@ -308,11 +216,11 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertInvalid(value , msg = "" ) as dynamic +public function AssertInvalid(value , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if value <> invalid if msg = "" - expr_as_string = RBS_CMN_AsString(value) + expr_as_string = RBS_CMN.AsString(value) msg = expr_as_string + " <> Invalid" end if m.currentResult.AddResult(msg) @@ -332,11 +240,11 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertNotInvalid(value , msg = "" ) as dynamic +public function AssertNotInvalid(value , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if value = invalid if msg = "" - expr_as_string = RBS_CMN_AsString(value) + expr_as_string = RBS_CMN.AsString(value) msg = expr_as_string + " = Invalid" end if m.currentResult.AddResult(msg) @@ -357,9 +265,9 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertAAHasKey(array , key , msg = "" ) as dynamic +public function AssertAAHasKey(array , key , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) + if RBS_CMN.IsAssociativeArray(array) if not array.DoesExist(key) if msg = "" msg = "Array doesn't have the '" + key + "' key." @@ -387,9 +295,9 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertAANotHasKey(array , key , msg = "" ) as dynamic +public function AssertAANotHasKey(array , key , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) + if RBS_CMN.IsAssociativeArray(array) if array.DoesExist(key) if msg = "" msg = "Array has the '" + key + "' key." @@ -417,9 +325,9 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertAAHasKeys(array , keys , msg = "" ) as dynamic +public function AssertAAHasKeys(array , keys , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsArray(keys) + if RBS_CMN.IsAssociativeArray(array) and RBS_CMN.IsArray(keys) for each key in keys if not array.DoesExist(key) if msg = "" @@ -449,9 +357,9 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertAANotHasKeys(array , keys , msg = "" ) as dynamic +public function AssertAANotHasKeys(array , keys , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsArray(keys) + if RBS_CMN.IsAssociativeArray(array) and RBS_CMN.IsArray(keys) for each key in keys if array.DoesExist(key) if msg = "" @@ -484,11 +392,11 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertArrayContains(array , value , key = invalid , msg = "" ) as dynamic +public function AssertArrayContains(array , value , key = invalid , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) - if not RBS_CMN_ArrayContains(array, value, key) - msg = "Array doesn't have the '" + RBS_CMN_AsString(value) + "' value." + if RBS_CMN.IsAssociativeArray(array) or RBS_CMN.IsArray(array) + if not RBS_CMN.ArrayContains(array, value, key) + msg = "Array doesn't have the '" + RBS_CMN.AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -512,20 +420,20 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertArrayContainsAAs(array , values , msg = "" ) as dynamic +public function AssertArrayContainsAAs(array , values , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - - if not RBS_CMN_IsArray(values) + + if not RBS_CMN.IsArray(values) msg = "values to search for are not an Array." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if - - if RBS_CMN_IsArray(array) + + if RBS_CMN.IsArray(array) for each value in values isMatched = false - if not RBS_CMN_IsAssociativeArray(value) - msg = "Value to search for was not associativeArray "+ RBS_CMN_AsString(value) + if not RBS_CMN.IsAssociativeArray(value) + msg = "Value to search for was not associativeArray " + RBS_CMN.AsString(value) m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -546,13 +454,13 @@ function RBS_BTS_AssertArrayContainsAAs(array , values , msg = "" ) as dynamic end if end if end for ' items in array - + if not isMatched - msg = "array missing value: "+ RBS_CMN_AsString(value) + msg = "array missing value: " + RBS_CMN.AsString(value) m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if - + end for 'values to match else msg = "Input value is not an Array." @@ -576,11 +484,11 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertArrayNotContains(array , value , key = invalid , msg = "" ) as dynamic +public function AssertArrayNotContains(array , value , key = invalid , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) - if RBS_CMN_ArrayContains(array, value, key) - msg = "Array has the '" + RBS_CMN_AsString(value) + "' value." + if RBS_CMN.IsAssociativeArray(array) or RBS_CMN.IsArray(array) + if RBS_CMN.ArrayContains(array, value, key) + msg = "Array has the '" + RBS_CMN.AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -604,10 +512,10 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertArrayContainsSubset(array , subset , msg = "" ) as dynamic +public function AssertArrayContainsSubset(array , subset , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if (RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsAssociativeArray(subset)) or (RBS_CMN_IsArray(array) and RBS_CMN_IsArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) + if (RBS_CMN.IsAssociativeArray(array) and RBS_CMN.IsAssociativeArray(subset)) or (RBS_CMN.IsArray(array) and RBS_CMN.IsArray(subset)) + isAA = RBS_CMN.IsAssociativeArray(subset) for each item in subset key = invalid value = item @@ -615,8 +523,8 @@ function RBS_BTS_AssertArrayContainsSubset(array , subset , msg = "" ) as dynami key = item value = subset[key] end if - if not RBS_CMN_ArrayContains(array, value, key) - msg = "Array doesn't have the '" + RBS_CMN_AsString(value) + "' value." + if not RBS_CMN.ArrayContains(array, value, key) + msg = "Array doesn't have the '" + RBS_CMN.AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -641,10 +549,10 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertArrayNotContainsSubset(array , subset , msg = "" ) as dynamic +public function AssertArrayNotContainsSubset(array , subset , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if (RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsAssociativeArray(subset)) or (RBS_CMN_IsArray(array) and RBS_CMN_IsArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) + if (RBS_CMN.IsAssociativeArray(array) and RBS_CMN.IsAssociativeArray(subset)) or (RBS_CMN.IsArray(array) and RBS_CMN.IsArray(subset)) + isAA = RBS_CMN.IsAssociativeArray(subset) for each item in subset key = invalid value = item @@ -652,8 +560,8 @@ function RBS_BTS_AssertArrayNotContainsSubset(array , subset , msg = "" ) as dyn key = item value = item[key] end if - if RBS_CMN_ArrayContains(array, value, key) - msg = "Array has the '" + RBS_CMN_AsString(value) + "' value." + if RBS_CMN.ArrayContains(array, value, key) + msg = "Array has the '" + RBS_CMN.AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -678,11 +586,11 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertArrayCount(array , count , msg = "" ) as dynamic +public function AssertArrayCount(array , count , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) + if RBS_CMN.IsAssociativeArray(array) or RBS_CMN.IsArray(array) if array.Count() <> count - msg = "Array items count " + RBS_CMN_AsString(array.Count()) + " <> " + RBS_CMN_AsString(count) + "." + msg = "Array items count " + RBS_CMN.AsString(array.Count()) + " <> " + RBS_CMN.AsString(count) + "." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -706,11 +614,11 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertArrayNotCount(array , count , msg = "" ) as dynamic +public function AssertArrayNotCount(array , count , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) + if RBS_CMN.IsAssociativeArray(array) or RBS_CMN.IsArray(array) if array.Count() = count - msg = "Array items count = " + RBS_CMN_AsString(count) + "." + msg = "Array items count = " + RBS_CMN.AsString(count) + "." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -733,16 +641,16 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertEmpty(item , msg = "" ) as dynamic +public function AssertEmpty(item , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(item) or RBS_CMN_IsArray(item) + if RBS_CMN.IsAssociativeArray(item) or RBS_CMN.IsArray(item) if item.Count() > 0 msg = "Array is not empty." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if - else if (RBS_CMN_IsString(item)) - if (RBS_CMN_AsString(item) <> "") + else if (RBS_CMN.IsString(item)) + if (RBS_CMN.AsString(item) <> "") msg = "Input value is not empty." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) @@ -766,15 +674,15 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertNotEmpty(item , msg = "" ) as dynamic +public function AssertNotEmpty(item , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if RBS_CMN_IsAssociativeArray(item) or RBS_CMN_IsArray(item) + if RBS_CMN.IsAssociativeArray(item) or RBS_CMN.IsArray(item) if item.Count() = 0 msg = "Array is empty." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if - else if RBS_CMN_IsString(item) + else if RBS_CMN.IsString(item) if (item = "") msg = "Input value is empty." m.currentResult.AddResult(msg) @@ -800,21 +708,21 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertArrayContainsOnlyValuesOfType(array , typeStr , msg = "" ) as dynamic +public function AssertArrayContainsOnlyValuesOfType(array , typeStr , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if typeStr <> "String" and typeStr <> "Integer" and typeStr <> "Boolean" and typeStr <> "Array" and typeStr <> "AssociativeArray" msg = "Type must be Boolean, String, Array, Integer, or AssociativeArray" m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if - - if RBS_CMN_IsAssociativeArray(array) or RBS_CMN_IsArray(array) + + if RBS_CMN.IsAssociativeArray(array) or RBS_CMN.IsArray(array) methodName = "RBS_CMN_Is" + typeStr - typeCheckFunction = RBS_CMN_GetIsTypeFunction(methodName) + typeCheckFunction = m.GetIsTypeFunction(methodName) if (typeCheckFunction <> invalid) for each item in array if not typeCheckFunction(item) - msg = RBS_CMN_AsString(item) + "is not a '" + typeStr + "' type." + msg = RBS_CMN.AsString(item) + "is not a '" + typeStr + "' type." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -833,37 +741,37 @@ function RBS_BTS_AssertArrayContainsOnlyValuesOfType(array , typeStr , msg = "" return m.GetLegacyCompatibleReturnValue(true) end function -function RBS_CMN_GetIsTypeFunction(name) +public function GetIsTypeFunction(name) if name = "RBS_CMN_IsFunction" - return RBS_CMN_IsFunction + return RBS_CMN.IsFunction else if name = "RBS_CMN_IsXmlElement" - return RBS_CMN_IsXmlElement + return RBS_CMN.IsXmlElement else if name = "RBS_CMN_IsInteger" - return RBS_CMN_IsInteger + return RBS_CMN.IsInteger else if name = "RBS_CMN_IsBoolean" - return RBS_CMN_IsBoolean + return RBS_CMN.IsBoolean else if name = "RBS_CMN_IsFloat" - return RBS_CMN_IsFloat + return RBS_CMN.IsFloat else if name = "RBS_CMN_IsDouble" - return RBS_CMN_IsDouble + return RBS_CMN.IsDouble else if name = "RBS_CMN_IsLongInteger" - return RBS_CMN_IsLongInteger + return RBS_CMN.IsLongInteger else if name = "RBS_CMN_IsNumber" - return RBS_CMN_IsNumber + return RBS_CMN.IsNumber else if name = "RBS_CMN_IsList" - return RBS_CMN_IsList + return RBS_CMN.IsList else if name = "RBS_CMN_IsArray" - return RBS_CMN_IsArray + return RBS_CMN.IsArray else if name = "RBS_CMN_IsAssociativeArray" - return RBS_CMN_IsAssociativeArray + return RBS_CMN.IsAssociativeArray else if name = "RBS_CMN_IsSGNode" - return RBS_CMN_IsSGNode + return RBS_CMN.IsSGNode else if name = "RBS_CMN_IsString" - return RBS_CMN_IsString + return RBS_CMN.IsString else if name = "RBS_CMN_IsDateTime" - return RBS_CMN_IsDateTime + return RBS_CMN.IsDateTime else if name = "RBS_CMN_IsUndefined" - return RBS_CMN_IsUndefined + return RBS_CMN.IsUndefined else return invalid end if @@ -880,11 +788,11 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertType(value , typeStr , msg ="" ) as dynamic +public function AssertType(value , typeStr , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if type(value) <> typeStr if msg = "" - expr_as_string = RBS_CMN_AsString(value) + expr_as_string = RBS_CMN.AsString(value) msg = expr_as_string + " was not expected type " + typeStr end if m.currentResult.AddResult(msg) @@ -905,19 +813,19 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertSubType(value , typeStr , msg ="" ) as dynamic +public function AssertSubType(value , typeStr , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if type(value) <> "roSGNode" if msg = "" - expr_as_string = RBS_CMN_AsString(value) + expr_as_string = RBS_CMN.AsString(value) msg = expr_as_string + " was not a node, so could not match subtype " + typeStr end if m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) else if (value.subType() <> typeStr) if msg = "" - expr_as_string = RBS_CMN_AsString(value) - msg = expr_as_string + "( type : " + value.subType() +") was not of subType " + typeStr + expr_as_string = RBS_CMN.AsString(value) + msg = expr_as_string + "( type : " + value.subType() + ") was not of subType " + typeStr end if m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) @@ -936,7 +844,7 @@ end function ' * @param {Dynamic} Vallue2 - second item to compare ' * @returns {boolean} - True if values are equal or False in other case. ' */ -function RBS_BTS_EqValues(Value1 , Value2 ) as dynamic +public function EqValues(Value1 , Value2) as dynamic ' Workaraund for bug with string boxing, and box everything else val1Type = type(Value1) val2Type = type(Value2) @@ -944,35 +852,35 @@ function RBS_BTS_EqValues(Value1 , Value2 ) as dynamic ? "ERROR!!!! - undefined value passed" return false end if - + if val1Type = "roString" or val1Type = "String" - Value1 = RBS_CMN_AsString(Value1) + Value1 = RBS_CMN.AsString(Value1) else Value1 = box(Value1) end if - + if val2Type = "roString" or val2Type = "String" - Value2 = RBS_CMN_AsString(Value2) + Value2 = RBS_CMN.AsString(Value2) else Value2 = box(Value2) end if 'update types after boxing val1Type = type(Value1) val2Type = type(Value2) - - + + 'Upcast int to float, if other is float if val1Type = "roFloat" and val2Type = "roInt" Value2 = box(Cdbl(Value2)) else if val2Type = "roFloat" and val1Type = "roInt" Value1 = box(Cdbl(Value1)) end if - + if val1Type <> val2Type return false else valtype = val1Type - + if valtype = "roList" return RBS_BTS_EqArray(Value1, Value2) else if valtype = "roAssociativeArray" @@ -1004,10 +912,10 @@ end function ' * @param {Dynamic} Vallue2 - second associative array ' * @returns {boolean} - True if arrays are equal or False in other case. ' */ -function RBS_BTS_EqAssocArray(Value1 , Value2 ) as dynamic +public function EqAssocArray(Value1 , Value2) as dynamic l1 = Value1.Count() l2 = Value2.Count() - + if not l1 = l2 return false else @@ -1038,12 +946,12 @@ end function ' * @param {Dynamic} Vallue2 - second array ' * @returns {boolean} - True if arrays are equal or False in other case. ' */ -function RBS_BTS_EqArray(Value1 , Value2 ) as dynamic - if not (RBS_CMN_IsArray(Value1)) or not RBS_CMN_IsArray(Value2) then return false - +public function EqArray(Value1 , Value2) as dynamic + if not (RBS_CMN.IsArray(Value1)) or not RBS_CMN.IsArray(Value2) then return false + l1 = Value1.Count() l2 = Value2.Count() - + if not l1 = l2 return false else @@ -1076,11 +984,11 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert w, false otherwise ' */ -function RBS_BTS_AssertNodeCount(node , count , msg = "" ) as dynamic +public function AssertNodeCount(node , count , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if type(node) = "roSGNode" if node.getChildCount() <> count - msg = "node items count <> " + RBS_CMN_AsString(count) + ". Received " + RBS_CMN_AsString(node.getChildCount()) + msg = "node items count <> " + RBS_CMN.AsString(count) + ". Received " + RBS_CMN.AsString(node.getChildCount()) m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -1104,11 +1012,11 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertNodeNotCount(node , count , msg = "" ) as dynamic +public function AssertNodeNotCount(node , count , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if type(node) = "roSGNode" if node.getChildCount() = count - msg = "node items count = " + RBS_CMN_AsString(count) + "." + msg = "node items count = " + RBS_CMN.AsString(count) + "." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -1131,7 +1039,7 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertNodeEmpty(node , msg = "" ) as dynamic +public function AssertNodeEmpty(node , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if type(node) = "roSGNode" if node.getChildCount() > 0 @@ -1154,7 +1062,7 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertNodeNotEmpty(node , msg = "" ) as dynamic +public function AssertNodeNotEmpty(node , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed if type(node) = "roSGNode" if node.Count() = 0 @@ -1178,11 +1086,11 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertNodeContains(node , value , msg = "" ) as dynamic +public function AssertNodeContains(node , value , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(node) = "roSGNode" - if not RBS_CMN_NodeContains(node, value) - msg = "Node doesn't have the '" + RBS_CMN_AsString(value) + "' value." + if type(node) = "roSGNode" + if not RBS_CMN.NodeContains(node, value) + msg = "Node doesn't have the '" + RBS_CMN.AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -1206,11 +1114,11 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertNodeContainsOnly(node , msg = "" ) as dynamic +public function AssertNodeContainsOnly(node , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(node) = "roSGNode" - if not RBS_CMN_NodeContains(node, value) - msg = "Node doesn't have the '" + RBS_CMN_AsString(value) + "' value." + if type(node) = "roSGNode" + if not RBS_CMN.NodeContains(node, value) + msg = "Node doesn't have the '" + RBS_CMN.AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) else if node.getChildCount() <> 1 @@ -1239,11 +1147,11 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertNodeNotContains(node , value , msg = "" ) as dynamic +public function AssertNodeNotContains(node , value , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if type(node) = "roSGNode" - if RBS_CMN_NodeContains(node, value) - msg = "Node has the '" + RBS_CMN_AsString(value) + "' value." + if type(node) = "roSGNode" + if RBS_CMN.NodeContains(node, value) + msg = "Node has the '" + RBS_CMN.AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -1267,18 +1175,18 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertNodeContainsFields(node , subset , ignoredFields=invalid, msg = "" ) as dynamic +public function AssertNodeContainsFields(node , subset , ignoredFields = invalid, msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if ( type(node) = "roSGNode" and RBS_CMN_IsAssociativeArray(subset)) or ( type(node) = "roSGNode" and RBS_CMN_IsArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) - isIgnoredFields = RBS_CMN_IsArray(ignoredFields) + if (type(node) = "roSGNode" and RBS_CMN.IsAssociativeArray(subset)) or (type(node) = "roSGNode" and RBS_CMN.IsArray(subset)) + isAA = RBS_CMN.IsAssociativeArray(subset) + isIgnoredFields = RBS_CMN.IsArray(ignoredFields) for each key in subset if (key <> "") - if (not isIgnoredFields or not RBS_CMN_ArrayContains(ignoredFields, key)) + if (not isIgnoredFields or not RBS_CMN.ArrayContains(ignoredFields, key)) subsetValue = subset[key] nodeValue = node[key] if not m.eqValues(nodeValue, subsetValue) - msg = key + ": Expected '" + RBS_CMN_AsString(subsetValue) + "', got '" + RBS_CMN_AsString(nodeValue) + "'" + msg = key + ": Expected '" + RBS_CMN.AsString(subsetValue) + "', got '" + RBS_CMN.AsString(nodeValue) + "'" m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -1307,10 +1215,10 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert w, false otherwise ' */ -function RBS_BTS_AssertNodeNotContainsFields(node , subset , msg = "" ) as dynamic +public function AssertNodeNotContainsFields(node , subset , msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if ( type(node) = "roSGNode" and RBS_CMN_IsAssociativeArray(subset)) or ( type(node) = "roSGNode" and RBS_CMN_IsArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) + if (type(node) = "roSGNode" and RBS_CMN.IsAssociativeArray(subset)) or (type(node) = "roSGNode" and RBS_CMN.IsArray(subset)) + isAA = RBS_CMN.IsAssociativeArray(subset) for each item in subset key = invalid value = item @@ -1318,8 +1226,8 @@ function RBS_BTS_AssertNodeNotContainsFields(node , subset , msg = "" ) as dynam key = item value = item[key] end if - if RBS_CMN_NodeContains(node, value, key) - msg = "Node has the '" + RBS_CMN_AsString(value) + "' value." + if RBS_CMN.NodeContains(node, value, key) + msg = "Node has the '" + RBS_CMN.AsString(value) + "' value." m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -1349,18 +1257,18 @@ end function ' * @param {Dynamic} [msg=""] - alternate error message ' * @returns {boolean} - true if the assert was satisfied, false otherwise ' */ -function RBS_BTS_AssertAAContainsSubset(array , subset , ignoredFields = invalid, msg = "" ) as dynamic +public function AssertAAContainsSubset(array , subset , ignoredFields = invalid, msg = "") as dynamic if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - if (RBS_CMN_IsAssociativeArray(array) and RBS_CMN_IsAssociativeArray(subset)) - isAA = RBS_CMN_IsAssociativeArray(subset) - isIgnoredFields = RBS_CMN_IsArray(ignoredFields) + if (RBS_CMN.IsAssociativeArray(array) and RBS_CMN.IsAssociativeArray(subset)) + isAA = RBS_CMN.IsAssociativeArray(subset) + isIgnoredFields = RBS_CMN.IsArray(ignoredFields) for each key in subset if (key <> "") - if (not isIgnoredFields or not RBS_CMN_ArrayContains(ignoredFields, key)) + if (not isIgnoredFields or not RBS_CMN.ArrayContains(ignoredFields, key)) subsetValue = subset[key] arrayValue = array[key] if not m.eqValues(arrayValue, subsetValue) - msg = key + ": Expected '" + RBS_CMN_AsString(subsetValue) + "', got '" + RBS_CMN_AsString(arrayValue) + "'" + msg = key + ": Expected '" + RBS_CMN.AsString(subsetValue) + "', got '" + RBS_CMN.AsString(arrayValue) + "'" m.currentResult.AddResult(msg) return m.GetLegacyCompatibleReturnValue(false) end if @@ -1371,7 +1279,7 @@ function RBS_BTS_AssertAAContainsSubset(array , subset , ignoredFields = invalid end for else msg = "Input values are not an Associative Array." - + return m.GetLegacyCompatibleReturnValue(false) end if m.currentResult.AddResult("") @@ -1395,25 +1303,25 @@ end function ' * @param {boolean} [allowNonExistingMethods=false] - if true, then rooibos will only warn if the method did not exist prior to faking ' * @returns {Object} - stub that was wired into the real method ' */ -function RBS_BTS_Stub(target, methodName, returnValue = invalid, allowNonExistingMethods = false) as object +public function Stub(target, methodName, returnValue = invalid, allowNonExistingMethods = false) as object if (type(target) <> "roAssociativeArray") m.Fail("could not create Stub provided target was null") return {} end if - - if (m.stubs =invalid) + + if (m.stubs = invalid) m.__stubId = -1 m.stubs = {} end if m.__stubId++ - + if (m.__stubId > 5) ? "ERROR ONLY 6 STUBS PER TEST ARE SUPPORTED!!" return invalid end if - + id = stri(m.__stubId).trim() - + fake = m.CreateFake(id, target, methodName, 1, invalid, returnValue) m.stubs[id] = fake allowNonExisting = m.allowNonExistingMethodsOnMocks = true or allowNonExistingMethods @@ -1421,14 +1329,14 @@ function RBS_BTS_Stub(target, methodName, returnValue = invalid, allowNonExistin if (isMethodPresent or allowNonExisting) target[methodName] = m["StubCallback" + id] target.__stubs = m.stubs - + if (not isMethodPresent) ? "WARNING - stubbing call " ; methodName; " which did not exist on target object" end if else ? "ERROR - could not create Stub : method not found "; target ; "." ; methodName end if - + return fake end function @@ -1445,7 +1353,7 @@ end function ' * @param {boolean} [allowNonExistingMethods=false] - if true, then rooibos will only warn if the method did not exist prior to faking ' * @returns {Object} - mock that was wired into the real method ' */ -function RBS_BTS_ExpectOnce(target, methodName, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object +public function ExpectOnce(target, methodName, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object return m.Mock(target, methodName, 1, expectedArgs, returnValue, allowNonExistingMethods) end function @@ -1463,7 +1371,7 @@ end function ' * @param {boolean} [allowNonExistingMethods=false] - if true, then rooibos will only warn if the method did not exist prior to faking ' * @returns {Object} - mock that was wired into the real method ' */ -function RBS_BTS_ExpectOnceOrNone(target, methodName, isExpected, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object +public function ExpectOnceOrNone(target, methodName, isExpected, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object if isExpected return m.ExpectOnce(target, methodName, expectedArgs, returnValue, allowNonExistingMethods) else @@ -1483,7 +1391,7 @@ end function ' * @param {boolean} [allowNonExistingMethods=false] - if true, then rooibos will only warn if the method did not exist prior to faking ' * @returns {Object} - mock that was wired into the real method ' */ -function RBS_BTS_ExpectNone(target, methodName, allowNonExistingMethods = false) as object +public function ExpectNone(target, methodName, allowNonExistingMethods = false) as object return m.Mock(target, methodName, 0, invalid, invalid, allowNonExistingMethods) end function @@ -1501,7 +1409,7 @@ end function ' * @param {boolean} [allowNonExistingMethods=false] - if true, then rooibos will only warn if the method did not exist prior to faking ' * @returns {Object} - mock that was wired into the real method ' */ -function RBS_BTS_Expect(target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object +public function Expect(target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object return m.Mock(target, methodName, expectedInvocations, expectedArgs, returnValue, allowNonExistingMethods) end function @@ -1519,31 +1427,31 @@ end function ' * @param {boolean} [allowNonExistingMethods=false] - if true, then rooibos will only warn if the method did not exist prior to faking ' * @returns {Object} - mock that was wired into the real method ' */ -function RBS_BTS_Mock(target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object +public function Mock(target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object 'check params - if not RBS_CMN_IsAssociativeArray(target) + if not RBS_CMN.IsAssociativeArray(target) m.Fail("mock args: target was not an AA") - else if not RBS_CMN_IsString(methodName) + else if not RBS_CMN.IsString(methodName) m.Fail("mock args: methodName was not a string") - else if not RBS_CMN_IsNumber(expectedInvocations) + else if not RBS_CMN.IsNumber(expectedInvocations) m.Fail("mock args: expectedInvocations was not an int") - else if not RBS_CMN_IsArray(expectedArgs) and RBS_CMN_IsValid(expectedArgs) + else if not RBS_CMN.IsArray(expectedArgs) and RBS_CMN.IsValid(expectedArgs) m.Fail("mock args: expectedArgs was not invalid or an array of args") - else if RBS_CMN_IsUndefined(expectedArgs) + else if RBS_CMN.IsUndefined(expectedArgs) m.Fail("mock args: expectedArgs undefined") end if - + if m.currentResult.isFail ? "ERROR: "; m.currentResult.messages[m.currentResult.currentAssertIndex - 1] return {} end if - + if (m.mocks = invalid) m.__mockId = -1 m.__mockTargetId = -1 m.mocks = {} end if - + fake = invalid if not target.doesExist("__rooibosTargetId") m.__mockTargetId++ @@ -1552,7 +1460,7 @@ function RBS_BTS_Mock(target, methodName, expectedInvocations = 1, expectedArgs 'ascertain if mock already exists for i = 0 to m.__mockId id = stri(i).trim() - mock = m.mocks[id] + mock = m.mocks[id] if mock <> invalid and mock.methodName = methodName and mock.target.__rooibosTargetId = target.__rooibosTargetId fake = mock exit for @@ -1566,15 +1474,15 @@ function RBS_BTS_Mock(target, methodName, expectedInvocations = 1, expectedArgs ? " Method was " ; methodName return invalid end if - + fake = m.CreateFake(id, target, methodName, expectedInvocations, expectedArgs, returnValue) m.mocks[id] = fake 'this will bind it to m allowNonExisting = m.allowNonExistingMethodsOnMocks = true or allowNonExistingMethods isMethodPresent = type(target[methodName]) = "Function" or type(target[methodName]) = "roFunction" if (isMethodPresent or allowNonExisting) - target[methodName] = m["MockCallback" + id] + target[methodName] = m["MockCallback" + id] target.__mocks = m.mocks - + if (not isMethodPresent) ? "WARNING - mocking call " ; methodName; " which did not exist on target object" end if @@ -1600,21 +1508,21 @@ end function ' * @param {Dynamic} [returnValue=invalid] - value that the stub method will return when invoked ' * @returns {Object} - stub that was wired into the real method ' */ -function RBS_BTS_CreateFake(id, target, methodName, expectedInvocations = 1, expectedArgs =invalid, returnValue=invalid ) as object +public function CreateFake(id, target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid) as object expectedArgsValues = [] - hasArgs = RBS_CMN_IsArray(expectedArgs) + hasArgs = RBS_CMN.IsArray(expectedArgs) if (hasArgs) defaultValue = m.invalidValue else defaultValue = m.ignoreValue expectedArgs = [] end if - + for i = 0 to 9 if (hasArgs and expectedArgs.count() > i) 'guard against bad values value = expectedArgs[i] - if not RBS_CMN_IsUndefined(value) + if not RBS_CMN.IsUndefined(value) expectedArgsValues.push(expectedArgs[i]) else expectedArgsValues.push("#ERR-UNDEFINED!") @@ -1633,24 +1541,24 @@ function RBS_BTS_CreateFake(id, target, methodName, expectedInvocations = 1, exp invokedArgs: [invalid, invalid, invalid, invalid, invalid, invalid, invalid, invalid, invalid], expectedArgs: expectedArgsValues, expectedInvocations: expectedInvocations, - callback: function (arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic + callback: function(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic ' ? "FAKE CALLBACK CALLED FOR " ; m.methodName if (m.allInvokedArgs = invalid) m.allInvokedArgs = [] end if - m.invokedArgs = [arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ] - m.allInvokedArgs.push ([arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ]) + m.invokedArgs = [arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9] + m.allInvokedArgs.push ([arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9]) m.isCalled = true m.invocations++ - + if (type(m.returnValue) = "roAssociativeArray" and m.returnValue.doesExist("multiResult")) returnValues = m.returnValue["multiResult"] - returnIndex = m.invocations -1 - + returnIndex = m.invocations - 1 + if (type(returnValues) = "roArray" and returnValues.count() > 0) - + if returnValues.count() <= m.invocations - returnIndex = returnValues.count() -1 + returnIndex = returnValues.count() - 1 print "Multi return values all used up - repeating last value" end if return returnValues[returnIndex] @@ -1666,7 +1574,7 @@ function RBS_BTS_CreateFake(id, target, methodName, expectedInvocations = 1, exp return fake end function -function RBS_BTS_CombineFakes(fake, otherFake) +public function CombineFakes(fake, otherFake) 'add on the expected invoked args if type(fake.expectedArgs) <> "roAssociativeArray" or not fake.expectedArgs.doesExist("multiInvoke") currentExpectedArgsArgs = fake.expectedArgs @@ -1675,7 +1583,7 @@ function RBS_BTS_CombineFakes(fake, otherFake) } end if fake.expectedArgs.multiInvoke.push(otherFake.expectedArgs) - + 'add on the expected return values if type(fake.returnValue) <> "roAssociativeArray" or not fake.returnValue.doesExist("multiResult") currentReturnValue = fake.returnValue @@ -1693,10 +1601,11 @@ end function ' * @instance ' * @description Will check all mocks that have been created to ensure they were invoked the expected amount of times, with the expected args. ' */ -function RBS_BTS_AssertMocks() as void - if (m.__mockId = invalid or not RBS_CMN_IsAssociativeArray(m.mocks)) +public function AssertMocks() as void + if (m.__mockId = invalid or not RBS_CMN.IsAssociativeArray(m.mocks)) return end if + lastId = int(m.__mockId) for each id in m.mocks mock = m.mocks[id] @@ -1705,9 +1614,9 @@ function RBS_BTS_AssertMocks() as void m.MockFail(methodName, "Wrong number of calls. (" + stri(mock.invocations).trim() + " / " + stri(mock.expectedInvocations).trim() + ")") m.CleanMocks() return - else if mock.expectedInvocations > 0 and (RBS_CMN_IsArray(mock.expectedArgs) or (type(mock.expectedArgs) = "roAssociativeArray" and RBS_CMN_IsArray(mock.expectedArgs.multiInvoke))) - isMultiArgsSupported = type(mock.expectedArgs) = "roAssociativeArray" and RBS_CMN_IsArray(mock.expectedArgs.multiInvoke) - + else if mock.expectedInvocations > 0 and (RBS_CMN.IsArray(mock.expectedArgs) or (type(mock.expectedArgs) = "roAssociativeArray" and RBS_CMN.IsArray(mock.expectedArgs.multiInvoke))) + isMultiArgsSupported = type(mock.expectedArgs) = "roAssociativeArray" and RBS_CMN.IsArray(mock.expectedArgs.multiInvoke) + for invocationIndex = 0 to mock.invocations - 1 invokedArgs = mock.allInvokedArgs[invocationIndex] if isMultiArgsSupported @@ -1715,19 +1624,19 @@ function RBS_BTS_AssertMocks() as void else expectedArgs = mock.expectedArgs end if - for i = 0 to expectedArgs.count() -1 + for i = 0 to expectedArgs.count() - 1 value = invokedArgs[i] expected = expectedArgs[i] - didNotExpectArg = RBS_CMN_IsString(expected) and expected = m.invalidValue + didNotExpectArg = RBS_CMN.IsString(expected) and expected = m.invalidValue if (didNotExpectArg) expected = invalid end if - if (not (RBS_CMN_IsString(expected) and expected = m.ignoreValue) and not m.eqValues(value, expected)) + if (not (RBS_CMN.IsString(expected) and expected = m.ignoreValue) and not m.eqValues(value, expected)) if (expected = invalid) expected = "[INVALID]" end if - - m.MockFail(methodName, "on Invocation #" + stri(invocationIndex).trim() + ", expected arg #" + stri(i).trim() + " to be '" + RBS_CMN_AsString(expected) + "' got '" + RBS_CMN_AsString(value) + "')") + + m.MockFail(methodName, "on Invocation #" + stri(invocationIndex).trim() + ", expected arg #" + stri(i).trim() + " to be '" + RBS_CMN.AsString(expected) + "' got '" + RBS_CMN.AsString(value) + "')") m.CleanMocks() return end if @@ -1735,7 +1644,7 @@ function RBS_BTS_AssertMocks() as void end for end if end for - + m.CleanMocks() end function @@ -1746,209 +1655,212 @@ end function ' * @instance ' * @description Cleans up all tracking data associated with mocks ' */ -function RBS_BTS_CleanMocks() as void - if m.mocks = invalid return - for each id in m.mocks - mock = m.mocks[id] - mock.target.__mocks = invalid - end for - m.mocks = invalid - end function - - ' /** - ' * @memberof module:BaseTestSuite - ' * @name CleanStubs - ' * @function - ' * @instance - ' * @description Cleans up all tracking data associated with stubs - ' */ - function RBS_BTS_CleanStubs() as void - if m.stubs = invalid return - for each id in m.stubs - stub = m.stubs[id] - stub.target.__stubs = invalid - end for - m.stubs = invalid - end function - - - function RBS_BTS_MockFail(methodName, message) as dynamic - if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed - m.currentResult.AddResult("mock failure on '" + methodName + "' : " + message) - return m.GetLegacyCompatibleReturnValue(false) - end function +public function CleanMocks() as void + if m.mocks = invalid then return + for each id in m.mocks + mock = m.mocks[id] + mock.target.__mocks = invalid + end for + m.mocks = invalid +end function +' /** +' * @memberof module:BaseTestSuite +' * @name CleanStubs +' * @function +' * @instance +' * @description Cleans up all tracking data associated with stubs +' */ +public function CleanStubs() as void + if m.stubs = invalid then return + for each id in m.stubs + stub = m.stubs[id] + stub.target.__stubs = invalid + end for + m.stubs = invalid +end function - '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - '++ Fake Stub callback functions - this is required to get scope - '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - function RBS_BTS_StubCallback0(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["0"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function +public function MockFail(methodName, message) as dynamic + if (m.currentResult.isFail) then return m.GetLegacyCompatibleReturnValue(false) ' skip test we already failed + m.currentResult.AddResult("mock failure on '" + methodName + "' : " + message) + return m.GetLegacyCompatibleReturnValue(false) +end function - function RBS_BTS_StubCallback1(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["1"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_StubCallback2(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["2"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function +'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +'++ Fake Stub callback functions - this is required to get scope +'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +public function StubCallback0(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__Stubs["0"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function - function RBS_BTS_StubCallback3(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["3"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function +public function StubCallback1(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__Stubs["1"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function +public function StubCallback2(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__Stubs["2"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function - function RBS_BTS_StubCallback4(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["4"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function +public function StubCallback3(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__Stubs["3"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function - function RBS_BTS_StubCallback5(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__Stubs["5"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - '++ Fake Mock callback functions - this is required to get scope - '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +public function StubCallback4(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__Stubs["4"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function - function RBS_BTS_MockCallback0(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["0"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function - function RBS_BTS_MockCallback1(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["1"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function +public function StubCallback5(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__Stubs["5"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function - function RBS_BTS_MockCallback2(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["2"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function +'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +'++ Fake Mock callback functions - this is required to get scope +'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +public function MockCallback0(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__mocks["0"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function - function RBS_BTS_MockCallback3(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["3"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function +public function MockCallback1(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__mocks["1"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function +public function MockCallback2(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__mocks["2"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function - function RBS_BTS_MockCallback4(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["4"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function +public function MockCallback3(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__mocks["3"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function - function RBS_BTS_MockCallback5(arg1=invalid, arg2=invalid, arg3=invalid, arg4=invalid, arg5=invalid, arg6=invalid, arg7=invalid, arg8=invalid, arg9 =invalid)as dynamic - fake = m.__mocks["5"] - return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - end function +public function MockCallback4(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__mocks["4"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function - '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - '++ Utility functions! - '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - '************************************************************* - '** ripped and adapted from rodash - thanks @veeta! - '** used by get method - consider thsis private - '************************************************************* - function RBS_BTS_rodash_pathsAsArray_(path) - pathRE = CreateObject("roRegex", "\[([0-9]+)\]", "i") - segments = [] - if type(path) = "String" or type(path) = "roString" - dottedPath = pathRE.replaceAll(path, ".\1") - stringSegments = dottedPath.tokenize(".") - for each s in stringSegments - if (Asc(s) >= 48) and (Asc(s) <= 57) - segments.push(s.toInt()) - else - segments.push(s) - end if - end for - else if type(path) = "roList" or type(path) = "roArray" - stringPath = "" - for each s in path - stringPath = stringPath + "." + Box(s).toStr() - end for - segments = m.pathAsArray_(stringPath) - else - segments = invalid - end if - return segments - end function +public function MockCallback5(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid)as dynamic + fake = m.__mocks["5"] + return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) +end function - ' /** - ' * @memberof module:BaseTestSuite - ' * @name g - ' * @function - ' * @instance - ' * @description ripped and adapted from rodash - thanks @veeta! - ' * use this method to safely get anything. useful for when unit testing a collection - ' * or something and you're not sure if it's gonna crash! - ' * @param {Dynamic} aa - node, array or assoArray - ' * @param {Dynamic} subset - the items to check for - ' * @param {Dynamic} path -as string path to target field. Can use .0. or [0] index notation e.g. "children.0.title" or "children[0].title" - ' * @returns {dynamic} - matched item, on aa at path - ' */ - - function RBS_BTS_rodash_get_(aa, path, default=invalid) - if type(aa) <> "roAssociativeArray" and type(aa) <> "roArray" and type(aa) <> "roSGNode" then return default - segments = m.pathAsArray_(path) - - if (Type(path) = "roInt" or Type(path) = "roInteger" or Type(path) = "Integer") - path = stri(path).trim() - end if - if segments = invalid then return default - result = invalid - - while segments.count() > 0 - key = segments.shift() - if (type(key) = "roInteger") 'it's a valid index - if (aa <> invalid and GetInterface(aa, "ifArray") <> invalid) - value = aa[key] - else if (aa <> invalid and GetInterface(aa, "ifSGNodeChildren") <> invalid) - value = aa.getChild(key) - else if (aa <> invalid and GetInterface(aa, "ifAssociativeArray") <> invalid) - key = tostr(key) - if not aa.doesExist(key) - exit while - end if - value = aa.lookup(key) - else - value = invalid - end if - else - if not aa.doesExist(key) - exit while - end if +'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +'++ Utility functions! +'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - value = aa.lookup(key) - end if +'************************************************************* +'** ripped and adapted from rodash - thanks @veeta! +'** used by get method - consider thsis private +'************************************************************* +public function pathAsArray_(path) + pathRE = CreateObject("roRegex", "\[([0-9]+)\]", "i") + segments = [] + if type(path) = "String" or type(path) = "roString" + dottedPath = pathRE.replaceAll(path, ".\1") + stringSegments = dottedPath.tokenize(".") + for each s in stringSegments + if (Asc(s) >= 48) and (Asc(s) <= 57) + segments.push(s.toInt()) + else + segments.push(s) + end if + end for + else if type(path) = "roList" or type(path) = "roArray" + stringPath = "" + for each s in path + stringPath = stringPath + "." + Box(s).toStr() + end for + segments = m.pathAsArray_(stringPath) + else + segments = invalid + end if + return segments +end function - if segments.count() = 0 - result = value - exit while - end if +' /** +' * @memberof module:BaseTestSuite +' * @name g +' * @function +' * @instance +' * @description ripped and adapted from rodash - thanks @veeta! +' * use this method to safely get anything. useful for when unit testing a collection +' * or something and you're not sure if it's gonna crash! +' * @param {Dynamic} aa - node, array or assoArray +' * @param {Dynamic} subset - the items to check for +' * @param {Dynamic} path -as string path to target field. Can use .0. or [0] index notation e.g. "children.0.title" or "children[0].title" +' * @returns {dynamic} - matched item, on aa at path +' */ - if type(value) <> "roAssociativeArray" and type(value) <> "roArray" and type(value) <> "roSGNode" +public function g(aa, path, default = invalid) + if type(aa) <> "roAssociativeArray" and type(aa) <> "roArray" and type(aa) <> "roSGNode" then return default + segments = m.pathAsArray_(path) + + if (Type(path) = "roInt" or Type(path) = "roInteger" or Type(path) = "Integer") + path = stri(path).trim() + end if + + if segments = invalid then return default + result = invalid + + while segments.count() > 0 + key = segments.shift() + if (type(key) = "roInteger") 'it's a valid index + if (aa <> invalid and GetInterface(aa, "ifArray") <> invalid) + value = aa[key] + else if (aa <> invalid and GetInterface(aa, "ifSGNodeChildren") <> invalid) + value = aa.getChild(key) + else if (aa <> invalid and GetInterface(aa, "ifAssociativeArray") <> invalid) + key = tostr(key) + if not aa.doesExist(key) exit while end if - aa = value - end while + + value = aa.lookup(key) + else + value = invalid + end if + else + if not aa.doesExist(key) + exit while + end if + + value = aa.lookup(key) + end if + + if segments.count() = 0 + result = value + exit while + end if + + if type(value) <> "roAssociativeArray" and type(value) <> "roArray" and type(value) <> "roSGNode" + exit while + end if + aa = value + end while + + if result = invalid then return default + return result +end function - if result = invalid then return default - return result - end function +end class +end namespace \ No newline at end of file diff --git a/src/Rooibos_CommonUtils.brs b/src/CommonUtils.bs similarity index 72% rename from src/Rooibos_CommonUtils.brs rename to src/CommonUtils.bs index c5cff4d6..aad386a9 100755 --- a/src/Rooibos_CommonUtils.brs +++ b/src/CommonUtils.bs @@ -1,3 +1,4 @@ +namespace RBS_CMN ' /** ' * @module CommonUtils ' */ @@ -13,8 +14,8 @@ ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value contains XMLElement interface, else return false ' */ -function RBS_CMN_IsXmlElement(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifXMLElement") <> invalid +function IsXmlElement(value) as boolean + return RBS_CMN.IsValid(value) and GetInterface(value, "ifXMLElement") <> invalid end function ' /** @@ -25,13 +26,13 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value contains Function interface, else return false ' */ -function RBS_CMN_IsFunction(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifFunction") <> invalid +function IsFunction(value) as boolean + return RBS_CMN.IsValid(value) and GetInterface(value, "ifFunction") <> invalid end function ' /** -' * @name RBS_CMN_GetFunction +' * @name RBS_CMN.GetFunction ' * @function ' * @description looks up the function by name, for the function map ' * @memberof module:CommonUtils @@ -39,9 +40,9 @@ end function ' * @param {String} functionName - name of the function to locate ' * @returns {Function} - function pointer or invalid ' */ -function RBS_CMN_GetFunction(filename, functionName) as object - if (not RBS_CMN_IsNotEmptyString(functionName)) then return invalid - if (not RBS_CMN_IsNotEmptyString(filename)) then return invalid +function GetFunction(filename, functionName) as object + if (not RBS_CMN.IsNotEmptyString(functionName)) then return invalid + if (not RBS_CMN.IsNotEmptyString(filename)) then return invalid mapFunction = RBSFM_getFunctionsForFile(filename) if mapFunction <> invalid map = mapFunction() @@ -57,7 +58,7 @@ function RBS_CMN_GetFunction(filename, functionName) as object end function ' /** -' * @name RBS_CMN_GetFunctionBruteforce +' * @name RBS_CMN.GetFunctionBruteforce ' * @function ' * @description looks up the function by name, from any function map ' * in future, functions retrieved in this way are stored in the special RBS_INTERNAL file map @@ -66,9 +67,9 @@ end function ' * @param {String} functionName - name of the function to locate ' * @returns {Function} - function pointer or invalid ' */ -function RBS_CMN_GetFunctionBruteForce(functionName) as object - if (not RBS_CMN_IsNotEmptyString(functionName)) then return invalid - ' func = RBS_CMN_GetFunction("RBS_INTERNAL", functionName) +function GetFunctionBruteForce(functionName) as object + if (not RBS_CMN.IsNotEmptyString(functionName)) then return invalid + ' func = RBS_CMN.GetFunction("RBS_INTERNAL", functionName) ' if func <> invalid ' return func ' end if @@ -99,8 +100,8 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value contains Boolean interface, else return false ' */ -function RBS_CMN_IsBoolean(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifBoolean") <> invalid +function IsBoolean(value) as boolean + return RBS_CMN.IsValid(value) and GetInterface(value, "ifBoolean") <> invalid end function ' /** @@ -111,8 +112,8 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value type equals Integer, else return false ' */ -function RBS_CMN_IsInteger(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifInt") <> invalid and (Type(value) = "roInt" or Type(value) = "roInteger" or Type(value) = "Integer") +function IsInteger(value) as boolean + return RBS_CMN.IsValid(value) and GetInterface(value, "ifInt") <> invalid and (Type(value) = "roInt" or Type(value) = "roInteger" or Type(value) = "Integer") end function ' /** @@ -123,8 +124,8 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value contains Float interface, else return false ' */ -function RBS_CMN_IsFloat(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifFloat") <> invalid +function IsFloat(value) as boolean + return RBS_CMN.IsValid(value) and GetInterface(value, "ifFloat") <> invalid end function ' /** @@ -135,8 +136,8 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value contains Double interface, else return false ' */ -function RBS_CMN_IsDouble(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifDouble") <> invalid +function IsDouble(value) as boolean + return RBS_CMN.IsValid(value) and GetInterface(value, "ifDouble") <> invalid end function ' /** @@ -147,8 +148,8 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value contains LongInteger interface, else return false ' */ -function RBS_CMN_IsLongInteger(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifLongInt") <> invalid +function IsLongInteger(value) as boolean + return RBS_CMN.IsValid(value) and GetInterface(value, "ifLongInt") <> invalid end function ' /** @@ -159,8 +160,8 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value is number, else return false ' */ -function RBS_CMN_IsNumber(value) as boolean - return RBS_CMN_IsLongInteger(value) or RBS_CMN_IsDouble(value) or RBS_CMN_IsInteger(value) or RBS_CMN_IsFloat(value) +function IsNumber(value) as boolean + return RBS_CMN.IsLongInteger(value) or RBS_CMN.IsDouble(value) or RBS_CMN.IsInteger(value) or RBS_CMN.IsFloat(value) end function ' /** @@ -171,8 +172,8 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value contains List interface, else return false ' */ -function RBS_CMN_IsList(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifList") <> invalid +function IsList(value) as boolean + return RBS_CMN.IsValid(value) and GetInterface(value, "ifList") <> invalid end function ' /** @@ -183,8 +184,8 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value contains Array interface, else return false ' */ -function RBS_CMN_IsArray(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifArray") <> invalid +function IsArray(value) as boolean + return RBS_CMN.IsValid(value) and GetInterface(value, "ifArray") <> invalid end function ' /** @@ -195,8 +196,8 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value contains AssociativeArray interface, else return false ' */ -function RBS_CMN_IsAssociativeArray(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifAssociativeArray") <> invalid +function IsAssociativeArray(value) as boolean + return RBS_CMN.IsValid(value) and GetInterface(value, "ifAssociativeArray") <> invalid end function ' /** @@ -207,8 +208,8 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value contains SGNodeChildren interface, else return false ' */ -function RBS_CMN_IsSGNode(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifSGNodeChildren") <> invalid +function IsSGNode(value) as boolean + return RBS_CMN.IsValid(value) and GetInterface(value, "ifSGNodeChildren") <> invalid end function ' /** @@ -219,8 +220,8 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value contains String interface, else return false ' */ -function RBS_CMN_IsString(value) as boolean - return RBS_CMN_IsValid(value) and GetInterface(value, "ifString") <> invalid +function IsString(value) as boolean + return RBS_CMN.IsValid(value) and GetInterface(value, "ifString") <> invalid end function ' /** @@ -231,8 +232,8 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value contains String interface and length more 0, else return false ' */ -function RBS_CMN_IsNotEmptyString(value) as boolean - return RBS_CMN_IsString(value) and len(value) > 0 +function IsNotEmptyString(value) as boolean + return RBS_CMN.IsString(value) and len(value) > 0 end function ' /** @@ -243,8 +244,8 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value contains DateTime interface, else return false ' */ -function RBS_CMN_IsDateTime(value) as boolean - return RBS_CMN_IsValid(value) and (GetInterface(value, "ifDateTime") <> invalid or Type(value) = "roDateTime") +function IsDateTime(value) as boolean + return RBS_CMN.IsValid(value) and (GetInterface(value, "ifDateTime") <> invalid or Type(value) = "roDateTime") end function ' /** @@ -255,11 +256,11 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value initialized and not equal invalid, else return false ' */ -function RBS_CMN_IsValid(value) as boolean - return not RBS_CMN_IsUndefined(value) and value <> invalid +function IsValid(value) as boolean + return not RBS_CMN.IsUndefined(value) and value <> invalid end function -function RBS_CMN_IsUndefined(value) as boolean +function IsUndefined(value) as boolean return type(value) = "" or Type(value) = "" end function @@ -271,7 +272,7 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {String} - value if his contains String interface else return empty string ' */ -function RBS_CMN_ValidStr(obj) as string +function ValidStr(obj) as string if obj <> invalid and GetInterface(obj, "ifString") <> invalid return obj else @@ -287,14 +288,14 @@ end function ' * @param {Dynamic} input - value to check ' * @returns {String} - converted string ' */ -function RBS_CMN_AsString(input) as string - if RBS_CMN_IsValid(input) = false +function AsString(input) as string + if RBS_CMN.IsValid(input) = false return "" - else if RBS_CMN_IsString(input) + else if RBS_CMN.IsString(input) return input - else if RBS_CMN_IsInteger(input) or RBS_CMN_IsLongInteger(input) or RBS_CMN_IsBoolean(input) + else if RBS_CMN.IsInteger(input) or RBS_CMN.IsLongInteger(input) or RBS_CMN.IsBoolean(input) return input.ToStr() - else if RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) + else if RBS_CMN.IsFloat(input) or RBS_CMN.IsDouble(input) return Str(input).Trim() else if type(input) = "roSGNode" return "Node(" + input.subType() + ")" @@ -307,7 +308,7 @@ function RBS_CMN_AsString(input) as string end if for each key in input if key <> "__mocks" and key <> "__stubs" - text += key + ":" + RBS_CMN_AsString(input[key]) + text += key + ":" + RBS_CMN.AsString(input[key]) end if end for text += "}" @@ -325,14 +326,14 @@ end function ' * @param {Dynamic} input - value to check ' * @returns {Integer} - converted Integer ' */ -function RBS_CMN_AsInteger(input) as integer - if RBS_CMN_IsValid(input) = false +function AsInteger(input) as integer + if RBS_CMN.IsValid(input) = false return 0 - else if RBS_CMN_IsString(input) + else if RBS_CMN.IsString(input) return input.ToInt() - else if RBS_CMN_IsInteger(input) + else if RBS_CMN.IsInteger(input) return input - else if RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) or RBS_CMN_IsLongInteger(input) + else if RBS_CMN.IsFloat(input) or RBS_CMN.IsDouble(input) or RBS_CMN.IsLongInteger(input) return Int(input) else return 0 @@ -347,12 +348,12 @@ end function ' * @param {Dynamic} input - value to check ' * @returns {Integer} - converted LongInteger ' */ -function RBS_CMN_AsLongInteger(input) as longinteger - if RBS_CMN_IsValid(input) = false +function AsLongInteger(input) as longinteger + if RBS_CMN.IsValid(input) = false return 0 - else if RBS_CMN_IsString(input) - return RBS_CMN_AsInteger(input) - else if RBS_CMN_IsLongInteger(input) or RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) or RBS_CMN_IsInteger(input) + else if RBS_CMN.IsString(input) + return RBS_CMN.AsInteger(input) + else if RBS_CMN.IsLongInteger(input) or RBS_CMN.IsFloat(input) or RBS_CMN.IsDouble(input) or RBS_CMN.IsInteger(input) return input else return 0 @@ -367,14 +368,14 @@ end function ' * @param {Dynamic} input - value to check ' * @returns {Float} - converted Float ' */ -function RBS_CMN_AsFloat(input) as float - if RBS_CMN_IsValid(input) = false +function AsFloat(input) as float + if RBS_CMN.IsValid(input) = false return 0.0 - else if RBS_CMN_IsString(input) + else if RBS_CMN.IsString(input) return input.ToFloat() - else if RBS_CMN_IsInteger(input) + else if RBS_CMN.IsInteger(input) return (input / 1) - else if RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) or RBS_CMN_IsLongInteger(input) + else if RBS_CMN.IsFloat(input) or RBS_CMN.IsDouble(input) or RBS_CMN.IsLongInteger(input) return input else return 0.0 @@ -389,12 +390,12 @@ end function ' * @param {Dynamic} input - value to check ' * @returns {Float} - converted Double ' */ -function RBS_CMN_AsDouble(input) as double - if RBS_CMN_IsValid(input) = false +function AsDouble(input) as double + if RBS_CMN.IsValid(input) = false return 0.0 - else if RBS_CMN_IsString(input) - return RBS_CMN_AsFloat(input) - else if RBS_CMN_IsInteger(input) or RBS_CMN_IsLongInteger(input) or RBS_CMN_IsFloat(input) or RBS_CMN_IsDouble(input) + else if RBS_CMN.IsString(input) + return RBS_CMN.AsFloat(input) + else if RBS_CMN.IsInteger(input) or RBS_CMN.IsLongInteger(input) or RBS_CMN.IsFloat(input) or RBS_CMN.IsDouble(input) return input else return 0.0 @@ -409,14 +410,14 @@ end function ' * @param {Dynamic} input - value to check ' * @returns {Boolean} - converted boolean ' */ -function RBS_CMN_AsBoolean(input) as boolean - if RBS_CMN_IsValid(input) = false +function AsBoolean(input) as boolean + if RBS_CMN.IsValid(input) = false return false - else if RBS_CMN_IsString(input) + else if RBS_CMN.IsString(input) return LCase(input) = "true" - else if RBS_CMN_IsInteger(input) or RBS_CMN_IsFloat(input) + else if RBS_CMN.IsInteger(input) or RBS_CMN.IsFloat(input) return input <> 0 - else if RBS_CMN_IsBoolean(input) + else if RBS_CMN.IsBoolean(input) return input else return false @@ -431,9 +432,9 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Array} - converted array ' */ -function RBS_CMN_AsArray(value) as object - if RBS_CMN_IsValid(value) - if not RBS_CMN_IsArray(value) +function AsArray(value) as object + if RBS_CMN.IsValid(value) + if not RBS_CMN.IsArray(value) return [value] else return value @@ -454,11 +455,11 @@ end function ' * @param {Dynamic} value - value to check ' * @returns {Boolean} - true if value is null or empty string, else return false ' */ -function RBS_CMN_IsNullOrEmpty(value) as boolean - if RBS_CMN_IsString(value) +function IsNullOrEmpty(value) as boolean + if RBS_CMN.IsString(value) return Len(value) = 0 else - return not RBS_CMN_IsValid(value) + return not RBS_CMN.IsValid(value) end if end function @@ -477,12 +478,12 @@ end function ' * @param {Boolean} caseSensitive - indicates if comparisons are case sensitive ' * @returns {Integer} - element index if array contains a value, else return -1 ' */ -function RBS_CMN_FindElementIndexInArray(array , value , compareAttribute = invalid , caseSensitive = false) as integer - if RBS_CMN_IsArray(array) - for i = 0 to RBS_CMN_AsArray(array).Count() - 1 +function FindElementIndexInArray(array , value , compareAttribute = invalid , caseSensitive = false) as integer + if RBS_CMN.IsArray(array) + for i = 0 to RBS_CMN.AsArray(array).Count() - 1 compareValue = array[i] - if compareAttribute <> invalid and RBS_CMN_IsAssociativeArray(compareValue) + if compareAttribute <> invalid and RBS_CMN.IsAssociativeArray(compareValue) compareValue = compareValue.LookupCI(compareAttribute) end if @@ -506,8 +507,8 @@ end function ' * @param {Dynamic} compareAttribute - attribute to compare on ' * @returns {Boolean} - true if array contains a value, else return false ' */ -function RBS_CMN_ArrayContains(array , value , compareAttribute = invalid) as boolean - return (RBS_CMN_FindElementIndexInArray(array, value, compareAttribute) > -1) +function ArrayContains(array , value , compareAttribute = invalid) as boolean + return (RBS_CMN.FindElementIndexInArray(array, value, compareAttribute) > -1) end function @@ -524,7 +525,7 @@ end function ' * @param {Dynamic} value - child to search for ' * @returns {Integer} - element index if node contains a value, else return -1 ' */ -function RBS_CMN_FindElementIndexInNode(node , value) as integer +function FindElementIndexInNode(node , value) as integer if type(node) = "roSGNode" for i = 0 to node.getChildCount() - 1 compareValue = node.getChild(i) @@ -544,6 +545,6 @@ end function ' * @param {Dynamic} value - child to look for ' * @returns {Boolean} - true if node contains a value, else return false ' */ -function RBS_CMN_NodeContains(node , value) as boolean - return (RBS_CMN_FindElementIndexInNode(node, value) > -1) +function NodeContains(node , value) as boolean + return (RBS_CMN.FindElementIndexInNode(node, value) > -1) end function diff --git a/src/Rooibos_ItGroup.brs b/src/ItGroup.bs similarity index 59% rename from src/Rooibos_ItGroup.brs rename to src/ItGroup.bs index 3cd483b3..0cc90bb8 100644 --- a/src/Rooibos_ItGroup.brs +++ b/src/ItGroup.bs @@ -1,5 +1,6 @@ +namespace RBS_ItG -function RBS_ItG_GetTestCases(group) as object +function GetTestCases(group) as object if (group.hasSoloTests = true) return group.soloTestCases else @@ -7,8 +8,8 @@ function RBS_ItG_GetTestCases(group) as object end if end function -function RBS_ItG_GetRunnableTestSuite(group) as object - testCases = RBS_ItG_GetTestCases(group) +function GetRunnableTestSuite(group) as object + testCases = RBS_ItG.GetTestCases(group) runnableSuite = BaseTestSuite() runnableSuite.name = group.name @@ -22,15 +23,17 @@ function RBS_ItG_GetRunnableTestSuite(group) as object if (testCase.isSolo = true) name += " [SOLO] " end if - testFunction = RBS_CMN_GetFunction(group.filename, testCase.funcName) + testFunction = RBS_CMN.GetFunction(group.filename, testCase.funcName) runnableSuite.addTest(name, testFunction, testCase.funcName) group.testCaseLookup[name] = testCase end for - runnableSuite.SetUp = RBS_CMN_GetFunction(group.filename, group.setupFunctionName) - runnableSuite.TearDown = RBS_CMN_GetFunction(group.filename, group.teardownFunctionName) - runnableSuite.BeforeEach = RBS_CMN_GetFunction(group.filename, group.beforeEachFunctionName) - runnableSuite.AfterEach = RBS_CMN_GetFunction(group.filename, group.afterEachFunctionName) + runnableSuite.SetUp = RBS_CMN.GetFunction(group.filename, group.setupFunctionName) + runnableSuite.TearDown = RBS_CMN.GetFunction(group.filename, group.teardownFunctionName) + runnableSuite.BeforeEach = RBS_CMN.GetFunction(group.filename, group.beforeEachFunctionName) + runnableSuite.AfterEach = RBS_CMN.GetFunction(group.filename, group.afterEachFunctionName) return runnableSuite end function + +end namespace \ No newline at end of file diff --git a/src/Rooibos_ItemGenerator.brs b/src/ItemGenerator.bs similarity index 82% rename from src/Rooibos_ItemGenerator.brs rename to src/ItemGenerator.bs index 7da841ea..c608654d 100644 --- a/src/Rooibos_ItemGenerator.brs +++ b/src/ItemGenerator.bs @@ -1,3 +1,4 @@ +namespace RBS_IG ' /** ' * @module ItemGenerator ' */ @@ -18,24 +19,10 @@ ' * @description Creates an ItemGenerator instance ' * @returns {Object} An object according to specified scheme or invalid, if scheme is not valid. ' */ -function ItemGenerator(scheme as object) as object +class ItemGenerator - this = {} - - this.getItem = RBS_IG_GetItem - this.getAssocArray = RBS_IG_GetAssocArray - this.getArray = RBS_IG_GetArray - this.getSimpleType = RBS_IG_GetSimpleType - this.getInteger = RBS_IG_GetInteger - this.getFloat = RBS_IG_GetFloat - this.getString = RBS_IG_GetString - this.getBoolean = RBS_IG_GetBoolean - - if not RBS_CMN_IsValid(scheme) - return invalid - end if - - return this.getItem(scheme) +public function new() + m.isValid = RBS_CMN.IsValid(scheme) end function ' /** @@ -54,15 +41,15 @@ end function ' * @description Gets an item according to the schem ' * @returns {Object} An object according to specified scheme or invalid if scheme is not one of simple type, array or associative array. ' */ -function RBS_IG_GetItem(scheme as object) as object +public function GetItem(scheme as object) as object item = invalid - if RBS_CMN_IsAssociativeArray(scheme) + if RBS_CMN.IsAssociativeArray(scheme) item = m.getAssocArray(scheme) - else if RBS_CMN_IsArray(scheme) + else if RBS_CMN.IsArray(scheme) item = m.getArray(scheme) - else if RBS_CMN_IsString(scheme) + else if RBS_CMN.IsString(scheme) item = m.getSimpleType(lCase(scheme)) end if @@ -85,7 +72,7 @@ end function ' * @description Generates associative array according to specified scheme. ' * @returns {Object} An associative array according to specified scheme. ' */ -function RBS_IG_GetAssocArray(scheme as object) as object +public function GetAssocArray(scheme as object) as object item = {} @@ -113,7 +100,7 @@ end function ' * @description Generates array according to specified scheme. ' * @returns {Object} An array according to specified scheme. ' */ -function RBS_IG_GetArray(scheme as object) as object +public function GetArray(scheme as object) as object item = [] @@ -133,7 +120,7 @@ end function ' * @param {Dynamic} typeStr - name of desired object type. ' * @returns {Object} A simple type object or invalid if type is not supported. ' */ -function RBS_IG_GetSimpleType(typeStr as string) as object +public function GetSimpleType(typeStr as string) as object item = invalid @@ -158,8 +145,8 @@ end function ' * @description Generates random boolean value. ' * @returns {Boolean} A random boolean value. ' */ -function RBS_IG_GetBoolean() as boolean - return RBS_CMN_AsBoolean(Rnd(2) \ Rnd(2)) +public function GetBoolean() as boolean + return RBS_CMN.AsBoolean(Rnd(2) \ Rnd(2)) end function ' /** @@ -171,7 +158,7 @@ end function ' * @param {Dynamic} seed - seed value for Rnd function. ' * @returns {integer} A random integer value. ' */ -function RBS_IG_GetInteger(seed = 100 as integer) as integer +public function GetInteger(seed = 100 as integer) as integer return Rnd(seed) end function @@ -183,7 +170,7 @@ end function ' * @description Generates random float value. ' * @returns {float} A random float value. ' */ -function RBS_IG_GetFloat() as float +public function GetFloat() as float return Rnd(0) end function @@ -196,7 +183,7 @@ end function ' * @param {Dynamic} seed - A string length ' * @returns {string} A random string value or empty string if seed is 0. ' */ -function RBS_IG_GetString(seed as integer) as string +public function GetString(seed as integer) as string item = "" if seed > 0 @@ -220,3 +207,5 @@ function RBS_IG_GetString(seed as integer) as string return item end function +end class +end namespace \ No newline at end of file diff --git a/src/Rooibos.brs b/src/Rooibos.bs similarity index 78% rename from src/Rooibos.brs rename to src/Rooibos.bs index 86125c74..f6b5d8e6 100644 --- a/src/Rooibos.brs +++ b/src/Rooibos.bs @@ -1,7 +1,7 @@ ' /** ' * @module rooibosh ' */ - +namespace Rooibos_ ' /** ' * @memberof module:rooibosh ' * @name Rooibos__Init @@ -16,7 +16,7 @@ ' * and therefore require a screen and scene are created. ' * @param nodeContext as object - this is the global scope of your tests - so where anonymous methods will run from. This should be m ' */ -function Rooibos__Init(preTestSetup = invalid, testUtilsDecoratorMethodName = invalid, testSceneName = invalid, nodeContext = invalid) as void +function Init(preTestSetup = invalid, testUtilsDecoratorMethodName = invalid, testSceneName = invalid, nodeContext = invalid) as void args = {} if createObject("roAPPInfo").IsDev() <> true then ? " not running in dev mode! - rooibos tests only support sideloaded builds - aborting" @@ -58,10 +58,10 @@ function Rooibos__Init(preTestSetup = invalid, testUtilsDecoratorMethodName = in rooibosVersion = "3.1.1" requiredRooibosPreprocessorVersion = "1.0.0" - if not RBS_CMN_isFunction(RBSFM_getPreprocessorVersion) + if not RBS_CMN.isFunction(RBSFM_getPreprocessorVersion) versionError = "You are using a rooibos-preprocessor (i.e. rooibos-cli) version older than 1.0.0 - please update to " + requiredRooibosPreprocessorVersion else - if RBSFM_getPreprocessorVersion() = requiredRooibosPreprocessorVersion + if Rooibos_.versionCompare(RBSFM_getPreprocessorVersion(),requiredRooibosPreprocessorVersion) >= 0 versionError = "" else versionError = "Your rooibos-preprocessor (i.e. rooibos-cli) version '" + RBSFM_getPreprocessorVersion() + "' is not compatible with rooibos version " + rooibosVersion + ". Please upgrade your rooibos-cli to version " + requiredRooibosPreprocessorVersion @@ -76,7 +76,7 @@ function Rooibos__Init(preTestSetup = invalid, testUtilsDecoratorMethodName = in ? "######################################################" ? "" - runner = RBS_TR_TestRunner(args) + runner = TestRunner(args) runner.Run() while(true) @@ -96,3 +96,39 @@ function Rooibos__Init(preTestSetup = invalid, testUtilsDecoratorMethodName = in ? "#########################################################" end if end function + +function versionCompare(v1, v2) + v1parts = v1.split(".") + v2parts = v2.split(".") + + while v1parts.count() < v2parts.count() + v1parts.push("0") + end while + + while v2parts.count() < v1parts.count() + v2parts.push("0") + end while + + for i = 0 to v1parts.count() + if (v2parts.count() = i) + return 1 + end if + + if (v1parts[i] = v2parts[i]) + 'continue + else if (v1parts[i] > v2parts[i]) + return 1 + else + return -1 + end if + end for + + if (v1parts.count() <> v2parts.count()) + return -1 + end if + + return 0 + +end function + +end namespace \ No newline at end of file diff --git a/src/Rooibos_TestCase.brs b/src/Rooibos_TestCase.brs deleted file mode 100644 index d3ec006d..00000000 --- a/src/Rooibos_TestCase.brs +++ /dev/null @@ -1,37 +0,0 @@ -function UnitTestCase(name as string, func as dynamic, funcName as string, isSolo as boolean, isIgnored as boolean, lineNumber as integer, params = invalid, paramTestIndex =0, paramLineNumber = 0) - this = {} - this.isSolo = isSolo - this.func = func - this.funcName = funcName - this.isIgnored = isIgnored - this.name = name - this.lineNumber = lineNumber - this.paramLineNumber = paramLineNumber - this.assertIndex = 0 - 'Map with which the testsuite processor can take the index of a an assert line, and map it to the line Number - this.assertLineNumberMap = {} - this.AddAssertLine = RBS_TC_AddAssertLine - this.getTestLineIndex = 0 - this.rawParams = params - this.paramTestIndex = paramTestIndex - this.isParamTest = false - this.time = 0 - if (params <> invalid) - this.name += stri(this.paramTestIndex) - end if - return this -end function - -function RBS_TC_AddAssertLine(lineNumber as integer) - m.assertLineNumberMap[stri(m.assertIndex).trim()] = lineNumber - m.assertIndex++ -end function - -'Static, becuase the result might be created across node boundaries, therefore stripping methods -function RBS_TC_GetAssertLine(testCase, index) - if (testCase.assertLineNumberMap.doesExist(stri(index).trim())) - return testCase.assertLineNumberMap[stri(index).trim()] - else - return testCase.lineNumber - end if -end function diff --git a/src/Rooibos_RuntimeConfig.brs b/src/RuntimeConfig.bs similarity index 64% rename from src/Rooibos_RuntimeConfig.brs rename to src/RuntimeConfig.bs index 3d7800b7..a1859f34 100644 --- a/src/Rooibos_RuntimeConfig.brs +++ b/src/RuntimeConfig.bs @@ -1,17 +1,18 @@ -function UnitTestRuntimeConfig() - this = {} - this.CreateSuites = RBS_CreateSuites - this.hasSoloSuites = false - this.hasSoloGroups = false - this.hasSoloTests = false - this.suites = this.CreateSuites() - return this +namespace RBS_UTRC +class UnitTestRuntimeConfig + +public hasSoloSuites = false +public hasSoloGroups = false +public hasSoloTests = false + +public function new() + m.suites = m.CreateSuites() end function -function RBS_CreateSuites() +public function CreateSuites() suites = RBSFM_getTestSuitesForProject() includedSuites = [] - for i = 0 to suites.count() -1 + for i = 0 to suites.count() - 1 suite = suites[i] if (suite.valid) if (suite.isSolo) @@ -28,7 +29,10 @@ function RBS_CreateSuites() else ? "ERROR! suite was not valid - ignoring" end if - + end for return includedSuites -end function \ No newline at end of file +end function + +end class +end namespace \ No newline at end of file diff --git a/src/Rooibos_Stats.brs b/src/Stats.bs similarity index 82% rename from src/Rooibos_Stats.brs rename to src/Stats.bs index 3c72c294..602e6b64 100644 --- a/src/Rooibos_Stats.brs +++ b/src/Stats.bs @@ -1,10 +1,11 @@ +namespace RBS_STATS '---------------------------------------------------------------- ' Create an empty statistic object for totals in output log. ' ' @return An empty statistic object. '---------------------------------------------------------------- -function RBS_STATS_CreateTotalStatistic() as object +function CreateTotalStatistic() as object statTotalItem = { Suites : [] Time : 0 @@ -25,7 +26,7 @@ end function '** @param param as ObjectP paramdesc '** @return ObjectR retdesc '************************************************************* -function RBS_STATS_MergeTotalStatistic(stat1, stat2) as void +function MergeTotalStatistic(stat1, stat2) as void for each suite in stat2.Suites stat1.Suites.push(suite) end for @@ -46,7 +47,7 @@ end function ' ' @return An empty statistic object for test suite. '---------------------------------------------------------------- -function RBS_STATS_CreateSuiteStatistic(name as string) as object +function CreateSuiteStatistic(name as string) as object statSuiteItem = { Name : name Tests : [] @@ -87,7 +88,7 @@ end function ' ' @return A statistic object for test. '---------------------------------------------------------------- -function RBS_STATS_CreateTestStatistic(name as string, result = "Success" as string, time = 0 as integer, errorCode = 0 as integer, errorMessage = "" as string) as object +function CreateTestStatistic(name as string, result = "Success" as string, time = 0 as integer, errorCode = 0 as integer, errorMessage = "" as string) as object statTestItem = { Name : name Result : result @@ -107,11 +108,11 @@ end function ' @param statSuiteObj (object) A target test suite object. ' @param statTestObj (object) A test statistic to append. '---------------------------------------------------------------- -sub RBS_STATS_AppendTestStatistic(statSuiteObj as object, statTestObj as object) - if RBS_CMN_IsAssociativeArray(statSuiteObj) and RBS_CMN_IsAssociativeArray(statTestObj) +sub AppendTestStatistic(statSuiteObj as object, statTestObj as object) + if RBS_CMN.IsAssociativeArray(statSuiteObj) and RBS_CMN.IsAssociativeArray(statTestObj) statSuiteObj.Tests.Push(statTestObj) - if RBS_CMN_IsInteger(statTestObj.time) + if RBS_CMN.IsInteger(statTestObj.time) statSuiteObj.Time = statSuiteObj.Time + statTestObj.Time end if @@ -134,26 +135,28 @@ end sub ' @param statTotalObj (object) A target total statistic object. ' @param statSuiteObj (object) A test suite statistic object to append. '---------------------------------------------------------------- -sub RBS_STATS_AppendSuiteStatistic(statTotalObj as object, statSuiteObj as object) - if RBS_CMN_IsAssociativeArray(statTotalObj) and RBS_CMN_IsAssociativeArray(statSuiteObj) +sub AppendSuiteStatistic(statTotalObj as object, statSuiteObj as object) + if RBS_CMN.IsAssociativeArray(statTotalObj) and RBS_CMN.IsAssociativeArray(statSuiteObj) statTotalObj.Suites.Push(statSuiteObj) statTotalObj.Time = statTotalObj.Time + statSuiteObj.Time - if RBS_CMN_IsInteger(statSuiteObj.Total) + if RBS_CMN.IsInteger(statSuiteObj.Total) statTotalObj.Total = statTotalObj.Total + statSuiteObj.Total end if - if RBS_CMN_IsInteger(statSuiteObj.Correct) + if RBS_CMN.IsInteger(statSuiteObj.Correct) statTotalObj.Correct = statTotalObj.Correct + statSuiteObj.Correct end if - if RBS_CMN_IsInteger(statSuiteObj.Fail) + if RBS_CMN.IsInteger(statSuiteObj.Fail) statTotalObj.Fail = statTotalObj.Fail + statSuiteObj.Fail end if - if RBS_CMN_IsInteger(statSuiteObj.Crash) + if RBS_CMN.IsInteger(statSuiteObj.Crash) statTotalObj.Crash = statTotalObj.Crash + statSuiteObj.Crash end if end if end sub + +end namespace \ No newline at end of file diff --git a/src/TestCase.bs b/src/TestCase.bs new file mode 100644 index 00000000..66411444 --- /dev/null +++ b/src/TestCase.bs @@ -0,0 +1,50 @@ +namespace RBS_TC +class UnitTestCase + +public isSolo +public func +public funcName +public isIgnored +public name +public lineNumber +public paramLineNumber +public assertIndex = 0 +'Map with which the testsuite processor can take the index of a an assert line, and map it to the line Number +public assertLineNumberMap = {} +public getTestLineIndex = 0 +public rawParams +public paramTestIndex +public isParamTest = false +public time = 0 + +public function new(name as string, func as dynamic, funcName as string, isSolo as boolean, isIgnored as boolean, lineNumber as integer, params = invalid, paramTestIndex = 0, paramLineNumber = 0) + m.isSolo = isSolo + m.func = func + m.funcName = funcName + m.isIgnored = isIgnored + m.name = name + m.lineNumber = lineNumber + m.paramLineNumber = paramLineNumber + m.rawParams = params + m.paramTestIndex = paramTestIndex + + if (params <> invalid) + m.name += stri(m.paramTestIndex) + end if + + return this +end function + +public function AddAssertLine(lineNumber as integer) + m.assertLineNumberMap[stri(m.assertIndex).trim()] = lineNumber + m.assertIndex++ +end function + +'Static, becuase the result might be created across node boundaries, therefore stripping methods +public function GetAssertLine(testCase, index) + if (testCase.assertLineNumberMap.doesExist(stri(index).trim())) + return testCase.assertLineNumberMap[stri(index).trim()] + else + return testCase.lineNumber + end if +end function diff --git a/src/Rooibos_TestLogger.brs b/src/TestLogger.bs similarity index 81% rename from src/Rooibos_TestLogger.brs rename to src/TestLogger.bs index 27c0a776..61933d3e 100644 --- a/src/Rooibos_TestLogger.brs +++ b/src/TestLogger.bs @@ -1,26 +1,16 @@ -function Logger(config) as object - this = {} - this.config = config +namespace RBS_LOGGER +class Logger - this.verbosityLevel = { +public function new(config) + m.config = config + + m.verbosityLevel = { basic : 0 normal : 1 verbose : 2 } - ' Internal properties - this.verbosity = this.config.logLevel - - ' Interface - this.PrintStatistic = RBS_LOGGER_PrintStatistic - this.PrintMetaSuiteStart = RBS_LOGGER_PrintMetaSuiteStart - this.PrintSuiteStatistic = RBS_LOGGER_PrintSuiteStatistic - this.PrintTestStatistic = RBS_LOGGER_PrintTestStatistic - this.PrintStart = RBS_LOGGER_PrintStart - this.PrintEnd = RBS_LOGGER_PrintEnd - this.PrintSuiteStart = RBS_LOGGER_PrintSuiteStart - - return this + m.verbosity = m.config.logLevel end function '---------------------------------------------------------------- @@ -28,7 +18,7 @@ end function ' ' @param statObj (object) A statistic object to print. '---------------------------------------------------------------- -sub RBS_LOGGER_PrintStatistic(statObj as object) +public sub PrintStatistic(statObj as object) m.PrintStart() previousfile = invalid @@ -45,7 +35,7 @@ sub RBS_LOGGER_PrintStatistic(statObj as object) ? "" m.PrintEnd() ignoredInfo = RBSFM_getIgnoredTestInfo() - ? "Total = "; RBS_CMN_AsString(statObj.Total); " ; Passed = "; statObj.Correct; " ; Failed = "; statObj.Fail; " ; Ignored = "; ignoredInfo.count + ? "Total = "; RBS_CMN.AsString(statObj.Total); " ; Passed = "; statObj.Correct; " ; Failed = "; statObj.Fail; " ; Ignored = "; ignoredInfo.count ? " Time spent: "; statObj.Time; "ms" ? "" ? "" @@ -77,7 +67,7 @@ end sub ' ' @param statSuiteObj (object) A target test suite object to print. '---------------------------------------------------------------- -sub RBS_LOGGER_PrintSuiteStatistic(statSuiteObj as object, hasFailures) +public sub PrintSuiteStatistic(statSuiteObj as object, hasFailures) m.PrintSuiteStart(statSuiteObj.Name) for each testCase in statSuiteObj.Tests @@ -89,7 +79,7 @@ sub RBS_LOGGER_PrintSuiteStatistic(statSuiteObj as object, hasFailures) ? " |" end sub -sub RBS_LOGGER_PrintTestStatistic(testCase as object) +public sub PrintTestStatistic(testCase as object) metaTestCase = testCase.metaTestCase if (LCase(testCase.Result) <> "success") @@ -116,7 +106,7 @@ sub RBS_LOGGER_PrintTestStatistic(testCase as object) if (metaTestcase.isParamTest = true) insetText = " " - messageLine = RBS_LOGGER_FillText(" " + testChar + insetText + " |--" + formatJson(metaTestCase.rawParams) + " : ", ".", 80) + messageLine = m.fillText(" " + testChar + insetText + " |--" + formatJson(metaTestCase.rawParams) + " : ", ".", 80) ? messageLine ; testCase.Result ; " (" + stri(metaTestCase.time).trim() +"ms)" end if @@ -129,7 +119,7 @@ sub RBS_LOGGER_PrintTestStatistic(testCase as object) end if end sub -function RBS_LOGGER_FillText(text as string, fillChar = " ", numChars = 40) as string +public function FillText(text as string, fillChar = " ", numChars = 40) as string if (len(text) >= numChars) text = left(text, numChars - 5) + "..." + fillChar + fillChar else @@ -140,10 +130,11 @@ function RBS_LOGGER_FillText(text as string, fillChar = " ", numChars = 40) as s end if return text end function + '---------------------------------------------------------------- ' Print testting start message. '---------------------------------------------------------------- -sub RBS_LOGGER_PrintStart() +public sub PrintStart() ? "" ? "[START TEST REPORT]" ? "" @@ -152,7 +143,7 @@ end sub '---------------------------------------------------------------- ' Print testing end message. '---------------------------------------------------------------- -sub RBS_LOGGER_PrintEnd() +public sub PrintEnd() ? "" ? "[END TEST REPORT]" ? "" @@ -161,7 +152,7 @@ end sub '---------------------------------------------------------------- ' Print test suite SetUp message. '---------------------------------------------------------------- -sub RBS_LOGGER_PrintSuiteSetUp(sName as string) +public sub PrintSuiteSetUp(sName as string) if m.verbosity = m.verbosityLevel.verbose ? "=================================================================" ? "=== SetUp "; sName; " suite." @@ -174,14 +165,14 @@ end sub ' Print test suite start message. '---------------------------------------------------------------- -sub RBS_LOGGER_PrintMetaSuiteStart(metaTestSuite) +public sub PrintMetaSuiteStart(metaTestSuite) ? metaTestSuite.name; " " ; "pkg:/" ; metaTestSuite.filePath + "(1)" end sub '---------------------------------------------------------------- ' Print '@It group start message. '---------------------------------------------------------------- -sub RBS_LOGGER_PrintSuiteStart(sName as string) +public sub PrintSuiteStart(sName as string) ' ? "It "; sName ? " |-" ; sName ' ? "" @@ -190,7 +181,7 @@ end sub '---------------------------------------------------------------- ' Print test suite TearDown message. '---------------------------------------------------------------- -sub RBS_LOGGER_PrintSuiteTearDown(sName as string) +public sub PrintSuiteTearDown(sName as string) if m.verbosity = m.verbosityLevel.verbose ? "=================================================================" ? "=== TearDown "; sName; " suite." @@ -201,7 +192,7 @@ end sub '---------------------------------------------------------------- ' Print test setUp message. '---------------------------------------------------------------- -sub RBS_LOGGER_PrintTestSetUp(tName as string) +public sub PrintTestSetUp(tName as string) if m.verbosity = m.verbosityLevel.verbose ? "----------------------------------------------------------------" ? "--- SetUp "; tName; " test." @@ -212,10 +203,12 @@ end sub '---------------------------------------------------------------- ' Print test TearDown message. '---------------------------------------------------------------- -sub RBS_LOGGER_PrintTestTearDown(tName as string) +public sub PrintTestTearDown(tName as string) if m.verbosity = m.verbosityLevel.verbose ? "----------------------------------------------------------------" ? "--- TearDown "; tName; " test." ? "----------------------------------------------------------------" end if end sub + +end namespace \ No newline at end of file diff --git a/src/Rooibos_TestRunner.brs b/src/TestRunner.bs similarity index 85% rename from src/Rooibos_TestRunner.brs rename to src/TestRunner.bs index 8c2cda52..4e2d4cc1 100644 --- a/src/Rooibos_TestRunner.brs +++ b/src/TestRunner.bs @@ -1,3 +1,4 @@ +namespace RBS_TR ' /** ' * @module TestRunner ' */ @@ -8,16 +9,15 @@ ' * @function ' * @description Creates an instance of the test runner ' * @param {Dynamic} args - contains the application launch args, and other settings required for test execution -' * @returns {Object} TestRunner ' */ +class TestRunner -function RBS_TR_TestRunner(args = {}) as object - this = {} - this.testScene = args.testScene - this.nodeContext = args.nodeContext +public function new(args = {}) + m.testScene = args.testScene + m.nodeContext = args.nodeContext config = RBSFM_getRuntimeConfig() - if (config = invalid or not RBS_CMN_IsAssociativeArray(config)) + if (config = invalid or not RBS_CMN.IsAssociativeArray(config)) ? "WARNING : specified config is invalid - using default" config = { showOnlyFailures: false @@ -34,19 +34,14 @@ function RBS_TR_TestRunner(args = {}) as object config.failFast = args.failFast = "true" end if - this.testUtilsDecoratorMethodName = args.testUtilsDecoratorMethodName - this.config = config + m.testUtilsDecoratorMethodName = args.testUtilsDecoratorMethodName + m.config = config ' Internal properties - this.config.testsDirectory = config.testsDirectory + m.config.testsDirectory = config.testsDirectory - this.logger = Logger(this.config) - this.global = args.global - - ' Interface - this.Run = RBS_TR_Run - - return this + m.logger = Logger(m.config) + m.global = args.global end function ' /** @@ -56,13 +51,13 @@ end function ' * @instance ' * @description Executes all tests for a project, as per the config ' */ -sub RBS_TR_Run() +public sub Run() if type(RBSFM_getTestSuitesForProject) <> "Function" ? " ERROR! RBSFM_getTestSuitesForProject is not found! That looks like you didn't run the preprocessor as part of your test process. Please refer to the docs." return end if - totalStatObj = RBS_STATS_CreateTotalStatistic() + totalStatObj = RBS_STATS.CreateTotalStatistic() m.runtimeConfig = UnitTestRuntimeConfig() m.runtimeConfig.global = m.global totalStatObj.testRunHasFailures = false @@ -109,7 +104,7 @@ sub RBS_TR_Run() "runtimeConfig": m.runtimeConfig } nodeStatResults = node.callFunc("Rooibos_RunNodeTests", args) - RBS_STATS_MergeTotalStatistic(totalStatObj, nodeStatResults) + RBS_STATS.MergeTotalStatistic(totalStatObj, nodeStatResults) m.testScene.RemoveChild(node) @@ -121,35 +116,35 @@ sub RBS_TR_Run() if (metaTestSuite.hasIgnoredTests) totalStatObj.IgnoredTestNames.push("|-" + metaTestSuite.name) end if - RBS_RT_RunItGroups(metaTestSuite, totalStatObj, m.testUtilsDecoratorMethodName, m.config, m.runtimeConfig, m.nodeContext) + RBS_TR.RunItGroups(metaTestSuite, totalStatObj, m.testUtilsDecoratorMethodName, m.config, m.runtimeConfig, m.nodeContext) end if skipSuite: end for m.logger.PrintStatistic(totalStatObj) - if RBS_CMN_IsFunction(RBS_ReportCodeCoverage) - RBS_ReportCodeCoverage() + if RBS_CMN.IsFunction(RBS_TR_ReportCodeCoverage) + RBS_TR.ReportCodeCoverage() end if - RBS_TR_SendHomeKeypress() + RBS_TR.SendHomeKeypress() end sub -sub RBS_RT_RunItGroups(metaTestSuite, totalStatObj, testUtilsDecoratorMethodName, config, runtimeConfig, nodeContext = invalid) +public sub RunItGroups(metaTestSuite, totalStatObj, testUtilsDecoratorMethodName, config, runtimeConfig, nodeContext = invalid) if (testUtilsDecoratorMethodName <> invalid) - testUtilsDecorator = RBS_CMN_GetFunctionBruteForce(testUtilsDecoratorMethodName) - if (not RBS_CMN_IsFunction(testUtilsDecorator)) + testUtilsDecorator = RBS_CMN.GetFunctionBruteForce(testUtilsDecoratorMethodName) + if (not RBS_CMN.IsFunction(testUtilsDecorator)) ? "[ERROR] Test utils decorator method `" ; testUtilsDecoratorMethodName ;"` was not in scope! for testSuite: " + metaTestSuite.name end if end if for each itGroup in metaTestSuite.itGroups - testSuite = RBS_ItG_GetRunnableTestSuite(itGroup) + testSuite = RBS_ItG.GetRunnableTestSuite(itGroup) if (nodeContext <> invalid) testSuite.node = nodeContext testSuite.global = nodeContext.global testSuite.top = nodeContext.top end if - if (RBS_CMN_IsFunction(testUtilsDecorator)) + if (RBS_CMN.IsFunction(testUtilsDecorator)) testUtilsDecorator(testSuite) end if @@ -200,13 +195,13 @@ sub RBS_RT_RunItGroups(metaTestSuite, totalStatObj, testUtilsDecoratorMethodName goto skipItGroup end if - if RBS_CMN_IsFunction(testSuite.SetUp) + if RBS_CMN.IsFunction(testSuite.SetUp) testSuite.SetUp() end if - RBS_RT_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, runtimeConfig) + RBS_TR.RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, runtimeConfig) - if RBS_CMN_IsFunction(testSuite.TearDown) + if RBS_CMN.IsFunction(testSuite.TearDown) testSuite.TearDown() end if @@ -217,8 +212,8 @@ sub RBS_RT_RunItGroups(metaTestSuite, totalStatObj, testUtilsDecoratorMethodName end for end sub -sub RBS_RT_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, runtimeConfig) - suiteStatObj = RBS_STATS_CreateSuiteStatistic(itGroup.Name) +public sub RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, runtimeConfig) + suiteStatObj = RBS_STATS.CreateSuiteStatistic(itGroup.Name) testSuite.global = runtimeConfig.global for each testCase in testSuite.testCases @@ -228,13 +223,13 @@ sub RBS_RT_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, goto skipTestCase end if - if RBS_CMN_IsFunction(testSuite.beforeEach) + if RBS_CMN.IsFunction(testSuite.beforeEach) testSuite.beforeEach() end if testTimer = CreateObject("roTimespan") testCaseTimer = CreateObject("roTimespan") - testStatObj = RBS_STATS_CreateTestStatistic(testCase.Name) + testStatObj = RBS_STATS.CreateTestStatistic(testCase.Name) testSuite.testCase = testCase.Func testStatObj.filePath = metaTestSuite.filePath testStatObj.metaTestCase = metaTestCase @@ -298,9 +293,9 @@ sub RBS_RT_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, end if testStatObj.Time = testTimer.TotalMilliseconds() - RBS_STATS_AppendTestStatistic(suiteStatObj, testStatObj) + RBS_STATS.AppendTestStatistic(suiteStatObj, testStatObj) - if RBS_CMN_IsFunction(testSuite.afterEach) + if RBS_CMN.IsFunction(testSuite.afterEach) testSuite.afterEach() end if @@ -315,10 +310,10 @@ sub RBS_RT_RunTestCases(metaTestSuite, itGroup, testSuite, totalStatObj, config, end for suiteStatObj.metaTestSuite = metaTestSuite - RBS_STATS_AppendSuiteStatistic(totalStatObj, suiteStatObj) + RBS_STATS.AppendSuiteStatistic(totalStatObj, suiteStatObj) end sub -sub RBS_TR_SendHomeKeypress() +public sub SendHomeKeypress() ut = CreateObject("roUrlTransfer") ut.SetUrl("http://localhost:8060/keypress/Home") ut.PostFromString("") @@ -335,9 +330,9 @@ end sub ' */ function Rooibos_RunNodeTests(args) as object ? " RUNNING NODE TESTS" - totalStatObj = RBS_STATS_CreateTotalStatistic() + totalStatObj = RBS_STATS.CreateTotalStatistic() - RBS_RT_RunItGroups(args.metaTestSuite, totalStatObj, args.testUtilsDecoratorMethodName, args.config, args.runtimeConfig, m) + RBS_TR.RunItGroups(args.metaTestSuite, totalStatObj, args.testUtilsDecoratorMethodName, args.config, args.runtimeConfig, m) return totalStatObj end function diff --git a/src/Rooibos_TestResult.brs b/src/UnitTestResult.bs similarity index 52% rename from src/Rooibos_TestResult.brs rename to src/UnitTestResult.bs index cc089700..f5449551 100644 --- a/src/Rooibos_TestResult.brs +++ b/src/UnitTestResult.bs @@ -1,21 +1,17 @@ -function UnitTestResult() as object - this = {} - this.messages = CreateObject("roArray", 0, true) - this.isFail = false - this.currentAssertIndex = 0 - this.failedAssertIndex = 0 - this.Reset = RBS_TRes_Reset - this.AddResult = RBS_TRes_AddResult - this.GetResult = RBS_TRes_GetResult - return this -end function +namespace RBS_UTR +class UnitTestResult + +public messages = CreateObject("roArray", 0, true) +public isFail = false +public currentAssertIndex = 0 +public failedAssertIndex = 0 -function RBS_TRes_Reset() as void +public function Reset() as void m.isFail = false m.messages = CreateObject("roArray", 0, true) end function -function RBS_TRes_AddResult(message as string) as string +public function AddResult(message as string) as string if (message <> "") m.messages.push(message) if (not m.isFail) @@ -27,7 +23,7 @@ function RBS_TRes_AddResult(message as string) as string return message end function -function RBS_TRes_GetResult() as string +public function GetResult() as string if (m.isFail) msg = m.messages.peek() if (msg <> invalid) @@ -38,4 +34,7 @@ function RBS_TRes_GetResult() as string else return "" end if -end function \ No newline at end of file +end function + +end class +end namespace \ No newline at end of file