|
| 1 | +Class UnitTest.TestCoverage.Unit.TestCoverageList Extends %UnitTest.TestCase |
| 2 | +{ |
| 3 | + |
| 4 | +/// helper function to find the samplecovlist.list's path |
| 5 | +ClassMethod FindCoverageList(directory As %String = "") As %String |
| 6 | +{ |
| 7 | + set stmt = ##class(%SQL.Statement).%New() |
| 8 | + set status = stmt.%PrepareClassQuery("%File", "FileSet") |
| 9 | + if $$$ISERR(status) {write "%Prepare failed:" do $SYSTEM.Status.DisplayError(status) quit} |
| 10 | + |
| 11 | + set rset = stmt.%Execute(directory) |
| 12 | + if (rset.%SQLCODE '= 0) {write "%Execute failed:", !, "SQLCODE ", rset.%SQLCODE, ": ", rset.%Message quit} |
| 13 | + |
| 14 | + while rset.%Next() |
| 15 | + { |
| 16 | + set name = rset.%Get("Name") |
| 17 | + set type = rset.%Get("Type") |
| 18 | + |
| 19 | + if (type = "F") { |
| 20 | + do ##class(%File).Deconstruct(name, .dirs) |
| 21 | + if (dirs(dirs) = "samplecovlist.list") { |
| 22 | + return name |
| 23 | + } |
| 24 | + } elseif (type = "D"){ |
| 25 | + do ..FindCoverageList(name) |
| 26 | + } |
| 27 | + } |
| 28 | + if (rset.%SQLCODE < 0) {write "%Next failed:", !, "SQLCODE ", rset.%SQLCODE, ": ", rset.%Message quit} |
| 29 | +} |
| 30 | + |
| 31 | +Method TestGettingCoverageList() |
| 32 | +{ |
| 33 | + set tFile = ..FindCoverageList(^UnitTestRoot) // finds the samplecovlist.list |
| 34 | + do ##class(TestCoverage.Manager).GetCoverageTargetsForFile(tFile, .tTargetArray) |
| 35 | + |
| 36 | + Set CorrectCoverageTargets("CLS", "TestCoverage.Data.CodeSubUnit") = "" |
| 37 | + Set CorrectCoverageTargets("CLS", "TestCoverage.Data.CodeSubUnit.Method") = "" |
| 38 | + Set CorrectCoverageTargets("CLS","TestCoverage.Data.CodeUnit")="" |
| 39 | + Set CorrectCoverageTargets("CLS","TestCoverage.Data.CodeUnitMap")="" |
| 40 | + Set CorrectCoverageTargets("CLS","TestCoverage.Data.Coverage")="" |
| 41 | + Set CorrectCoverageTargets("CLS","TestCoverage.Data.Run")="" |
| 42 | + Set CorrectCoverageTargets("CLS","TestCoverage.Manager")="" |
| 43 | + Set CorrectCoverageTargets("MAC","UnitTest.TestCoverage.Unit.CodeUnit.G1")="" |
| 44 | + Set CorrectCoverageTargets("MAC","UnitTest.TestCoverage.Unit.sampleRoutine")="" |
| 45 | + Do $$$AssertEquals(..CompareArrays(.tTargetArray, .CorrectCoverageTargets, .pMessage), 1, "tTargetarray equals CorrectCoverageTargets") |
| 46 | + Do $$$LogMessage(pMessage) |
| 47 | +} |
| 48 | + |
| 49 | +/// Taken from Tim's Developer Community post |
| 50 | +/// Returns true if arrays <var>first</var> and <var>second</var> have all the same subscripts and all |
| 51 | +/// the same values at those subscripts. <br /> |
| 52 | +/// If <var>first</var> and <var>second</var> both happen to be either undefined or unsubscripted variables, |
| 53 | +/// returns true if they're both undefined or have the same value.<br /> |
| 54 | +/// <var>pMessage</var> has details of the first difference found, if any. |
| 55 | +ClassMethod CompareArrays(ByRef first, ByRef second, Output pMessage) As %Boolean [ ProcedureBlock = 0 ] |
| 56 | +{ |
| 57 | + New tEqual,tRef1,tRef2,tRef1Data,tRef1Value,tRef2Data,tRef2Value |
| 58 | + |
| 59 | + Set pMessage = "" |
| 60 | + Set tEqual = 1 |
| 61 | + Set tRef1 = "first" |
| 62 | + Set tRef2 = "second" |
| 63 | + While (tRef1 '= "") || (tRef2 '= "") { |
| 64 | + #; See if the subscript is the same for both arrays. |
| 65 | + #; If not, one of them has a subscript the other doesn't, and they're not equal. |
| 66 | + If ($Piece(tRef1,"first",2) '= $Piece(tRef2,"second",2)) { |
| 67 | + Set tEqual = 0 |
| 68 | + Set pMessage = "Different subscripts encountered by $Query: "_ |
| 69 | + $Case(tRef1,"":"<end>",:tRef1)_"; "_$Case(tRef2,"":"<end>",:tRef2) |
| 70 | + Quit |
| 71 | + } |
| 72 | + |
| 73 | + Kill tRef1Value,tRef2Value |
| 74 | + Set tRef1Data = $Data(@tRef1,tRef1Value) |
| 75 | + Set tRef2Data = $Data(@tRef2,tRef2Value) |
| 76 | + #; See if the $Data values are the same for the two. |
| 77 | + #; This is really only useful to detect if one of the arrays is undefined on the first pass; |
| 78 | + #; $Query only returns subscripts with data. |
| 79 | + #; This will catch only one being defined, or one being an array and |
| 80 | + #; the other being a regular variable. |
| 81 | + If (tRef1Data '= tRef2Data) { |
| 82 | + Set tEqual = 0 |
| 83 | + Set pMessage = "$Data("_tRef1_")="_tRef1Data_"; $Data("_tRef2_")="_tRef2Data |
| 84 | + Quit |
| 85 | + } ElseIf (tRef1Data#2) && (tRef2Data#2) { |
| 86 | + #; See if the value at the subscript is the same for both arrays. |
| 87 | + #; If not, they're not equal. |
| 88 | + If (tRef1Value '= tRef2Value) { |
| 89 | + Set tEqual = 0 |
| 90 | + Set pMessage = tRef1_"="_@tRef1_"; "_tRef2_"="_@tRef2 |
| 91 | + Quit |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + Set tRef1 = $Query(@tRef1) |
| 96 | + Set tRef2 = $Query(@tRef2) |
| 97 | + } |
| 98 | + Quit tEqual |
| 99 | +} |
| 100 | + |
| 101 | +} |
0 commit comments