Skip to content

Commit 114426e

Browse files
authored
Merge pull request #65 from intersystems/fix-63
fix: call superclass in TestCoverage.Manager so updates to %UnitTest.Manager will be propagated
2 parents adbe6ae + cfd1241 commit 114426e

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [4.0.6]
9+
10+
### Fixed
11+
- #63: TestCoverage.Manager On/After methods now call superclass so improvements to %UnitTest.Manager like AutoUserNames will work properly
12+
813
## [4.0.5] - 2024-11-04
914

1015
### Fixed

cls/TestCoverage/Manager.cls

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ Method OnAfterSaveResult(ByRef userparam)
592592
{
593593
Try {
594594
Quit:'$IsObject(..Run)
595+
Do ##super(.userparam)
595596

596597
// Associate to unit test results.
597598
Do ..Run.TestResultsSetObjectId(..LogIndex)
@@ -630,6 +631,7 @@ ClassMethod OnBeforeAllTests(manager As TestCoverage.Manager, dir As %String, By
630631
{
631632
Set tSC = $$$OK
632633
Try {
634+
Set tSC = ##super(.manager, .dir, .qstruct, .userparam)
633635
Set tCoverageClasses = $Get(userparam("CoverageClasses"))
634636
Set tCoverageRoutines = $Get(userparam("CoverageRoutines"))
635637
Set tCoverageDetail = $Get(userparam("CoverageDetail"))
@@ -717,8 +719,12 @@ ClassMethod OnAfterAllTests(manager As TestCoverage.Manager, dir As %String, ByR
717719
{
718720
Set tSC = $$$OK
719721
Try {
722+
Set tSC = ##super(.manager, .dir, .qstruct, .userparam)
720723
If (manager.CoverageDetail = 0) {
721-
Set tSC = manager.EndCoverageTracking()
724+
Set sc = manager.EndCoverageTracking()
725+
If $$$ISERR(sc) {
726+
Set tSC = $$$ADDSC(tSC,sc)
727+
}
722728
if (manager.ListenerManager) {
723729
set tObj = {"message": "All tests complete"}
724730
Do manager.ListenerManager.BroadCastToAll(tObj)
@@ -742,6 +748,7 @@ Method OnBeforeAutoLoad(dir As %String, suite As %String, testspec As %String, B
742748
{
743749
Set tSC = $$$OK
744750
Try {
751+
Set tSC = ##super(.dir, .suite, .testspec, .qstruct)
745752
// TODO: Flag to capture code coverage of compiling autoload classes? (e.g., to cover generators?)
746753
} Catch e {
747754
Set tSC = e.AsStatus()
@@ -756,6 +763,7 @@ Method OnBeforeTestSuite(dir As %String, suite As %String, testspec As %String,
756763
{
757764
Set tSC = $$$OK
758765
Try {
766+
Set tSC = ##super(.dir, .suite, .testspec, .qstruct)
759767
If ..DynamicTargets && (dir '= "") {
760768
// Determine coverage targets based on directory contents (looking for coverage.list in that directory or the nearest ancestor containing it).
761769
Set tSC = ..UpdateCoverageTargetsForTestDirectory(dir)
@@ -770,7 +778,10 @@ Method OnBeforeTestSuite(dir As %String, suite As %String, testspec As %String,
770778
Do ..ListenerManager.BroadCastToAll(tObj)
771779
}
772780
If (..CoverageDetail = 1) {
773-
Set tSC = ..StartCoverageTracking()
781+
Set sc = ..StartCoverageTracking()
782+
If $$$ISERR(sc) {
783+
Set tSC = $$$ADDSC(tSC,sc)
784+
}
774785
}
775786

776787
} Catch e {
@@ -785,9 +796,13 @@ Method OnAfterTestSuite(dir As %String, suite As %String, testspec As %String, B
785796
{
786797
Set tSC = $$$OK
787798
Try {
799+
Set tSC = ##super(.dir, .suite, .testspec, .qstruct)
788800

789801
If (..CoverageDetail = 1) {
790-
Set tSC = ..EndCoverageTracking($Case(suite,"":"(root)",:suite))
802+
Set sc = ..EndCoverageTracking($Case(suite,"":"(root)",:suite))
803+
If $$$ISERR(sc) {
804+
Set tSC = $$$ADDSC(tSC,sc)
805+
}
791806
}
792807
if (..ListenerManager) {
793808
set tObj = {"message": "Finished test suite: "}
@@ -806,6 +821,7 @@ Method OnBeforeTestCase(suite As %String, class As %String) As %Status
806821
{
807822
Set tSC = $$$OK
808823
Try {
824+
Set tSC = ##super(.suite, .class, .testcase)
809825
Set ..CurrentTestClass = class
810826
Set ..CurrentTestMethod = ""
811827
if (..ListenerManager) {
@@ -815,7 +831,10 @@ Method OnBeforeTestCase(suite As %String, class As %String) As %Status
815831
Do ..ListenerManager.BroadCastToAll(tObj)
816832
}
817833
If (..CoverageDetail = 2) {
818-
Set tSC = ..StartCoverageTracking()
834+
Set sc = ..StartCoverageTracking()
835+
If $$$ISERR(sc) {
836+
Set tSC = $$$ADDSC(tSC,sc)
837+
}
819838
}
820839
} Catch e {
821840
Set tSC = e.AsStatus()
@@ -829,8 +848,12 @@ Method OnAfterTestCase(suite As %String, class As %String) As %Status
829848
{
830849
Set tSC = $$$OK
831850
Try {
851+
Set tSC = ##super(.suite, .class, .testcase)
832852
If (..CoverageDetail = 2) {
833-
Set tSC = ..EndCoverageTracking(suite, class)
853+
Set sc = ..EndCoverageTracking(suite, class)
854+
If $$$ISERR(sc) {
855+
Set tSC = $$$ADDSC(tSC,sc)
856+
}
834857
}
835858
if (..ListenerManager) {
836859
set tObj = {"message": "Finished test case: "}
@@ -850,6 +873,7 @@ Method OnBeforeOneTest(suite As %String, class As %String, method As %String) As
850873
{
851874
Set tSC = $$$OK
852875
Try {
876+
Set tSC = ##super(.suite, .class, .method)
853877
Set ..CurrentTestMethod = method
854878
if (..ListenerManager) {
855879
set tObj = {"message": "Starting test method: "}
@@ -859,7 +883,10 @@ Method OnBeforeOneTest(suite As %String, class As %String, method As %String) As
859883
Do ..ListenerManager.BroadCastToAll(tObj)
860884
}
861885
If (..CoverageDetail = 3) {
862-
Set tSC = ..StartCoverageTracking()
886+
Set sc = ..StartCoverageTracking()
887+
If $$$ISERR(sc) {
888+
Set tSC = $$$ADDSC(tSC,sc)
889+
}
863890
}
864891
} Catch e {
865892
Set tSC = e.AsStatus()
@@ -873,8 +900,12 @@ Method OnAfterOneTest(suite As %String, class As %String, method As %String) As
873900
{
874901
Set tSC = $$$OK
875902
Try {
903+
Set tSC = ##super(.suite, .class, .method)
876904
If (..CoverageDetail = 3) {
877-
Set tSC = ..EndCoverageTracking(suite, class, method)
905+
Set sc = ..EndCoverageTracking(suite, class, method)
906+
If $$$ISERR(sc) {
907+
Set tSC = $$$ADDSC(tSC,sc)
908+
}
878909
}
879910
if (..ListenerManager) {
880911
set tObj = {"message": "Finished test method: "}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Class UnitTest.TestCoverage.Unit.Manager Extends %UnitTest.TestCase
2+
{
3+
4+
Parameter AutoUserNames As STRING = "TestA;TestB;TestC";
5+
6+
Method TestAutoUserNames()
7+
{
8+
// verify the 3 usernames are automatically created
9+
New $NAMESPACE
10+
Set $NAMESPACE = "%SYS"
11+
12+
Do $$$AssertTrue(##class(Security.Users).Exists("TestA"))
13+
Do $$$AssertTrue(##class(Security.Users).Exists("TestB"))
14+
Do $$$AssertTrue(##class(Security.Users).Exists("TestC"))
15+
Do $$$AssertNotTrue(##class(Security.Users).Exists("TestD"))
16+
}
17+
18+
}

module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Export generator="Cache" version="25">
33
<Document name="TestCoverage.ZPM"><Module>
44
<Name>TestCoverage</Name>
5-
<Version>4.0.5</Version>
5+
<Version>4.0.6</Version>
66
<Description>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.</Description>
77
<Packaging>module</Packaging>
88
<Resource Name="TestCoverage.PKG" Directory="cls" />

0 commit comments

Comments
 (0)