From dbecacfc5da168660c629f840fa0db40b6d6b9c4 Mon Sep 17 00:00:00 2001 From: Fulgerul Date: Thu, 12 Jan 2017 21:59:59 +0100 Subject: [PATCH 1/6] Fixed for 7.1 --- asserts.lua | 9 +++++++++ core.lua | 1 + frame.lua | 4 ++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/asserts.lua b/asserts.lua index 098fd4e..cf46c01 100644 --- a/asserts.lua +++ b/asserts.lua @@ -7,6 +7,7 @@ function wowUnit:assert(value, message) if (value) then wowUnit:CurrentTestSucceeded(message); else + message = message.." - Expected: 'a true value'" wowUnit:CurrentTestFailed(message); end end @@ -15,6 +16,7 @@ function wowUnit:assertEquals(value1, value2, message) if (value1 == value2) then wowUnit:CurrentTestSucceeded(message); else + message = message.." - Got '"..value1.."' Expected: '"..value2.."'" wowUnit:CurrentTestFailed(message); end end @@ -23,6 +25,7 @@ function wowUnit:assertNonEquals(value1, value2, message) if (value1 ~= value2) then wowUnit:CurrentTestSucceeded(message); else + message = message.." - Got '"..value1.."' Didn't expect: '"..value2.."'" wowUnit:CurrentTestFailed(message); end end @@ -32,6 +35,7 @@ function wowUnit:assertSame(value1, value2, message) if (wowUnit:DeepEquals(value1, value2)) then wowUnit:CurrentTestSucceeded(message); else + message = message.." - Got '"..value1.."' Expected: '"..value2.."'" wowUnit:CurrentTestFailed(message); end else @@ -75,6 +79,7 @@ function wowUnit:isTable(value, message) if (type(value) == "table")then wowUnit:CurrentTestSucceeded(message); else + message = message.." - Got '"..type(value).."' Expected: 'table'" wowUnit:CurrentTestFailed(message); end end @@ -83,6 +88,7 @@ function wowUnit:isString(value, message) if (type(value) == "string") then wowUnit:CurrentTestSucceeded(message); else + message = message.." - Got '"..type(value).."' Expected: 'string'" wowUnit:CurrentTestFailed(message); end end @@ -91,6 +97,7 @@ function wowUnit:isNumber(value, message) if (type(value) == "number") then wowUnit:CurrentTestSucceeded(message); else + message = message.." - Got '"..type(value).."' Expected: 'number'" wowUnit:CurrentTestFailed(message); end end @@ -99,6 +106,7 @@ function wowUnit:isNil(value, message) if (type(value) == "nil") then wowUnit:CurrentTestSucceeded(message); else + message = message.."' Expected: 'nil'" wowUnit:CurrentTestFailed(message); end end @@ -107,6 +115,7 @@ function wowUnit:isFunction(value, message) if (type(value) == "function") then wowUnit:CurrentTestSucceeded(message); else + message = message.." - Got '"..type(value).."' Expected: 'function'" wowUnit:CurrentTestFailed(message); end end diff --git a/core.lua b/core.lua index 7acad01..7aabaa9 100644 --- a/core.lua +++ b/core.lua @@ -34,6 +34,7 @@ function wowUnit:RegisterChatCommands() --TODO: remove this unless there is a reasonable command to add, like 'config' else if _G[command] then + print("this is cmd: " ..command.. " Gcmd:") wowUnit:SetCurrentTestSuiteName(command); wowUnit:StartTests(_G[command]); else diff --git a/frame.lua b/frame.lua index 41ae91a..ad98332 100644 --- a/frame.lua +++ b/frame.lua @@ -26,8 +26,8 @@ function wowUnit.UI:InitializeUI() mainFrame:SetHeight(460); mainFrame:SetWidth(460); mainFrame:EnableMouse(true); - local titleRegion = mainFrame:CreateTitleRegion(); - titleRegion:SetAllPoints(mainFrame); + --local titleRegion = mainFrame:CreateTitleRegion(); + --titleRegion:SetAllPoints(mainFrame); local closeButton = CreateFrame("Button", "wowUnitFrameCloseButton", mainFrame, "UIPanelCloseButton"); closeButton:SetWidth(30); From 7d1cef9d8790d1e56950816fae6dae6b325fbc1b Mon Sep 17 00:00:00 2001 From: Fulgerul Date: Fri, 13 Jan 2017 10:54:02 +0100 Subject: [PATCH 2/6] WoWUnit now works with WoW 7.1 (70100) --- wowUnit.toc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wowUnit.toc b/wowUnit.toc index 2c4dd2e..b16889d 100755 --- a/wowUnit.toc +++ b/wowUnit.toc @@ -1,11 +1,11 @@ -## Interface: 40100 +## Interface: 70100 ## Dependencies: ## OptionalDeps: ## SavedVariables: ## SavedVariablesPerCharacter: ## Title: wowUnit -## Author: Mirroar +## Author: Mirroar / Fulgerul (Contributor) ## Version: 4.1v1 ## Notes: A unit testing framework for LUA Addon developers. From 149903db6622391e2436f1ca5c7928f493df7ef8 Mon Sep 17 00:00:00 2001 From: Fulgerul Date: Thu, 26 Jan 2017 21:49:10 +0100 Subject: [PATCH 3/6] Found the test string! Was huge.. --- README.md | 299 +++++++++++++++++++++++++++++++++++++++++ asserts.lua | 31 ++++- core.lua | 29 ++-- external_functions.lua | 94 +++++++++++++ frame.lua | 21 ++- wowUnit.toc | 7 +- 6 files changed, 465 insertions(+), 16 deletions(-) create mode 100644 README.md create mode 100644 external_functions.lua diff --git a/README.md b/README.md new file mode 100644 index 0000000..767559c --- /dev/null +++ b/README.md @@ -0,0 +1,299 @@ +wowUnit is a [unit testing](http://en.wikipedia.org/wiki/Unit_testing "see Wikipedia") +framework intended to be used for AddOn development in World of Warcraft. + +Example +======= + +Say you have an AddOn called *addAddOn* that simply has a function for adding two +numbers. You could write tests to make sure the function performs as expected +like so: + + addAddOn.tests = { + ["Check addition of numbers"] = { + ["See if results are correct"] = function() + wowUnit:assertEquals(addAddOn:add(1, 1), 2, "1 and 1 is 2"); + wowUnit:assertEquals(addAddOn:add(-3, 5), 2, "-3 + 5 = 2"); + wowUnit:assertEquals(addAddOn:add(1997, -1995), 2, "1997 + (-1995) = 2"); + end, + ["make sure it behaves as expected for strange input"] = function() + wowUnit:isNil(addAddOn:add(), "nil when no parameters are given"); + wowUnit:isNil(addAddOn:add(1), "nil when only on parameter is given"); + wowUnit:isNil(addAddOn:add(nil, 1), "nil when only one parameter is given"); + wowUnit:assertEquals(addAddOn:add(-3, 5, 10), 2, "any parameters past the first 2 are ignored"); + wowUnit:isNil(addAddOn:add(1, "1"), "nil when a parameter is not a number"); + end + } + } + +Once tests are written and loaded, you could run these tests in game by typing +"*/test addAddOn*". + +Running Tests +============= + +You can easily run unit tests contained in any table directly accessible in the +global namespace by using any of the following slash-commands: + + /test myAddon + /wowunit myOtherAddon + /wu testTable + /unittest testSuite + +If your tests are buried deeper within another table, you'll have to run command +like so: + + /run wowUnit:StartTests(myAddon.someTable.testSuiteIsHere) + +Test Tables +=========== + +Anatomy of a Test Suite +----------------------- + +#### title +(optional) The title of this test suite, diplayed in wowUnit's main window +#### tests +A table containing the test categories for this test suite. The keys of any +entries in this table serve as titles for your categories, while their values +should be tables containing the actual tests. + +Example: + + testTable = { + title = "My test Suite", + tests = { + ["Category 1"] = { + ... + }, + ["Another Category"] = { + ... + }, + ... + } + } + +Anatomy of a Test Category +-------------------------- + +#### setup +(optional) The function defined here will be called before every test in the +current category. +#### teardown +(optional) The function defined here will be called after every test in the +current category. + +Any other functions defined in the table will be considered tests. + +Example: + + ... + ["Example Category"] = { + ["setup"] = function() + -- mock complicated function + myAddon.oldFunc = myAddon.complicatedFunction; + myAddon.complicatedFunction = function() + assert(true, "complicated function has been called"); + end + end, + ["teardown"] = function() + -- restore complicated function + myAddon.complicatedFunction = myAddon.oldFunc; + end, + ["does it get called?"] = function() + wowUnit:expect(1); + myAddon.shouldCallTheOtherFunction(); + end, + ... + } + ... + +Assertions +========== + +wowUnit:assert(value, message) +------------------------------ + +#### value +This test will pass if and only if value evaluates to true in an _if (value) then +..._ statement. + +#### message +(optional) This message will be displayed in the test window to indicate which +tests passed or failed. + +wowUnit:assertEquals(value1, value2, message) +--------------------------------------------- + +#### value1, value2 +This test will pass if and only if value1 is deemed equal to value2 in an _if +(value1 == value2) then ..._ statement. + +Note: Lua does not do automatic type conversion here, so _1_ and _"1"_ are not +equal. Also, two table values are only deemed equal if they reference the exact +same table. Two tables at different adresses are not deemed equal, even if their +contents are the same. + +#### message +(optional) This message will be displayed in the test window to indicate which +tests passed or failed. + +wowUnit:assertNonEquals(value1, value2, message) +--------------------------------------------- + +#### value1, value2 +This test will pass if and only if value1 is not deemed equal to value2 in an _if +(value1 ~= value2) then ..._ statement. + +Note: Lua does not do automatic type conversion here, so _1_ and _"1"_ are not +equal. + +#### message +(optional) This message will be displayed in the test window to indicate which +tests passed or failed. + + +wowUnit:assertSame(value1, value2, message) +------------------------------------------- + +#### value1, value2 +If any of the two values are not tables, this will behave exactly like +wowUnit:assertEquals. Provided with two tables, a recursive comparison will be +done to see whether the contents of the two tables are the same. + +#### message +(optional) This message will be displayed in the test window to indicate which +tests passed or failed. + +wowUnit:isNil(value, message) +----------------------------- + +#### value +This test will pass if and only if value evaluates to nil in an +_if (type(value) == "nil") then ..._ statement. + +#### message +(optional) This message will be displayed in the test window to indicate which +tests passed or failed. + +wowUnit:isTable(value, message) +------------------------------- + +#### value +This test will pass if and only if value evaluates to a table in an +_if (type(value) == "table") then ..._ statement. + +#### message +(optional) This message will be displayed in the test window to indicate which +tests passed or failed. + +wowUnit:isString(value, message) +-------------------------------- + +#### value +This test will pass if and only if value evaluates to a string in an +_if (type(value) == "string") then ..._ statement. + +#### message +(optional) This message will be displayed in the test window to indicate which +tests passed or failed. + +wowUnit:isNumber(value, message) +-------------------------------- + +#### value +This test will pass if and only if value evaluates to a number in an +_if (type(value) == "number") then ..._ statement. + +#### message +(optional) This message will be displayed in the test window to indicate which +tests passed or failed. + +wowUnit:isFunction(value, message) +---------------------------------- + +#### value +This test will pass if and only if value evaluates to a function in an +_if (type(value) == "function") then ..._ statement. + +#### message +(optional) This message will be displayed in the test window to indicate which +tests passed or failed. + +wowUnit:expect(numTests) +------------------------ + +#### numTests +This will pass if - during the course of the current test function - a number of +assertions is run that equals numTests. + +Note: you can set the number of expected tests at any time during a test function. +It will only be checked after the test has completed. The following test, for +example, will show two successful assertions. + + ["expectation test"] = function() + wowUnit:expect(1); + wowUnit:assert(true); + end + +Asynchronous Testing +==================== + +If you want to test processes that take a while to complete and don't block the +main thread, you will have to tell wowUnit to wait for more results instead of +continuing on to the next test. + +Example: + + ["asynch test"] = function() + wowUnit:expect(1); + local testID = wowUnit:pauseTesting(10); + local timeElapsed = 0; + local timeFrame = CreateFrame("Frame"); + timeFrame:SetScript("OnUpdate", function(self, elapsed) + timeElapsed = timeElapsed + elapsed; + + -- How many seconds you want to block + if (timeElapsed > 5) then + timeFrame:SetScript("OnUpdate", nil); -- don't forget to remove checks like this, otherwise you might be spamming asserts every frame + + -- Code to check the results + wowUnit:assert(myAddon.processCompleted, "all done"); + + -- Code to release block + wowUnit:resumeTesting(testID); + end + end) + + -- Code you want to run + myAddon:StartProcess(); + end + +testID = wowUnit:pauseTesting(timeout) +-------------------------------------- + +Will pause running new tests until the timeout is reached or wowUnit:resumeTesting +is called. + +#### timeout +(optional) New tests will not be run until this timeout (in seconds) is reached. +Default is 5 seconds. + +#### testID +A unique ID for the currently running test, to be used with wowUnit:resumeTesting. + +wowUnit:resumeTesting(testID) +----------------------------- + +Will try to resume normal testing on the next frame. + +#### testID +(optional) If provided, testing will only be resumed if the provided testID +matches the value returned by the most recent call to wowUnit:pauseTesting. + +What Else? +========== + +If you need further insights and examples for tests, check out wowUnit's tests.lua +and compare it with the results of running "*/test wowUnit*" ingame. + + diff --git a/asserts.lua b/asserts.lua index 491874e..46a9ee9 100644 --- a/asserts.lua +++ b/asserts.lua @@ -7,7 +7,9 @@ function wowUnit:assert(value, message) if (value) then wowUnit:CurrentTestSucceeded(message); else + message = message.." - Expected: 'a true value'" wowUnit:CurrentTestFailed(message); + print(message) end end @@ -15,7 +17,19 @@ function wowUnit:assertEquals(value1, value2, message) if (value1 == value2) then wowUnit:CurrentTestSucceeded(message); else + message = message.." - Got '"..tostring(value1).."' Expected: '"..tostring(value2).."'" wowUnit:CurrentTestFailed(message); + print(message) + end +end + +function wowUnit:assertNonEquals(value1, value2, message) + if (value1 ~= value2) then + wowUnit:CurrentTestSucceeded(message); + else + message = message.." - Got '"..tostring(value1).."' Expected: '"..tostring(value2).."'" + wowUnit:CurrentTestFailed(message); + print(message) end end @@ -24,7 +38,8 @@ function wowUnit:assertSame(value1, value2, message) if (wowUnit:DeepEquals(value1, value2)) then wowUnit:CurrentTestSucceeded(message); else - wowUnit:CurrentTestFailed(message); + message = message.." - Got '"..tostring(value1).."' Expected: '"..tostring(value2).."'" + wowUnit:CurrentTestFailed(message); end else wowUnit:assertEquals(value1, value2, message); @@ -67,6 +82,7 @@ function wowUnit:isTable(value, message) if (type(value) == "table")then wowUnit:CurrentTestSucceeded(message); else + message = message.." - Got '"..type(value).."' Expected: 'table'" wowUnit:CurrentTestFailed(message); end end @@ -75,6 +91,7 @@ function wowUnit:isString(value, message) if (type(value) == "string") then wowUnit:CurrentTestSucceeded(message); else + message = message.." - Got '"..type(value).."' Expected: 'string'" wowUnit:CurrentTestFailed(message); end end @@ -83,6 +100,7 @@ function wowUnit:isNumber(value, message) if (type(value) == "number") then wowUnit:CurrentTestSucceeded(message); else + message = message.." - Got '"..type(value).."' Expected: 'number'" wowUnit:CurrentTestFailed(message); end end @@ -91,6 +109,17 @@ function wowUnit:isNil(value, message) if (type(value) == "nil") then wowUnit:CurrentTestSucceeded(message); else + message = message.."' Expected: 'nil'" + wowUnit:CurrentTestFailed(message); + print(message) + end +end + +function wowUnit:isFunction(value, message) + if (type(value) == "function") then + wowUnit:CurrentTestSucceeded(message); + else + message = message.." - Got '"..type(value).."' Expected: 'function'" wowUnit:CurrentTestFailed(message); end end diff --git a/core.lua b/core.lua index 15d1363..66205e6 100644 --- a/core.lua +++ b/core.lua @@ -34,6 +34,7 @@ function wowUnit:RegisterChatCommands() --TODO: remove this unless there is a reasonable command to add, like 'config' else if _G[command] then + print("this is cmd: " ..command.. " Gcmd:") wowUnit:SetCurrentTestSuiteName(command); wowUnit:StartTests(_G[command]); else @@ -47,7 +48,6 @@ function wowUnit:SetCurrentTestSuiteName(name) wowUnit.testSuiteName = name; wowUnit.UI:SetTestSuiteName(); end - function wowUnit:StartTests(testTable) if type(testTable) ~= "table" then wowUnit:Print("Invalid test suite supplied: Object is not a table."); @@ -71,7 +71,7 @@ function wowUnit:IterateTestSuiteCategories(testTable) end wowUnit:ResetAllTestingData(); - for testCategoryTitle, testCategoryTable in pairs(testTable.tests) do + for testCategoryTitle, testCategoryTable in orderedPairs(testTable.tests) do wowUnit:PrepareCategoryForTesting(testCategoryTitle, testCategoryTable); end @@ -102,6 +102,12 @@ function wowUnit:ResetAllTestingData() wowUnit.testTimeout = nil; wowUnit.testPaused = false; wowUnit.currentTestID = 0; + + local i = 1; + while (_G["wowUnitTestCategory"..i]) do + _G["wowUnitTestCategory"..i]:Hide(); + i = i + 1; + end end function wowUnit:PrepareCategoryForTesting(testCategoryTitle, testCategoryTable) @@ -120,7 +126,7 @@ end function wowUnit:PrepareTestsTable(testCategoryTable) local testsTable = {}; - for testTitle, testFunc in pairs(testCategoryTable) do + for testTitle, testFunc in orderedPairs(testCategoryTable) do if (testTitle ~= "setup" and testTitle ~= "teardown") then tinsert(testsTable, { title = testTitle, @@ -181,6 +187,7 @@ function wowUnit:CompleteTest() end resultString = resultString.." |cff00ff00"..wowUnit.currentTestResults.success.."|r"; resultString = resultString.."/|cffff0000"..wowUnit.currentTestResults.failure.."|r"; + if (wowUnit.currentTestResults.expect == nil) then resultString = resultString.."/"..wowUnit.currentTestResults.total; else @@ -348,11 +355,13 @@ function wowUnit:CurrentTestSucceeded(message) wowUnit.currentTestSuiteResults.total = wowUnit.currentTestSuiteResults.total + 1; wowUnit.currentTestCategoryResults.total = wowUnit.currentTestCategoryResults.total + 1; wowUnit.currentTestResults.total = wowUnit.currentTestResults.total + 1; - if (message ~= nil) then - local currentCategory = wowUnit.currentTests[wowUnit.currentCategoryIndex]; - local currentTest = currentCategory.tests[wowUnit.currentTestIndex]; + local currentCategory = wowUnit.currentTests[wowUnit.currentCategoryIndex]; + local currentTest = currentCategory.tests[wowUnit.currentTestIndex]; + if (message ~= nil) then currentTest.result = currentTest.result..POSITIVE.." |cff00ff00"..message.."|r\n"; + else + currentTest.result = currentTest.result..POSITIVE.."\n"; end end @@ -364,11 +373,13 @@ function wowUnit:CurrentTestFailed(message) wowUnit.currentTestSuiteResults.total = wowUnit.currentTestSuiteResults.total + 1; wowUnit.currentTestCategoryResults.total = wowUnit.currentTestCategoryResults.total + 1; wowUnit.currentTestResults.total = wowUnit.currentTestResults.total + 1; - if (message ~= nil) then - local currentCategory = wowUnit.currentTests[wowUnit.currentCategoryIndex]; - local currentTest = currentCategory.tests[wowUnit.currentTestIndex]; + local currentCategory = wowUnit.currentTests[wowUnit.currentCategoryIndex]; + local currentTest = currentCategory.tests[wowUnit.currentTestIndex]; + if (message ~= nil) then currentTest.result = currentTest.result..NEGATIVE.." |cffff0000"..message.."|r\n"; + else + currentTest.result = currentTest.result..NEGATIVE.."\n"; end end diff --git a/external_functions.lua b/external_functions.lua new file mode 100644 index 0000000..f7908a4 --- /dev/null +++ b/external_functions.lua @@ -0,0 +1,94 @@ +-------------------------------------------------------------------------- +--[[ + +http://lua-users.org/wiki/SortedIteration + +Ordered table iterator, allow to iterate on the natural order of the keys of a +table. + +Example: + +t = { + ['1'] = nil, + ['2'] = nil, + ['3'] = 'xxx', + ['4'] = 'xxx', + ['5'] = 'xxx', +} + +print("Ordered iterating") +for key, val in orderedPairs(t) do + print(key.." : "..val) +end + +Output: +Ordered iterating +3: xxx +4: xxx +5: xxx +]] + +function cmp_multitype(op1, op2) + local type1, type2 = type(op1), type(op2) + if type1 ~= type2 then --cmp by type + return type1 < type2 + elseif type1 == "number" and type2 == "number" + or type1 == "string" and type2 == "string" then + return op1 < op2 --comp by default + elseif type1 == "boolean" and type2 == "boolean" then + return op1 == true + else + return tostring(op1) < tostring(op2) --cmp by address + end +end + +function __genOrderedIndex( t ) + local orderedIndex = {} + for key in pairs(t) do + table.insert( orderedIndex, key ) + end + table.sort( orderedIndex, cmp_multitype ) --### CANGE ### + + return orderedIndex +end + +function orderedNext(t, state) + -- Equivalent of the next function, but returns the keys in the alphabetic + -- order. We use a temporary ordered key table that is stored in the + -- table being iterated. + + --print("orderedNext: state = "..tostring(state) ) + if state == nil then + -- the first time, generate the index + t.__orderedIndex = __genOrderedIndex( t ) + key = t.__orderedIndex[1] + + if key ~= "__orderedIndex" then + return key, t[key] + end + end + -- fetch the next value + key = nil + for i = 1,table.getn(t.__orderedIndex) do + if t.__orderedIndex[i] == state then + key = t.__orderedIndex[i+1] + end + end + + if key and key ~= "__orderedIndex "then + + + return key, t[key] + + end + + -- no more value to return, cleanup + t.__orderedIndex = nil + return +end + +function orderedPairs(t) + -- Equivalent of the pairs() function on tables. Allows to iterate + -- in order + return orderedNext, t, nil +end \ No newline at end of file diff --git a/frame.lua b/frame.lua index 361bfca..f3379e8 100644 --- a/frame.lua +++ b/frame.lua @@ -24,10 +24,14 @@ function wowUnit.UI:InitializeUI() } }); mainFrame:SetHeight(460); - mainFrame:SetWidth(344); + mainFrame:SetWidth(460); mainFrame:EnableMouse(true); - local titleRegion = mainFrame:CreateTitleRegion(); - titleRegion:SetAllPoints(mainFrame); + mainFrame:SetMovable(true) + mainFrame:RegisterForDrag("LeftButton") + mainFrame:SetScript("OnDragStart", mainFrame.StartMoving) + mainFrame:SetScript("OnDragStop", mainFrame.StopMovingOrSizing) + --local titleRegion = mainFrame:CreateTitleRegion(); + --titleRegion:SetAllPoints(mainFrame); local closeButton = CreateFrame("Button", "wowUnitFrameCloseButton", mainFrame, "UIPanelCloseButton"); closeButton:SetWidth(30); @@ -74,6 +78,7 @@ function wowUnit.UI:AddTestCategory() categoryFrame.NameText:SetText(currentCategory.title); categoryFrame.testCategory = currentCategory; + categoryFrame:Show(); wowUnit.UI:UpdateTestCategoryFrame(categoryFrame); end @@ -167,8 +172,16 @@ function wowUnit.UI:UpdateTestCategoryFrame(statGroup) else statGroup.BgBottom:SetHeight(46); end + + -- hide extra statframes from old testing + i = #currentCategory.tests + 1; + while (_G[statGroup:GetName().."Test"..i]) do + _G[statGroup:GetName().."Test"..i]:Hide(); + i = i + 1; + end end + function wowUnit.UI:ToggleTestFrame(frame) if not frame.opened then if not frame.resultString then @@ -181,9 +194,11 @@ function wowUnit.UI:ToggleTestFrame(frame) frame.resultString:SetJustifyV("TOP"); --frame.resultString:SetTextHeight(10); frame.resultString:SetWordWrap(true); + end frame.resultString:SetText(frame.test.result); + if string.len(frame.test.result) > 10000 then KPS:DebugMsg(frame.test.result) end frame.resultString:Show(); frame:SetHeight(frame.resultString:GetHeight() + frame.startingHeight); diff --git a/wowUnit.toc b/wowUnit.toc index e51e79c..b16889d 100755 --- a/wowUnit.toc +++ b/wowUnit.toc @@ -1,16 +1,17 @@ -## Interface: 40100 +## Interface: 70100 ## Dependencies: ## OptionalDeps: ## SavedVariables: ## SavedVariablesPerCharacter: ## Title: wowUnit -## Author: Mirroar +## Author: Mirroar / Fulgerul (Contributor) ## Version: 4.1v1 ## Notes: A unit testing framework for LUA Addon developers. template.xml - + +external_functions.lua core.lua frame.lua asserts.lua From 33c2c5571b823b19009c5770119f00ae8294b8d4 Mon Sep 17 00:00:00 2001 From: Fulgerul Date: Fri, 27 Jan 2017 00:48:29 +0100 Subject: [PATCH 4/6] Implemented a scrollTable for large test results. TODO: Implement Ac3 GUI --- Libs/Ace3/Ace3.lua | 110 + Libs/Ace3/Ace3.toc | 31 + Libs/Ace3/AceAddon-3.0/AceAddon-3.0.lua | 674 ++++++ Libs/Ace3/AceAddon-3.0/AceAddon-3.0.xml | 4 + Libs/Ace3/AceBucket-3.0/AceBucket-3.0.lua | 293 +++ Libs/Ace3/AceBucket-3.0/AceBucket-3.0.xml | 4 + Libs/Ace3/AceComm-3.0/AceComm-3.0.lua | 302 +++ Libs/Ace3/AceComm-3.0/AceComm-3.0.xml | 5 + Libs/Ace3/AceComm-3.0/ChatThrottleLib.lua | 524 +++++ Libs/Ace3/AceConfig-3.0/AceConfig-3.0.lua | 57 + Libs/Ace3/AceConfig-3.0/AceConfig-3.0.xml | 8 + .../AceConfigCmd-3.0/AceConfigCmd-3.0.lua | 794 +++++++ .../AceConfigCmd-3.0/AceConfigCmd-3.0.xml | 4 + .../AceConfigDialog-3.0.lua | 1955 +++++++++++++++++ .../AceConfigDialog-3.0.xml | 4 + .../AceConfigRegistry-3.0.lua | 349 +++ .../AceConfigRegistry-3.0.xml | 4 + Libs/Ace3/AceConsole-3.0/AceConsole-3.0.lua | 250 +++ Libs/Ace3/AceConsole-3.0/AceConsole-3.0.xml | 4 + Libs/Ace3/AceDB-3.0/AceDB-3.0.lua | 746 +++++++ Libs/Ace3/AceDB-3.0/AceDB-3.0.xml | 4 + .../AceDBOptions-3.0/AceDBOptions-3.0.lua | 460 ++++ .../AceDBOptions-3.0/AceDBOptions-3.0.xml | 4 + Libs/Ace3/AceEvent-3.0/AceEvent-3.0.lua | 126 ++ Libs/Ace3/AceEvent-3.0/AceEvent-3.0.xml | 4 + .../AceGUI-3.0-SharedMediaWidgets.toc | 14 + .../BackgroundWidget.lua | 162 ++ .../BorderWidget.lua | 163 ++ .../FontWidget.lua | 94 + .../SharedFunctions.lua | 55 + .../SoundWidget.lua | 274 +++ .../StatusbarWidget.lua | 106 + .../AceGUI-3.0-SharedMediaWidgets/widget.xml | 9 + ...og-AceGUI-3.0-SharedMediaWidgets-3.3.1.txt | 23 + .../AceGUI-3.0-SharedMediaWidgets/widget.xml | 4 + Libs/Ace3/AceGUI-3.0/AceGUI-3.0.lua | 813 +++++++ Libs/Ace3/AceGUI-3.0/AceGUI-3.0.xml | 28 + .../AceGUIContainer-BlizOptionsGroup.lua | 138 ++ .../widgets/AceGUIContainer-DropDownGroup.lua | 157 ++ .../widgets/AceGUIContainer-Frame.lua | 311 +++ .../widgets/AceGUIContainer-InlineGroup.lua | 103 + .../widgets/AceGUIContainer-ScrollFrame.lua | 210 ++ .../widgets/AceGUIContainer-SimpleGroup.lua | 69 + .../widgets/AceGUIContainer-TabGroup.lua | 350 +++ .../widgets/AceGUIContainer-TreeGroup.lua | 717 ++++++ .../widgets/AceGUIContainer-Window.lua | 331 +++ .../widgets/AceGUIWidget-BlizOptionsGroup.lua | 153 ++ .../widgets/AceGUIWidget-Button.lua | 103 + .../widgets/AceGUIWidget-CheckBox.lua | 295 +++ .../widgets/AceGUIWidget-ColorPicker.lua | 194 ++ .../widgets/AceGUIWidget-DropDown-Items.lua | 477 ++++ .../widgets/AceGUIWidget-DropDown.lua | 737 +++++++ .../widgets/AceGUIWidget-DropDownGroup.lua | 178 ++ .../widgets/AceGUIWidget-EditBox.lua | 265 +++ .../AceGUI-3.0/widgets/AceGUIWidget-Frame.lua | 309 +++ .../widgets/AceGUIWidget-Heading.lua | 78 + .../AceGUI-3.0/widgets/AceGUIWidget-Icon.lua | 140 ++ .../widgets/AceGUIWidget-InlineGroup.lua | 138 ++ .../widgets/AceGUIWidget-InteractiveLabel.lua | 101 + .../widgets/AceGUIWidget-Keybinding.lua | 249 +++ .../AceGUI-3.0/widgets/AceGUIWidget-Label.lua | 166 ++ .../widgets/AceGUIWidget-MultiLineEditBox.lua | 366 +++ .../widgets/AceGUIWidget-ScrollFrame.lua | 241 ++ .../widgets/AceGUIWidget-SimpleGroup.lua | 99 + .../widgets/AceGUIWidget-Slider.lua | 285 +++ .../widgets/AceGUIWidget-TabGroup.lua | 387 ++++ .../widgets/AceGUIWidget-TreeGroup.lua | 746 +++++++ .../widgets/AceGUIWidget-Window.lua | 328 +++ Libs/Ace3/AceHook-3.0/AceHook-3.0.lua | 511 +++++ Libs/Ace3/AceHook-3.0/AceHook-3.0.xml | 4 + Libs/Ace3/AceLocale-3.0/AceLocale-3.0.lua | 137 ++ Libs/Ace3/AceLocale-3.0/AceLocale-3.0.xml | 4 + .../AceSerializer-3.0/AceSerializer-3.0.lua | 287 +++ .../AceSerializer-3.0/AceSerializer-3.0.xml | 4 + Libs/Ace3/AceTab-3.0/AceTab-3.0.lua | 446 ++++ Libs/Ace3/AceTab-3.0/AceTab-3.0.xml | 4 + Libs/Ace3/AceTimer-3.0/AceTimer-3.0.lua | 276 +++ Libs/Ace3/AceTimer-3.0/AceTimer-3.0.xml | 4 + Libs/Ace3/Bindings.xml | 5 + .../CallbackHandler-1.0.lua | 238 ++ .../CallbackHandler-1.0.xml | 4 + Libs/Ace3/Changelog-Ace3-Release-r1151.txt | 92 + Libs/Ace3/LICENSE.txt | 29 + .../LibSharedMedia-3.0/LibSharedMedia-3.0.lua | 227 ++ Libs/Ace3/LibSharedMedia-3.0/lib.xml | 4 + Libs/Ace3/LibStub/LibStub.lua | 30 + Libs/Ace3/changelog.txt | 381 ++++ frame.lua | 32 +- wowUnit.toc | 5 + 89 files changed, 19606 insertions(+), 4 deletions(-) create mode 100644 Libs/Ace3/Ace3.lua create mode 100644 Libs/Ace3/Ace3.toc create mode 100644 Libs/Ace3/AceAddon-3.0/AceAddon-3.0.lua create mode 100644 Libs/Ace3/AceAddon-3.0/AceAddon-3.0.xml create mode 100644 Libs/Ace3/AceBucket-3.0/AceBucket-3.0.lua create mode 100644 Libs/Ace3/AceBucket-3.0/AceBucket-3.0.xml create mode 100644 Libs/Ace3/AceComm-3.0/AceComm-3.0.lua create mode 100644 Libs/Ace3/AceComm-3.0/AceComm-3.0.xml create mode 100644 Libs/Ace3/AceComm-3.0/ChatThrottleLib.lua create mode 100644 Libs/Ace3/AceConfig-3.0/AceConfig-3.0.lua create mode 100644 Libs/Ace3/AceConfig-3.0/AceConfig-3.0.xml create mode 100644 Libs/Ace3/AceConfig-3.0/AceConfigCmd-3.0/AceConfigCmd-3.0.lua create mode 100644 Libs/Ace3/AceConfig-3.0/AceConfigCmd-3.0/AceConfigCmd-3.0.xml create mode 100644 Libs/Ace3/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.lua create mode 100644 Libs/Ace3/AceConfig-3.0/AceConfigDialog-3.0/AceConfigDialog-3.0.xml create mode 100644 Libs/Ace3/AceConfig-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.lua create mode 100644 Libs/Ace3/AceConfig-3.0/AceConfigRegistry-3.0/AceConfigRegistry-3.0.xml create mode 100644 Libs/Ace3/AceConsole-3.0/AceConsole-3.0.lua create mode 100644 Libs/Ace3/AceConsole-3.0/AceConsole-3.0.xml create mode 100644 Libs/Ace3/AceDB-3.0/AceDB-3.0.lua create mode 100644 Libs/Ace3/AceDB-3.0/AceDB-3.0.xml create mode 100644 Libs/Ace3/AceDBOptions-3.0/AceDBOptions-3.0.lua create mode 100644 Libs/Ace3/AceDBOptions-3.0/AceDBOptions-3.0.xml create mode 100644 Libs/Ace3/AceEvent-3.0/AceEvent-3.0.lua create mode 100644 Libs/Ace3/AceEvent-3.0/AceEvent-3.0.xml create mode 100644 Libs/Ace3/AceGUI-3.0-SharedMediaWidgets/AceGUI-3.0-SharedMediaWidgets.toc create mode 100644 Libs/Ace3/AceGUI-3.0-SharedMediaWidgets/AceGUI-3.0-SharedMediaWidgets/BackgroundWidget.lua create mode 100644 Libs/Ace3/AceGUI-3.0-SharedMediaWidgets/AceGUI-3.0-SharedMediaWidgets/BorderWidget.lua create mode 100644 Libs/Ace3/AceGUI-3.0-SharedMediaWidgets/AceGUI-3.0-SharedMediaWidgets/FontWidget.lua create mode 100644 Libs/Ace3/AceGUI-3.0-SharedMediaWidgets/AceGUI-3.0-SharedMediaWidgets/SharedFunctions.lua create mode 100644 Libs/Ace3/AceGUI-3.0-SharedMediaWidgets/AceGUI-3.0-SharedMediaWidgets/SoundWidget.lua create mode 100644 Libs/Ace3/AceGUI-3.0-SharedMediaWidgets/AceGUI-3.0-SharedMediaWidgets/StatusbarWidget.lua create mode 100644 Libs/Ace3/AceGUI-3.0-SharedMediaWidgets/AceGUI-3.0-SharedMediaWidgets/widget.xml create mode 100644 Libs/Ace3/AceGUI-3.0-SharedMediaWidgets/Changelog-AceGUI-3.0-SharedMediaWidgets-3.3.1.txt create mode 100644 Libs/Ace3/AceGUI-3.0-SharedMediaWidgets/widget.xml create mode 100644 Libs/Ace3/AceGUI-3.0/AceGUI-3.0.lua create mode 100644 Libs/Ace3/AceGUI-3.0/AceGUI-3.0.xml create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIContainer-BlizOptionsGroup.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIContainer-DropDownGroup.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIContainer-Frame.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIContainer-InlineGroup.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIContainer-ScrollFrame.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIContainer-SimpleGroup.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIContainer-TabGroup.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIContainer-TreeGroup.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIContainer-Window.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-BlizOptionsGroup.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-Button.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-CheckBox.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-ColorPicker.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-DropDown-Items.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-DropDown.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-DropDownGroup.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-EditBox.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-Frame.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-Heading.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-Icon.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-InlineGroup.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-InteractiveLabel.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-Keybinding.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-Label.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-MultiLineEditBox.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-ScrollFrame.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-SimpleGroup.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-Slider.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-TabGroup.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-TreeGroup.lua create mode 100644 Libs/Ace3/AceGUI-3.0/widgets/AceGUIWidget-Window.lua create mode 100644 Libs/Ace3/AceHook-3.0/AceHook-3.0.lua create mode 100644 Libs/Ace3/AceHook-3.0/AceHook-3.0.xml create mode 100644 Libs/Ace3/AceLocale-3.0/AceLocale-3.0.lua create mode 100644 Libs/Ace3/AceLocale-3.0/AceLocale-3.0.xml create mode 100644 Libs/Ace3/AceSerializer-3.0/AceSerializer-3.0.lua create mode 100644 Libs/Ace3/AceSerializer-3.0/AceSerializer-3.0.xml create mode 100644 Libs/Ace3/AceTab-3.0/AceTab-3.0.lua create mode 100644 Libs/Ace3/AceTab-3.0/AceTab-3.0.xml create mode 100644 Libs/Ace3/AceTimer-3.0/AceTimer-3.0.lua create mode 100644 Libs/Ace3/AceTimer-3.0/AceTimer-3.0.xml create mode 100644 Libs/Ace3/Bindings.xml create mode 100644 Libs/Ace3/CallbackHandler-1.0/CallbackHandler-1.0.lua create mode 100644 Libs/Ace3/CallbackHandler-1.0/CallbackHandler-1.0.xml create mode 100644 Libs/Ace3/Changelog-Ace3-Release-r1151.txt create mode 100644 Libs/Ace3/LICENSE.txt create mode 100644 Libs/Ace3/LibSharedMedia-3.0/LibSharedMedia-3.0.lua create mode 100644 Libs/Ace3/LibSharedMedia-3.0/lib.xml create mode 100644 Libs/Ace3/LibStub/LibStub.lua create mode 100644 Libs/Ace3/changelog.txt diff --git a/Libs/Ace3/Ace3.lua b/Libs/Ace3/Ace3.lua new file mode 100644 index 0000000..2fa8c09 --- /dev/null +++ b/Libs/Ace3/Ace3.lua @@ -0,0 +1,110 @@ + +-- This file is only there in standalone Ace3 and provides handy dev tool stuff I guess +-- for now only /rl to reload your UI :) +-- note the complete overkill use of AceAddon and console, ain't it cool? + +-- GLOBALS: next, loadstring, ReloadUI, geterrorhandler +-- GLOBALS: BINDING_HEADER_ACE3, BINDING_NAME_RELOADUI, Ace3, LibStub + +-- BINDINGs labels +BINDING_HEADER_ACE3 = "Ace3" +BINDING_NAME_RELOADUI = "ReloadUI" +-- + +local gui = LibStub("AceGUI-3.0") +local reg = LibStub("AceConfigRegistry-3.0") +local dialog = LibStub("AceConfigDialog-3.0") + +Ace3 = LibStub("AceAddon-3.0"):NewAddon("Ace3", "AceConsole-3.0") +local Ace3 = Ace3 + +local selectedgroup +local frame +local select +local status = {} +local configs = {} + +local function frameOnClose() + gui:Release(frame) + frame = nil +end + +local function RefreshConfigs() + for name in reg:IterateOptionsTables() do + configs[name] = name + end +end + +local function ConfigSelected(widget, event, value) + selectedgroup = value + dialog:Open(value, widget) +end + +local old_CloseSpecialWindows + +-- GLOBALS: CloseSpecialWindows, next +function Ace3:Open() + if not old_CloseSpecialWindows then + old_CloseSpecialWindows = CloseSpecialWindows + CloseSpecialWindows = function() + local found = old_CloseSpecialWindows() + if frame then + frame:Hide() + return true + end + return found + end + end + RefreshConfigs() + if next(configs) == nil then + self:Print("No Configs are Registered") + return + end + + if not frame then + frame = gui:Create("Frame") + frame:ReleaseChildren() + frame:SetTitle("Ace3 Options") + frame:SetLayout("FILL") + frame:SetCallback("OnClose", frameOnClose) + + select = gui:Create("DropdownGroup") + select:SetGroupList(configs) + select:SetCallback("OnGroupSelected", ConfigSelected) + frame:AddChild(select) + end + if not selectedgroup then + selectedgroup = next(configs) + end + select:SetGroup(selectedgroup) + frame:Show() +end + +local function RefreshOnUpdate(this) + select:SetGroup(selectedgroup) + this:SetScript("OnUpdate", nil) +end + +function Ace3:ConfigTableChanged(event, appName) + if selectedgroup == appName and frame then + frame.frame:SetScript("OnUpdate", RefreshOnUpdate) + end +end + +reg.RegisterCallback(Ace3, "ConfigTableChange", "ConfigTableChanged") + +function Ace3:PrintCmd(input) + input = input:trim():match("^(.-);*$") + local func, err = loadstring("LibStub(\"AceConsole-3.0\"):Print(" .. input .. ")") + if not func then + LibStub("AceConsole-3.0"):Print("Error: " .. err) + else + func() + end +end + +function Ace3:OnInitialize() + self:RegisterChatCommand("ace3", function() self:Open() end) + self:RegisterChatCommand("rl", function() ReloadUI() end) + self:RegisterChatCommand("print", "PrintCmd") +end diff --git a/Libs/Ace3/Ace3.toc b/Libs/Ace3/Ace3.toc new file mode 100644 index 0000000..a843bed --- /dev/null +++ b/Libs/Ace3/Ace3.toc @@ -0,0 +1,31 @@ +## Interface: 70000 +## X-Curse-Packaged-Version: Release-r1151 +## X-Curse-Project-Name: Ace3 +## X-Curse-Project-ID: ace3 +## X-Curse-Repository-ID: wow/ace3/mainline + +## Title: Lib: Ace3 +## Notes: AddOn development framework +## Author: Ace3 Development Team +## X-Website: http://www.wowace.com +## X-Category: Library +## X-License: Limited BSD + +LibStub\LibStub.lua +CallbackHandler-1.0\CallbackHandler-1.0.xml +AceAddon-3.0\AceAddon-3.0.xml +AceEvent-3.0\AceEvent-3.0.xml +AceTimer-3.0\AceTimer-3.0.xml +AceBucket-3.0\AceBucket-3.0.xml +AceHook-3.0\AceHook-3.0.xml +AceDB-3.0\AceDB-3.0.xml +AceDBOptions-3.0\AceDBOptions-3.0.xml +AceLocale-3.0\AceLocale-3.0.xml +AceConsole-3.0\AceConsole-3.0.xml +AceGUI-3.0\AceGUI-3.0.xml +AceConfig-3.0\AceConfig-3.0.xml +AceComm-3.0\AceComm-3.0.xml +AceTab-3.0\AceTab-3.0.xml +AceSerializer-3.0\AceSerializer-3.0.xml + +Ace3.lua diff --git a/Libs/Ace3/AceAddon-3.0/AceAddon-3.0.lua b/Libs/Ace3/AceAddon-3.0/AceAddon-3.0.lua new file mode 100644 index 0000000..a7f7279 --- /dev/null +++ b/Libs/Ace3/AceAddon-3.0/AceAddon-3.0.lua @@ -0,0 +1,674 @@ +--- **AceAddon-3.0** provides a template for creating addon objects. +-- It'll provide you with a set of callback functions that allow you to simplify the loading +-- process of your addon.\\ +-- Callbacks provided are:\\ +-- * **OnInitialize**, which is called directly after the addon is fully loaded. +-- * **OnEnable** which gets called during the PLAYER_LOGIN event, when most of the data provided by the game is already present. +-- * **OnDisable**, which is only called when your addon is manually being disabled. +-- @usage +-- -- A small (but complete) addon, that doesn't do anything, +-- -- but shows usage of the callbacks. +-- local MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon") +-- +-- function MyAddon:OnInitialize() +-- -- do init tasks here, like loading the Saved Variables, +-- -- or setting up slash commands. +-- end +-- +-- function MyAddon:OnEnable() +-- -- Do more initialization here, that really enables the use of your addon. +-- -- Register Events, Hook functions, Create Frames, Get information from +-- -- the game that wasn't available in OnInitialize +-- end +-- +-- function MyAddon:OnDisable() +-- -- Unhook, Unregister Events, Hide frames that you created. +-- -- You would probably only use an OnDisable if you want to +-- -- build a "standby" mode, or be able to toggle modules on/off. +-- end +-- @class file +-- @name AceAddon-3.0.lua +-- @release $Id: AceAddon-3.0.lua 1084 2013-04-27 20:14:11Z nevcairiel $ + +local MAJOR, MINOR = "AceAddon-3.0", 12 +local AceAddon, oldminor = LibStub:NewLibrary(MAJOR, MINOR) + +if not AceAddon then return end -- No Upgrade needed. + +AceAddon.frame = AceAddon.frame or CreateFrame("Frame", "AceAddon30Frame") -- Our very own frame +AceAddon.addons = AceAddon.addons or {} -- addons in general +AceAddon.statuses = AceAddon.statuses or {} -- statuses of addon. +AceAddon.initializequeue = AceAddon.initializequeue or {} -- addons that are new and not initialized +AceAddon.enablequeue = AceAddon.enablequeue or {} -- addons that are initialized and waiting to be enabled +AceAddon.embeds = AceAddon.embeds or setmetatable({}, {__index = function(tbl, key) tbl[key] = {} return tbl[key] end }) -- contains a list of libraries embedded in an addon + +-- Lua APIs +local tinsert, tconcat, tremove = table.insert, table.concat, table.remove +local fmt, tostring = string.format, tostring +local select, pairs, next, type, unpack = select, pairs, next, type, unpack +local loadstring, assert, error = loadstring, assert, error +local setmetatable, getmetatable, rawset, rawget = setmetatable, getmetatable, rawset, rawget + +-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded +-- List them here for Mikk's FindGlobals script +-- GLOBALS: LibStub, IsLoggedIn, geterrorhandler + +--[[ + xpcall safecall implementation +]] +local xpcall = xpcall + +local function errorhandler(err) + return geterrorhandler()(err) +end + +local function CreateDispatcher(argCount) + local code = [[ + local xpcall, eh = ... + local method, ARGS + local function call() return method(ARGS) end + + local function dispatch(func, ...) + method = func + if not method then return end + ARGS = ... + return xpcall(call, eh) + end + + return dispatch + ]] + + local ARGS = {} + for i = 1, argCount do ARGS[i] = "arg"..i end + code = code:gsub("ARGS", tconcat(ARGS, ", ")) + return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler) +end + +local Dispatchers = setmetatable({}, {__index=function(self, argCount) + local dispatcher = CreateDispatcher(argCount) + rawset(self, argCount, dispatcher) + return dispatcher +end}) +Dispatchers[0] = function(func) + return xpcall(func, errorhandler) +end + +local function safecall(func, ...) + -- we check to see if the func is passed is actually a function here and don't error when it isn't + -- this safecall is used for optional functions like OnInitialize OnEnable etc. When they are not + -- present execution should continue without hinderance + if type(func) == "function" then + return Dispatchers[select('#', ...)](func, ...) + end +end + +-- local functions that will be implemented further down +local Enable, Disable, EnableModule, DisableModule, Embed, NewModule, GetModule, GetName, SetDefaultModuleState, SetDefaultModuleLibraries, SetEnabledState, SetDefaultModulePrototype + +-- used in the addon metatable +local function addontostring( self ) return self.name end + +-- Check if the addon is queued for initialization +local function queuedForInitialization(addon) + for i = 1, #AceAddon.initializequeue do + if AceAddon.initializequeue[i] == addon then + return true + end + end + return false +end + +--- Create a new AceAddon-3.0 addon. +-- Any libraries you specified will be embeded, and the addon will be scheduled for +-- its OnInitialize and OnEnable callbacks. +-- The final addon object, with all libraries embeded, will be returned. +-- @paramsig [object ,]name[, lib, ...] +-- @param object Table to use as a base for the addon (optional) +-- @param name Name of the addon object to create +-- @param lib List of libraries to embed into the addon +-- @usage +-- -- Create a simple addon object +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon", "AceEvent-3.0") +-- +-- -- Create a Addon object based on the table of a frame +-- local MyFrame = CreateFrame("Frame") +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon(MyFrame, "MyAddon", "AceEvent-3.0") +function AceAddon:NewAddon(objectorname, ...) + local object,name + local i=1 + if type(objectorname)=="table" then + object=objectorname + name=... + i=2 + else + name=objectorname + end + if type(name)~="string" then + error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2) + end + if self.addons[name] then + error(("Usage: NewAddon([object,] name, [lib, lib, lib, ...]): 'name' - Addon '%s' already exists."):format(name), 2) + end + + object = object or {} + object.name = name + + local addonmeta = {} + local oldmeta = getmetatable(object) + if oldmeta then + for k, v in pairs(oldmeta) do addonmeta[k] = v end + end + addonmeta.__tostring = addontostring + + setmetatable( object, addonmeta ) + self.addons[name] = object + object.modules = {} + object.orderedModules = {} + object.defaultModuleLibraries = {} + Embed( object ) -- embed NewModule, GetModule methods + self:EmbedLibraries(object, select(i,...)) + + -- add to queue of addons to be initialized upon ADDON_LOADED + tinsert(self.initializequeue, object) + return object +end + + +--- Get the addon object by its name from the internal AceAddon registry. +-- Throws an error if the addon object cannot be found (except if silent is set). +-- @param name unique name of the addon object +-- @param silent if true, the addon is optional, silently return nil if its not found +-- @usage +-- -- Get the Addon +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +function AceAddon:GetAddon(name, silent) + if not silent and not self.addons[name] then + error(("Usage: GetAddon(name): 'name' - Cannot find an AceAddon '%s'."):format(tostring(name)), 2) + end + return self.addons[name] +end + +-- - Embed a list of libraries into the specified addon. +-- This function will try to embed all of the listed libraries into the addon +-- and error if a single one fails. +-- +-- **Note:** This function is for internal use by :NewAddon/:NewModule +-- @paramsig addon, [lib, ...] +-- @param addon addon object to embed the libs in +-- @param lib List of libraries to embed into the addon +function AceAddon:EmbedLibraries(addon, ...) + for i=1,select("#", ... ) do + local libname = select(i, ...) + self:EmbedLibrary(addon, libname, false, 4) + end +end + +-- - Embed a library into the addon object. +-- This function will check if the specified library is registered with LibStub +-- and if it has a :Embed function to call. It'll error if any of those conditions +-- fails. +-- +-- **Note:** This function is for internal use by :EmbedLibraries +-- @paramsig addon, libname[, silent[, offset]] +-- @param addon addon object to embed the library in +-- @param libname name of the library to embed +-- @param silent marks an embed to fail silently if the library doesn't exist (optional) +-- @param offset will push the error messages back to said offset, defaults to 2 (optional) +function AceAddon:EmbedLibrary(addon, libname, silent, offset) + local lib = LibStub:GetLibrary(libname, true) + if not lib and not silent then + error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Cannot find a library instance of %q."):format(tostring(libname)), offset or 2) + elseif lib and type(lib.Embed) == "function" then + lib:Embed(addon) + tinsert(self.embeds[addon], libname) + return true + elseif lib then + error(("Usage: EmbedLibrary(addon, libname, silent, offset): 'libname' - Library '%s' is not Embed capable"):format(libname), offset or 2) + end +end + +--- Return the specified module from an addon object. +-- Throws an error if the addon object cannot be found (except if silent is set) +-- @name //addon//:GetModule +-- @paramsig name[, silent] +-- @param name unique name of the module +-- @param silent if true, the module is optional, silently return nil if its not found (optional) +-- @usage +-- -- Get the Addon +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- -- Get the Module +-- MyModule = MyAddon:GetModule("MyModule") +function GetModule(self, name, silent) + if not self.modules[name] and not silent then + error(("Usage: GetModule(name, silent): 'name' - Cannot find module '%s'."):format(tostring(name)), 2) + end + return self.modules[name] +end + +local function IsModuleTrue(self) return true end + +--- Create a new module for the addon. +-- The new module can have its own embeded libraries and/or use a module prototype to be mixed into the module.\\ +-- A module has the same functionality as a real addon, it can have modules of its own, and has the same API as +-- an addon object. +-- @name //addon//:NewModule +-- @paramsig name[, prototype|lib[, lib, ...]] +-- @param name unique name of the module +-- @param prototype object to derive this module from, methods and values from this table will be mixed into the module (optional) +-- @param lib List of libraries to embed into the addon +-- @usage +-- -- Create a module with some embeded libraries +-- MyModule = MyAddon:NewModule("MyModule", "AceEvent-3.0", "AceHook-3.0") +-- +-- -- Create a module with a prototype +-- local prototype = { OnEnable = function(self) print("OnEnable called!") end } +-- MyModule = MyAddon:NewModule("MyModule", prototype, "AceEvent-3.0", "AceHook-3.0") +function NewModule(self, name, prototype, ...) + if type(name) ~= "string" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - string expected got '%s'."):format(type(name)), 2) end + if type(prototype) ~= "string" and type(prototype) ~= "table" and type(prototype) ~= "nil" then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'prototype' - table (prototype), string (lib) or nil expected got '%s'."):format(type(prototype)), 2) end + + if self.modules[name] then error(("Usage: NewModule(name, [prototype, [lib, lib, lib, ...]): 'name' - Module '%s' already exists."):format(name), 2) end + + -- modules are basically addons. We treat them as such. They will be added to the initializequeue properly as well. + -- NewModule can only be called after the parent addon is present thus the modules will be initialized after their parent is. + local module = AceAddon:NewAddon(fmt("%s_%s", self.name or tostring(self), name)) + + module.IsModule = IsModuleTrue + module:SetEnabledState(self.defaultModuleState) + module.moduleName = name + + if type(prototype) == "string" then + AceAddon:EmbedLibraries(module, prototype, ...) + else + AceAddon:EmbedLibraries(module, ...) + end + AceAddon:EmbedLibraries(module, unpack(self.defaultModuleLibraries)) + + if not prototype or type(prototype) == "string" then + prototype = self.defaultModulePrototype or nil + end + + if type(prototype) == "table" then + local mt = getmetatable(module) + mt.__index = prototype + setmetatable(module, mt) -- More of a Base class type feel. + end + + safecall(self.OnModuleCreated, self, module) -- Was in Ace2 and I think it could be a cool thing to have handy. + self.modules[name] = module + tinsert(self.orderedModules, module) + + return module +end + +--- Returns the real name of the addon or module, without any prefix. +-- @name //addon//:GetName +-- @paramsig +-- @usage +-- print(MyAddon:GetName()) +-- -- prints "MyAddon" +function GetName(self) + return self.moduleName or self.name +end + +--- Enables the Addon, if possible, return true or false depending on success. +-- This internally calls AceAddon:EnableAddon(), thus dispatching a OnEnable callback +-- and enabling all modules of the addon (unless explicitly disabled).\\ +-- :Enable() also sets the internal `enableState` variable to true +-- @name //addon//:Enable +-- @paramsig +-- @usage +-- -- Enable MyModule +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyModule = MyAddon:GetModule("MyModule") +-- MyModule:Enable() +function Enable(self) + self:SetEnabledState(true) + + -- nevcairiel 2013-04-27: don't enable an addon/module if its queued for init still + -- it'll be enabled after the init process + if not queuedForInitialization(self) then + return AceAddon:EnableAddon(self) + end +end + +--- Disables the Addon, if possible, return true or false depending on success. +-- This internally calls AceAddon:DisableAddon(), thus dispatching a OnDisable callback +-- and disabling all modules of the addon.\\ +-- :Disable() also sets the internal `enableState` variable to false +-- @name //addon//:Disable +-- @paramsig +-- @usage +-- -- Disable MyAddon +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyAddon:Disable() +function Disable(self) + self:SetEnabledState(false) + return AceAddon:DisableAddon(self) +end + +--- Enables the Module, if possible, return true or false depending on success. +-- Short-hand function that retrieves the module via `:GetModule` and calls `:Enable` on the module object. +-- @name //addon//:EnableModule +-- @paramsig name +-- @usage +-- -- Enable MyModule using :GetModule +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyModule = MyAddon:GetModule("MyModule") +-- MyModule:Enable() +-- +-- -- Enable MyModule using the short-hand +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyAddon:EnableModule("MyModule") +function EnableModule(self, name) + local module = self:GetModule( name ) + return module:Enable() +end + +--- Disables the Module, if possible, return true or false depending on success. +-- Short-hand function that retrieves the module via `:GetModule` and calls `:Disable` on the module object. +-- @name //addon//:DisableModule +-- @paramsig name +-- @usage +-- -- Disable MyModule using :GetModule +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyModule = MyAddon:GetModule("MyModule") +-- MyModule:Disable() +-- +-- -- Disable MyModule using the short-hand +-- MyAddon = LibStub("AceAddon-3.0"):GetAddon("MyAddon") +-- MyAddon:DisableModule("MyModule") +function DisableModule(self, name) + local module = self:GetModule( name ) + return module:Disable() +end + +--- Set the default libraries to be mixed into all modules created by this object. +-- Note that you can only change the default module libraries before any module is created. +-- @name //addon//:SetDefaultModuleLibraries +-- @paramsig lib[, lib, ...] +-- @param lib List of libraries to embed into the addon +-- @usage +-- -- Create the addon object +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon") +-- -- Configure default libraries for modules (all modules need AceEvent-3.0) +-- MyAddon:SetDefaultModuleLibraries("AceEvent-3.0") +-- -- Create a module +-- MyModule = MyAddon:NewModule("MyModule") +function SetDefaultModuleLibraries(self, ...) + if next(self.modules) then + error("Usage: SetDefaultModuleLibraries(...): cannot change the module defaults after a module has been registered.", 2) + end + self.defaultModuleLibraries = {...} +end + +--- Set the default state in which new modules are being created. +-- Note that you can only change the default state before any module is created. +-- @name //addon//:SetDefaultModuleState +-- @paramsig state +-- @param state Default state for new modules, true for enabled, false for disabled +-- @usage +-- -- Create the addon object +-- MyAddon = LibStub("AceAddon-3.0"):NewAddon("MyAddon") +-- -- Set the default state to "disabled" +-- MyAddon:SetDefaultModuleState(false) +-- -- Create a module and explicilty enable it +-- MyModule = MyAddon:NewModule("MyModule") +-- MyModule:Enable() +function SetDefaultModuleState(self, state) + if next(self.modules) then + error("Usage: SetDefaultModuleState(state): cannot change the module defaults after a module has been registered.", 2) + end + self.defaultModuleState = state +end + +--- Set the default prototype to use for new modules on creation. +-- Note that you can only change the default prototype before any module is created. +-- @name //addon//:SetDefaultModulePrototype +-- @paramsig prototype +-- @param prototype Default prototype for the new modules (table) +-- @usage +-- -- Define a prototype +-- local prototype = { OnEnable = function(self) print("OnEnable called!") end } +-- -- Set the default prototype +-- MyAddon:SetDefaultModulePrototype(prototype) +-- -- Create a module and explicitly Enable it +-- MyModule = MyAddon:NewModule("MyModule") +-- MyModule:Enable() +-- -- should print "OnEnable called!" now +-- @see NewModule +function SetDefaultModulePrototype(self, prototype) + if next(self.modules) then + error("Usage: SetDefaultModulePrototype(prototype): cannot change the module defaults after a module has been registered.", 2) + end + if type(prototype) ~= "table" then + error(("Usage: SetDefaultModulePrototype(prototype): 'prototype' - table expected got '%s'."):format(type(prototype)), 2) + end + self.defaultModulePrototype = prototype +end + +--- Set the state of an addon or module +-- This should only be called before any enabling actually happend, e.g. in/before OnInitialize. +-- @name //addon//:SetEnabledState +-- @paramsig state +-- @param state the state of an addon or module (enabled=true, disabled=false) +function SetEnabledState(self, state) + self.enabledState = state +end + + +--- Return an iterator of all modules associated to the addon. +-- @name //addon//:IterateModules +-- @paramsig +-- @usage +-- -- Enable all modules +-- for name, module in MyAddon:IterateModules() do +-- module:Enable() +-- end +local function IterateModules(self) return pairs(self.modules) end + +-- Returns an iterator of all embeds in the addon +-- @name //addon//:IterateEmbeds +-- @paramsig +local function IterateEmbeds(self) return pairs(AceAddon.embeds[self]) end + +--- Query the enabledState of an addon. +-- @name //addon//:IsEnabled +-- @paramsig +-- @usage +-- if MyAddon:IsEnabled() then +-- MyAddon:Disable() +-- end +local function IsEnabled(self) return self.enabledState end +local mixins = { + NewModule = NewModule, + GetModule = GetModule, + Enable = Enable, + Disable = Disable, + EnableModule = EnableModule, + DisableModule = DisableModule, + IsEnabled = IsEnabled, + SetDefaultModuleLibraries = SetDefaultModuleLibraries, + SetDefaultModuleState = SetDefaultModuleState, + SetDefaultModulePrototype = SetDefaultModulePrototype, + SetEnabledState = SetEnabledState, + IterateModules = IterateModules, + IterateEmbeds = IterateEmbeds, + GetName = GetName, +} +local function IsModule(self) return false end +local pmixins = { + defaultModuleState = true, + enabledState = true, + IsModule = IsModule, +} +-- Embed( target ) +-- target (object) - target object to embed aceaddon in +-- +-- this is a local function specifically since it's meant to be only called internally +function Embed(target, skipPMixins) + for k, v in pairs(mixins) do + target[k] = v + end + if not skipPMixins then + for k, v in pairs(pmixins) do + target[k] = target[k] or v + end + end +end + + +-- - Initialize the addon after creation. +-- This function is only used internally during the ADDON_LOADED event +-- It will call the **OnInitialize** function on the addon object (if present), +-- and the **OnEmbedInitialize** function on all embeded libraries. +-- +-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing. +-- @param addon addon object to intialize +function AceAddon:InitializeAddon(addon) + safecall(addon.OnInitialize, addon) + + local embeds = self.embeds[addon] + for i = 1, #embeds do + local lib = LibStub:GetLibrary(embeds[i], true) + if lib then safecall(lib.OnEmbedInitialize, lib, addon) end + end + + -- we don't call InitializeAddon on modules specifically, this is handled + -- from the event handler and only done _once_ +end + +-- - Enable the addon after creation. +-- Note: This function is only used internally during the PLAYER_LOGIN event, or during ADDON_LOADED, +-- if IsLoggedIn() already returns true at that point, e.g. for LoD Addons. +-- It will call the **OnEnable** function on the addon object (if present), +-- and the **OnEmbedEnable** function on all embeded libraries.\\ +-- This function does not toggle the enable state of the addon itself, and will return early if the addon is disabled. +-- +-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing. +-- Use :Enable on the addon itself instead. +-- @param addon addon object to enable +function AceAddon:EnableAddon(addon) + if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end + if self.statuses[addon.name] or not addon.enabledState then return false end + + -- set the statuses first, before calling the OnEnable. this allows for Disabling of the addon in OnEnable. + self.statuses[addon.name] = true + + safecall(addon.OnEnable, addon) + + -- make sure we're still enabled before continueing + if self.statuses[addon.name] then + local embeds = self.embeds[addon] + for i = 1, #embeds do + local lib = LibStub:GetLibrary(embeds[i], true) + if lib then safecall(lib.OnEmbedEnable, lib, addon) end + end + + -- enable possible modules. + local modules = addon.orderedModules + for i = 1, #modules do + self:EnableAddon(modules[i]) + end + end + return self.statuses[addon.name] -- return true if we're disabled +end + +-- - Disable the addon +-- Note: This function is only used internally. +-- It will call the **OnDisable** function on the addon object (if present), +-- and the **OnEmbedDisable** function on all embeded libraries.\\ +-- This function does not toggle the enable state of the addon itself, and will return early if the addon is still enabled. +-- +-- **Note:** Do not call this function manually, unless you're absolutely sure that you know what you are doing. +-- Use :Disable on the addon itself instead. +-- @param addon addon object to enable +function AceAddon:DisableAddon(addon) + if type(addon) == "string" then addon = AceAddon:GetAddon(addon) end + if not self.statuses[addon.name] then return false end + + -- set statuses first before calling OnDisable, this allows for aborting the disable in OnDisable. + self.statuses[addon.name] = false + + safecall( addon.OnDisable, addon ) + + -- make sure we're still disabling... + if not self.statuses[addon.name] then + local embeds = self.embeds[addon] + for i = 1, #embeds do + local lib = LibStub:GetLibrary(embeds[i], true) + if lib then safecall(lib.OnEmbedDisable, lib, addon) end + end + -- disable possible modules. + local modules = addon.orderedModules + for i = 1, #modules do + self:DisableAddon(modules[i]) + end + end + + return not self.statuses[addon.name] -- return true if we're disabled +end + +--- Get an iterator over all registered addons. +-- @usage +-- -- Print a list of all installed AceAddon's +-- for name, addon in AceAddon:IterateAddons() do +-- print("Addon: " .. name) +-- end +function AceAddon:IterateAddons() return pairs(self.addons) end + +--- Get an iterator over the internal status registry. +-- @usage +-- -- Print a list of all enabled addons +-- for name, status in AceAddon:IterateAddonStatus() do +-- if status then +-- print("EnabledAddon: " .. name) +-- end +-- end +function AceAddon:IterateAddonStatus() return pairs(self.statuses) end + +-- Following Iterators are deprecated, and their addon specific versions should be used +-- e.g. addon:IterateEmbeds() instead of :IterateEmbedsOnAddon(addon) +function AceAddon:IterateEmbedsOnAddon(addon) return pairs(self.embeds[addon]) end +function AceAddon:IterateModulesOfAddon(addon) return pairs(addon.modules) end + +-- Event Handling +local function onEvent(this, event, arg1) + -- 2011-08-17 nevcairiel - ignore the load event of Blizzard_DebugTools, so a potential startup error isn't swallowed up + if (event == "ADDON_LOADED" and arg1 ~= "Blizzard_DebugTools") or event == "PLAYER_LOGIN" then + -- if a addon loads another addon, recursion could happen here, so we need to validate the table on every iteration + while(#AceAddon.initializequeue > 0) do + local addon = tremove(AceAddon.initializequeue, 1) + -- this might be an issue with recursion - TODO: validate + if event == "ADDON_LOADED" then addon.baseName = arg1 end + AceAddon:InitializeAddon(addon) + tinsert(AceAddon.enablequeue, addon) + end + + if IsLoggedIn() then + while(#AceAddon.enablequeue > 0) do + local addon = tremove(AceAddon.enablequeue, 1) + AceAddon:EnableAddon(addon) + end + end + end +end + +AceAddon.frame:RegisterEvent("ADDON_LOADED") +AceAddon.frame:RegisterEvent("PLAYER_LOGIN") +AceAddon.frame:SetScript("OnEvent", onEvent) + +-- upgrade embeded +for name, addon in pairs(AceAddon.addons) do + Embed(addon, true) +end + +-- 2010-10-27 nevcairiel - add new "orderedModules" table +if oldminor and oldminor < 10 then + for name, addon in pairs(AceAddon.addons) do + addon.orderedModules = {} + for module_name, module in pairs(addon.modules) do + tinsert(addon.orderedModules, module) + end + end +end diff --git a/Libs/Ace3/AceAddon-3.0/AceAddon-3.0.xml b/Libs/Ace3/AceAddon-3.0/AceAddon-3.0.xml new file mode 100644 index 0000000..e6ad639 --- /dev/null +++ b/Libs/Ace3/AceAddon-3.0/AceAddon-3.0.xml @@ -0,0 +1,4 @@ + +