Skip to content

Commit 69e6e0b

Browse files
committed
UnitTestSuite: make testing automation scripts and module functions not exposed by its API possible
1 parent 6986d85 commit 69e6e0b

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

modules/DependencyControl.moon

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,19 +442,24 @@ class DependencyControl
442442
reqVersion = reqVersion and " (v#{reqVersion})" or ""
443443
return msgs.formatVersionErrorTemplate.missing\format name, reqVersion, url, reason
444444

445-
loadTests: (ref) =>
445+
registerTests: (...) =>
446446
-- load external tests
447447
haveTests, tests = pcall require, "DepUnit.#{@type}.#{@namespace}"
448448

449-
if haveTests
449+
if haveTests and not @testsLoaded
450450
@tests, tests.name = tests, @name
451-
@tests\import ref, @requireModules!
451+
modules = table.pack @requireModules!
452+
if @moduleName
453+
@tests\import @ref, modules, ...
454+
else @tests\import modules, ...
455+
452456
@tests\registerMacros!
457+
@testsLoaded = true
453458

454-
register: (selfRef) =>
459+
register: (selfRef, ...) =>
455460
-- replace dummy refs with real refs to own module
456-
@loadTests selfRef
457461
@ref.__index, @ref, LOADED_MODULES[@moduleName] = selfRef, selfRef, selfRef
462+
@registerTests selfRef, ...
458463
return selfRef
459464

460465
registerMacro: (name=@name, description=@description, process, validate, isActive, useSubmenu) =>

modules/DependencyControl/UnitTestSuite.moon

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,13 @@ class UnitTestSuite
760760
--- Creates a complete unit test suite for a module or automation script.
761761
-- Using this constructor will create all test classes and tests automatically.
762762
-- @tparam string namespace the namespace of the module or automation script to test.
763-
-- @tparam {[string] = table, ...}|function(module1, module2, ...) args To create a UnitTest suite,
763+
-- @tparam {[string] = table, ...}|function(self, dependencies, args...) args To create a UnitTest suite,
764764
-- you must supply a hashtable of @{UnitTestClass} constructor tables by name. You can either do so directly,
765-
-- or wrap it in a function that takes the modules required by the tested script/module as inputs.
765+
-- or wrap it in a function that takes a number of arguments depending on how the tests are registered:
766+
-- * self: the module being testsed (skipped for automation scripts)
767+
-- * dependencies: a numerically keyed table of all the modules required by the tested script/module (in order)
768+
-- * args: any additional arguments passed into the @{DependencyControl\registerTests} function.
769+
-- Doing so is required to test automation scripts as well as module functions not exposed by its API.
766770
-- indexes starting with "_" have special meaning and are not added as regular tests:
767771
-- * _order: alternative syntax to the order parameter (see below)
768772
-- @tparam [opt=nil (unordered)] {string, ...} An list of test class names in the desired execution order.

0 commit comments

Comments
 (0)