Skip to content

Fix #23 and #24 #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 17, 2024
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
78 changes: 78 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Export XML and Release on Tag Push

on:
push:
tags:
- '*'

jobs:
build:
runs-on: ubuntu-latest

env:
# ** FOR GENERAL USE, LIKELY NEED TO CHANGE: **
package: TestCoverage
container_image: intersystemsdc/iris-community:latest

# ** FOR GENERAL USE, MAY NEED TO CHANGE: **
build_flags: -dev -verbose # Load in -dev mode to get unit test code preloaded
test_package: UnitTest

# ** FOR GENERAL USE, SHOULD NOT NEED TO CHANGE: **
instance: iris
# Note: test_reports value is duplicated in test_flags environment variable
test_reports: test-reports
test_flags: >-
-verbose -DUnitTest.ManagerClass=TestCoverage.Manager -DUnitTest.JUnitOutput=/test-reports/junit.xml
-DUnitTest.FailuresAreFatal=1 -DUnitTest.Manager=TestCoverage.Manager
-DUnitTest.UserParam.CoverageReportClass=TestCoverage.Report.Cobertura.ReportGenerator
-DUnitTest.UserParam.CoverageReportFile=/source/coverage.xml

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run Container
run: |
# Create test_reports directory to share test results before running container
mkdir $test_reports
chmod 777 $test_reports
# Run InterSystems IRIS instance
docker pull $container_image
docker run -d -h $instance --name $instance -v $GITHUB_WORKSPACE:/source -v $GITHUB_WORKSPACE/$test_reports:/$test_reports --init $container_image
echo halt > wait
# Wait for instance to be ready
until docker exec --interactive $instance iris session $instance < wait; do sleep 1; done

- name: Install TestCoverage
run: |
echo "zpm \"install testcoverage\":1:1" > install-testcoverage
docker exec --interactive $instance iris session $instance -B < install-testcoverage
# Workaround for permissions issues in TestCoverage (creating directory for source export)
chmod 777 $GITHUB_WORKSPACE

- name: Get latest tag
id: tag
uses: actions-ecosystem/action-get-latest-tag@v1

- name: Export XML
run: |
# Pick the targets to export as XML
echo 'set list("TestCoverage.*.cls") = ""' >> export
echo 'set list("TestCoverage.inc") = ""' >> export
echo 'do $System.OBJ.Export(.list,"/source/TestCoverage-${{ steps.tag.outputs.tag }}.xml","/exportversion=2017.2")' >> export
docker exec --interactive $instance iris session $instance -B < export

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: TestCoverage-${{ steps.tag.outputs.tag }}.xml
tag_name: ${{ github.ref }}
name: ${{ steps.tag.outputs.tag }}
body: |
Automated release created by [action-gh-release](https://github.com/softprops/action-gh-release).
draft: false
prerelease: false
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ 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).

## [3.1.0] - 2024-01-17

### Changed
- #23: Allow CoverageClasses and CoverageRoutines to be specified as %DynamicArray in addition to $ListBuild() lists.

### Fixed
- #24: Whenever a new tag is created, a new release will be published using the tag string as its version. The release also comes with an export of the TestCoverage package in XML.

## [3.0.0] - 2023-12-01

### Changed
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Generally speaking, set `^UnitTestRoot`, and then call `##class(TestCoverage.Man
The "userparam" argument can be used to pass information about code coverage data collection. For example:

```
Set tCoverageParams("CoverageClasses") = <$ListBuild list of class names for which code coverage data should be collected>
Set tCoverageParams("CoverageRoutines") = <$ListBuild list of routine names for which code coverage data should be collected>
Set tCoverageParams("CoverageClasses") = <$ListBuild list or %DynamicArray of class names for which code coverage data should be collected>
Set tCoverageParams("CoverageRoutines") = <$ListBuild list or %DynamicArray of routine names for which code coverage data should be collected>
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.>
Do ##class(TestCoverage.Manager).RunTest(,,.tCoverageParams)
```
Expand Down
18 changes: 14 additions & 4 deletions cls/TestCoverage/Manager.cls
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Property Monitor As TestCoverage.Utils.LineByLineMonitor [ InitialExpression = {
/// <ul>
/// <li><var>pPackage</var> has the top-level package containing all the unit test classes to run. These must already be loaded.</li>
/// <li><var>pLogFile</var> (optional) may specify a file to log all output to.</li>
/// <li><var>pCoverageClasses</var> (optional) has a $ListBuild list of class names within which to track code coverage. By default, none are tracked.</li>
/// <li><var>pCoverageRoutines</var> (optional) has a $ListBuild list of routine names within which to track code coverage. By default, none are tracked.</li>
/// <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>
/// <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>
/// <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.
/// Note that overall tracking is always available; more granular tracking requires more time and disk space.</li>
/// <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>
Expand All @@ -94,8 +94,8 @@ ClassMethod RunAllTests(pPackage As %String = "", pLogFile As %String = "", pCov
Set tTestSuite = $Replace(pPackage,"/",".")
Set tSpec = "/noload/nodelete"
Merge tCoverageParams("LogIndex") = pLogIndex // Set only if defined.
Set tCoverageParams("CoverageClasses") = pCoverageClasses
Set tCoverageParams("CoverageRoutines") = pCoverageRoutines
Set tCoverageParams("CoverageClasses") = $SELECT($CLASSNAME(pCoverageClasses) = "%Library.DynamicArray":..ArrayToList(pCoverageClasses), 1:pCoverageClasses)
Set tCoverageParams("CoverageRoutines") = $SELECT($CLASSNAME(pCoverageRoutines) = "%Library.DynamicArray":..ArrayToList(pCoverageRoutines), 1:pCoverageRoutines)
Set tCoverageParams("CoverageDetail") = pCoverageLevel
Set tCoverageParams("SourceNamespace") = pSourceNamespace
Set tCoverageParams("ProcessIDs") = pPIDList
Expand Down Expand Up @@ -129,6 +129,16 @@ ClassMethod RunAllTests(pPackage As %String = "", pLogFile As %String = "", pCov
Quit $Select(tSuccess:1,1:$$$ERROR($$$GeneralError,"One or more errors occurred in unit tests."))
}

ClassMethod ArrayToList(pDynamicArray As %DynamicArray) As %List
{
Set tList = ""
Set tIter = pDynamicArray.%GetIterator()
While tIter.GetNext(, .value) {
Set tList = tList _ $LISTBUILD(value)
}
Quit tList
}

Method SetCoverageTargets(pClasses As %List = "", pRoutines As %List = "", pInit As %Boolean = 0) [ Private ]
{
Set tList = "", tPtr = 0
Expand Down
2 changes: 1 addition & 1 deletion module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Export generator="Cache" version="25">
<Document name="TestCoverage.ZPM"><Module>
<Name>TestCoverage</Name>
<Version>3.0.0</Version>
<Version>3.1.0</Version>
<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>
<Packaging>module</Packaging>
<Resource Name="TestCoverage.PKG" Directory="cls" />
Expand Down