Skip to content

Commit 4455ecd

Browse files
committed
enhance: allow CoverageClasses/Routines to be %DynamicArray
1 parent 9c2c65a commit 4455ecd

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ Generally speaking, set `^UnitTestRoot`, and then call `##class(TestCoverage.Man
6767
The "userparam" argument can be used to pass information about code coverage data collection. For example:
6868

6969
```
70-
Set tCoverageParams("CoverageClasses") = <$ListBuild list of class names for which code coverage data should be collected>
71-
Set tCoverageParams("CoverageRoutines") = <$ListBuild list of routine names for which code coverage data should be collected>
70+
Set tCoverageParams("CoverageClasses") = <$ListBuild list or %DynamicArray of class names for which code coverage data should be collected>
71+
Set tCoverageParams("CoverageRoutines") = <$ListBuild list or %DynamicArray of routine names for which code coverage data should be collected>
7272
Set tCoverageParams("CoverageDetail") = <0 to track code coverage overall; 1 to track it per test suite (the default); 2 to track it per test class; 3 to track it per test method.>
7373
Do ##class(TestCoverage.Manager).RunTest(,,.tCoverageParams)
7474
```

cls/TestCoverage/Manager.cls

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ Property Monitor As TestCoverage.Utils.LineByLineMonitor [ InitialExpression = {
6767
/// <ul>
6868
/// <li><var>pPackage</var> has the top-level package containing all the unit test classes to run. These must already be loaded.</li>
6969
/// <li><var>pLogFile</var> (optional) may specify a file to log all output to.</li>
70-
/// <li><var>pCoverageClasses</var> (optional) has a $ListBuild list of class names within which to track code coverage. By default, none are tracked.</li>
71-
/// <li><var>pCoverageRoutines</var> (optional) has a $ListBuild list of routine names within which to track code coverage. By default, none are tracked.</li>
70+
/// <li><var>pCoverageClasses</var> (optional) has a $ListBuild list or %DynamicArray of class names within which to track code coverage. By default, none are tracked.</li>
71+
/// <li><var>pCoverageRoutines</var> (optional) has a $ListBuild list or %DynamicArray of routine names within which to track code coverage. By default, none are tracked.</li>
7272
/// <li><var>pCoverageLevel</var> (optional) is 0 to track code coverage overall; 1 to track it per test suite (the default); 2 to track it per test class; 3 to track it per test method.
7373
/// Note that overall tracking is always available; more granular tracking requires more time and disk space.</li>
7474
/// <li><var>pLogIndex</var> (optional) allows for aggregation of code coverage results across unit test runs. To use this, get it back as output from the first test run, then pass it to the next.</li>
@@ -78,7 +78,7 @@ Property Monitor As TestCoverage.Utils.LineByLineMonitor [ InitialExpression = {
7878
/// </ul>
7979
/// Granular data is stored in <class>TestCoverage.Data.Coverage</class>; aggregated data is stored per class in <class>TestCoverage.Data.Aggregate.ByCodeUnit</class> and for the whole run in <class>TestCoverage.Data.Aggregate.ByRun</class>.
8080
/// @API.Method
81-
ClassMethod RunAllTests(pPackage As %String = "", pLogFile As %String = "", pCoverageClasses As %List = "", pCoverageRoutines As %List = "", pCoverageLevel As %Integer = 1, ByRef pLogIndex As %Integer, pSourceNamespace As %String = {$Namespace}, pPIDList = {$ListBuild($Job)}, pTiming As %Boolean = 0) As %Status
81+
ClassMethod RunAllTests(pPackage As %String = "", pLogFile As %String = "", pCoverageClasses As %List = "", pCoverageRoutines As %List = "", pCoverageLevel As %Integer = 1, ByRef pLogIndex As %Integer, pSourceNamespace As %String = {$NAMESPACE}, pPIDList = {$LISTBUILD($JOB)}, pTiming As %Boolean = 0) As %Status
8282
{
8383
#dim tUnitTestManager As TestCoverage.Manager
8484
Set tSuccess = 1
@@ -94,8 +94,8 @@ ClassMethod RunAllTests(pPackage As %String = "", pLogFile As %String = "", pCov
9494
Set tTestSuite = $Replace(pPackage,"/",".")
9595
Set tSpec = "/noload/nodelete"
9696
Merge tCoverageParams("LogIndex") = pLogIndex // Set only if defined.
97-
Set tCoverageParams("CoverageClasses") = pCoverageClasses
98-
Set tCoverageParams("CoverageRoutines") = pCoverageRoutines
97+
Set tCoverageParams("CoverageClasses") = $SELECT($CLASSNAME(pCoverageClasses) = "%Library.DynamicArray":..ArrayToList(pCoverageClasses), 1:pCoverageClasses)
98+
Set tCoverageParams("CoverageRoutines") = $SELECT($CLASSNAME(pCoverageRoutines) = "%Library.DynamicArray":..ArrayToList(pCoverageRoutines), 1:pCoverageRoutines)
9999
Set tCoverageParams("CoverageDetail") = pCoverageLevel
100100
Set tCoverageParams("SourceNamespace") = pSourceNamespace
101101
Set tCoverageParams("ProcessIDs") = pPIDList
@@ -129,6 +129,16 @@ ClassMethod RunAllTests(pPackage As %String = "", pLogFile As %String = "", pCov
129129
Quit $Select(tSuccess:1,1:$$$ERROR($$$GeneralError,"One or more errors occurred in unit tests."))
130130
}
131131

132+
ClassMethod ArrayToList(pDynamicArray As %DynamicArray) As %List
133+
{
134+
Set tList = ""
135+
Set tIter = pDynamicArray.%GetIterator()
136+
While tIter.GetNext(, .value) {
137+
Set tList = tList _ $LISTBUILD(value)
138+
}
139+
Quit tList
140+
}
141+
132142
Method SetCoverageTargets(pClasses As %List = "", pRoutines As %List = "", pInit As %Boolean = 0) [ Private ]
133143
{
134144
Set tList = "", tPtr = 0

0 commit comments

Comments
 (0)