Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [4.0.1] - 2024-08-09

### Fixed
- #45: Fixed Python line 0 tracking for 2024.2
- #46: Fix for bug caused by UpdateComplexity calling GetCurrentByName unnecessarily and causing dependency issues
- #47: Fixed mapping issue caused by empty lines at top of Python method not showing up in compiled Python

## [4.0.0] - 2024-08-01

Expand Down
33 changes: 26 additions & 7 deletions cls/TestCoverage/Data/CodeUnit.cls
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ Property LineIsPython As array Of %Boolean;
/// Set to true if this class/routine is generated
Property Generated As %Boolean [ InitialExpression = 0 ];

///
/// If the CodeUnit has changed since we last updated it, used to see if we need to call UpdateComplexity
Property OutdatedComplexity As %Boolean [ InitialExpression = 1 ];

/// Methods, branches, etc. within this unit of code.
Relationship SubUnits As TestCoverage.Data.CodeSubUnit [ Cardinality = children, Inverse = Parent ];

Expand Down Expand Up @@ -87,6 +89,9 @@ ClassMethod GetCurrentByName(pInternalName As %String, pSourceNamespace As %Stri
If (tUpdatedHash '= tKnownHash) {
//Clear out old data and flag the need for an update.
Set tNeedsUpdate = 1
If $IsObject($Get(tMapToUnit)) {
set tMapToUnit.OutdatedComplexity = 1
}
&sql(delete from TestCoverage_Data.CodeUnitMap where ToHash = :tKnownHash)
If (SQLCODE < 0) {
Throw ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE,%msg)
Expand Down Expand Up @@ -399,17 +404,27 @@ Method UpdateSourceMap(pSourceNamespace As %String, ByRef pCache) As %Status
Set tMethodStart = ..MethodMap.GetAt(tMethod)
Set tMethodEnd = ..MethodEndMap.GetAt(tMethod)
Set tMethodName = tMethod

// tFullMap(py/int Line Number, absolute) = $lb("CLS", class name, method name, CLS/mac start line (relative to method), CLS/mac end line (relative to method))
Set tFullMap(tMethodStart) = $lb("CLS", tClass,tMethodName, -1, -1) ; -1 because the class
; definition doesn't have the +1 offset from the {

// there's a strange edge case where if the python method in the .CLS file starts with spaces, that's not captured in the Python compiled code
// so we have to find how many empty lines there are at the beginning
Set tEmptyLines = 0
while ($zstrip( pCLSCodeUnit.Lines.GetAt(tCLSMethodNum + 1 + tEmptyLines + 1), "<>W") = "") {
Set tEmptyLines = tEmptyLines + 1
}

For i = tMethodStart+1:1:tMethodEnd {
Set tClassLineNum = i-tMethodStart
Set tFullMap(i) = $lb("CLS", tClass,tMethodName, tClassLineNum, tClassLineNum)
Set tFullMap(i) = $lb("CLS", tClass,tMethodName, tClassLineNum+tEmptyLines, tClassLineNum+tEmptyLines)

// extra check to make sure that the lines we're mapping between are the same as expected
Set tClassLineCode = $zstrip(pCLSCodeUnit.Lines.GetAt(tCLSMethodNum + tClassLineNum + 1), "<>W")
Set tClassLineCode = $zstrip(pCLSCodeUnit.Lines.GetAt(tCLSMethodNum + 1 + tEmptyLines + tClassLineNum), "<>W")
Set tPyLineCode = $zstrip(..Lines.GetAt(i), "<>W")
if (tPyLineCode '= tClassLineCode) {
Set tSC = $$$ERROR($$$GeneralError,"Compiled .py code doesn't match .CLS python code at line " _ $char(10,13) _ tPyLineCode)
$$$ThrowStatus($$$ERROR($$$GeneralError,"Compiled .py code doesn't match .CLS python code at line " _ $char(10,13) _ tPyLineCode))
}
}
Do ..MethodMap.GetNext(.tMethod)
Expand Down Expand Up @@ -521,9 +536,10 @@ Method UpdateSourceMap(pSourceNamespace As %String, ByRef pCache) As %Status
}
}

