From 46152fa61dac8585151b6e17d35aff979f0a57b1 Mon Sep 17 00:00:00 2001 From: isc-tleavitt <73311181+isc-tleavitt@users.noreply.github.com> Date: Tue, 23 Sep 2025 11:00:35 -0400 Subject: [PATCH] Fix #66; also line ending issues on docker - #66: Fixed errors when a Language = python method has a name starting with "%" - coverage.list files with Windows-style line endings are now parsed properly in Linux containers --- CHANGELOG.md | 8 +++++++- cls/TestCoverage/Data/CodeUnit.cls | 11 ++++++++++- cls/TestCoverage/Manager.cls | 3 ++- .../UnitTest/TestCoverage/Unit/TestComplexity.cls | 9 +++++++++ module.xml | 2 +- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6910cb..fc31a45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [4.0.6] +## [4.0.7] - 2025-09-23 + +### Fixed +- #66: No longer errors when a `[ Language = python ]` method has a name starting with "%" +- coverage.list files with Windows-style line endings are now parsed properly in Linux containers + +## [4.0.6] - 2025-08-13 ### Fixed - #63: TestCoverage.Manager On/After methods now call superclass so improvements to %UnitTest.Manager like AutoUserNames will work properly diff --git a/cls/TestCoverage/Data/CodeUnit.cls b/cls/TestCoverage/Data/CodeUnit.cls index 0009890..543d0f2 100644 --- a/cls/TestCoverage/Data/CodeUnit.cls +++ b/cls/TestCoverage/Data/CodeUnit.cls @@ -401,6 +401,10 @@ Method UpdateSourceMap(pSourceNamespace As %String, ByRef pCache) As %Status // for each method in the .py file, we'll find the line number of the corresponding method (guaranteed to be unique) in the .cls file // and then map each line in the .py file to each line in the .cls file by just going 1 by 1 down the lines Set tCLSMethodNum = pCLSCodeUnit.MethodMap.GetAt(tMethod) + If (tCLSMethodNum = "") { + // %Foo() becomes _Foo() in the Python code unit. + Set tCLSMethodNum = pCLSCodeUnit.MethodMap.GetAt($Replace(tMethod,"_","%")) + } Set tMethodStart = ..MethodMap.GetAt(tMethod) Set tMethodEnd = ..MethodEndMap.GetAt(tMethod) Set tMethodName = tMethod @@ -571,7 +575,12 @@ Method UpdateComplexity() As %Status Quit } If (tSubUnit.IsPythonMethod) { - set tSubUnit.Complexity = tMethodComplexities."__getitem__"(tSubUnit.Name) + for name = tSubUnit.Name,$Replace(tSubUnit.Name,"%","_") { + if tMethodComplexities."__contains__"(name) { + set tSubUnit.Complexity = tMethodComplexities."__getitem__"(name) + quit + } + } $$$ThrowOnError(tSubUnit.%Save(0)) } Else { $$$ThrowOnError(tSubUnit.UpdateComplexity()) diff --git a/cls/TestCoverage/Manager.cls b/cls/TestCoverage/Manager.cls index 3c5c469..0d4c48b 100644 --- a/cls/TestCoverage/Manager.cls +++ b/cls/TestCoverage/Manager.cls @@ -425,13 +425,14 @@ ClassMethod GetCoverageTargetsForFile(pFileName As %String, Output pTargetArray) Set tFileStream = ##class(%Stream.FileCharacter).%New() Do tFileStream.LinkToFile(pFileName) + Set tFileStream.LineTerminator = $c(10) While 'tFileStream.AtEnd { Set tFileLines($Increment(tFileLines)) = tFileStream.ReadLine() } For tLineIndex=1:1:$Get(tFileLines) { Set tLine = tFileLines(tLineIndex) - Set tLine = $zstrip(tLine, "<>W") + Set tLine = $zstrip(tLine, "<>WC") // Skip blank lines If (tLine = "") { Continue diff --git a/internal/testing/unit_tests/UnitTest/TestCoverage/Unit/TestComplexity.cls b/internal/testing/unit_tests/UnitTest/TestCoverage/Unit/TestComplexity.cls index 1801d6c..3f39f8a 100644 --- a/internal/testing/unit_tests/UnitTest/TestCoverage/Unit/TestComplexity.cls +++ b/internal/testing/unit_tests/UnitTest/TestCoverage/Unit/TestComplexity.cls @@ -254,4 +254,13 @@ ClassMethod ForLoopPython() [ Language = python ] return 1 } +/// Complexity: 3 (1 + for + if) +ClassMethod %ForLoopPython() [ Language = python ] +{ + for i in range(5): + if i > 4: + continue + return 1 +} + } diff --git a/module.xml b/module.xml index f099dc6..94ead62 100644 --- a/module.xml +++ b/module.xml @@ -2,7 +2,7 @@ TestCoverage - 4.0.6 + 4.0.7 Run your typical ObjectScript %UnitTest tests and see which lines of your code are executed. Includes Cobertura-style reporting for use in continuous integration tools. module