// Update cyclomatic complexity for methods in the linked class
// Update cyclomatic complexity for methods in the linked class if we don't already have the newest version
Set tClass = $Order(tCodeUnits("CLS",""),1,tClassCodeUnit)
If $IsObject($Get(tClassCodeUnit)) {
If ($IsObject($Get(tClassCodeUnit)) && (tClassCodeUnit.OutdatedComplexity)){
set tClassCodeUnit.OutdatedComplexity = 0
$$$ThrowOnError(tClassCodeUnit.UpdateComplexity())
}
} Catch e {
Expand Down Expand Up @@ -589,7 +605,7 @@ Method GetMethodOffset(pAbsoluteLine As %Integer, Output pMethod As %String, Out
{
}

ClassMethod GetCurrentHash(pName As %String, pType As %String, Output pHash As %String, Output pCodeArray As %String, Output pCache) As %Status [ Private ]
ClassMethod GetCurrentHash(pName As %String, pType As %String, Output pHash As %String, Output pCodeArray As %String, Output pCache) As %Status
{
Set tSC = $$$OK
Try {
Expand Down Expand Up @@ -690,6 +706,9 @@ Storage Default
<Value name="5">
<Value>Generated</Value>
</Value>
<Value name="6">
<Value>OutdatedComplexity</Value>
</Value>
</Data>
<Data name="LineIsPython">
<Attribute>LineIsPython</Attribute>
Expand Down
9 changes: 4 additions & 5 deletions cls/TestCoverage/Manager.cls
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,11 @@ ClassMethod OnBeforeAllTests(manager As TestCoverage.Manager, dir As %String, By
Set tSC = manager.UpdateCoverageTargetsForTestDirectory(dir)
$$$ThrowOnError(tSC)
}

if (manager.ListenerManager) {
set tObj = {"message": "Starting tests"}
Do manager.ListenerManager.BroadCastToAll(tObj)
}
If (manager.CoverageDetail = 0) {
if (manager.ListenerManager) {
set tObj = {"message": "Starting tests"}
Do manager.ListenerManager.BroadCastToAll(tObj)
}
Set tSC = manager.StartCoverageTracking()
$$$ThrowOnError(tSC)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ Method TestCodeUnitCreation()
Set tCodeGeneratorLine = tClsCodeUnit.MethodMap.GetAt("SampleCodeGenerator")
Set tNormalMethodLine = tClsCodeUnit.MethodMap.GetAt("SampleNormalMethod")
Set tPythonMethodLine = tClsCodeUnit.MethodMap.GetAt("SamplePythonMethod")
set tPythonWeirdSpacingMethodLine = tClsCodeUnit.MethodMap.GetAt("PythonWeirdSpacing")

Do $$$AssertNotEquals(tConstantReturnValueLine,"")
Do $$$AssertNotEquals(tCodeGeneratorLine,"")
Do $$$AssertNotEquals(tNormalMethodLine,"")
Do $$$AssertNotEquals(tPythonMethodLine,"")
Do $$$AssertNotEquals(tPythonWeirdSpacingMethodLine,"")

// test if LineIsPython is working properly
Do $$$AssertEquals(tClsCodeUnit.LineIsPython.GetAt(tPythonMethodLine+2), 1)
Expand All @@ -69,6 +71,10 @@ Method TestCodeUnitCreation()
Set tTestLines(tNormalMethodLine+3) = $ListBuild("SampleNormalMethod+2",,,tIntCodeUnit.Hash,tIntCodeUnit.MethodMap.GetAt(methodLabel)+2, "INT")
Set tTestLines(tPythonMethodLine+2) = $ListBuild("SamplePythonMethod+1",,,tPyCodeUnit.Hash,tPyCodeUnit.MethodMap.GetAt("SamplePythonMethod")+1, "PY")
Set tTestLines(tPythonMethodLine+3) = $ListBuild("SamplePythonMethod+2",,,tPyCodeUnit.Hash,tPyCodeUnit.MethodMap.GetAt("SamplePythonMethod")+2, "PY")
Set tTestLines(tPythonWeirdSpacingMethodLine+4) = $ListBuild("PythonWeirdSpacing+1",,,tPyCodeUnit.Hash,tPyCodeUnit.MethodMap.GetAt("PythonWeirdSpacing")+1, "PY")
Set tTestLines(tPythonWeirdSpacingMethodLine+5) = $ListBuild("PythonWeirdSpacing+2",,,tPyCodeUnit.Hash,tPyCodeUnit.MethodMap.GetAt("PythonWeirdSpacing")+2, "PY")
Set tTestLines(tPythonWeirdSpacingMethodLine+6) = $ListBuild("PythonWeirdSpacing+3",,,tPyCodeUnit.Hash,tPyCodeUnit.MethodMap.GetAt("PythonWeirdSpacing")+3, "PY")

Set tLine = ""
For {
Set tLine = $Order(tTestLines(tLine),1,tInfo)
Expand Down Expand Up @@ -149,4 +155,13 @@ ClassMethod SamplePythonMethod() [ Language = python ]
return 50
}

ClassMethod PythonWeirdSpacing() [ Language = python ]
{


x = [0] * 10
x.append([50])
return [element * 2 for element in x]
}

}
Loading