-
Notifications
You must be signed in to change notification settings - Fork 27
feat: Add JSON, YAML, and Toon output options for zpm test results #979
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
base: main
Are you sure you want to change the base?
Changes from all commits
4307599
dbb7bed
cd77c52
aef4c32
d1c0dce
3b731a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /// The class serves as the base class for all the unit test result formatting. | ||
| Class %IPM.Test.Abstract Extends %RegisteredObject | ||
| { | ||
|
|
||
| ClassMethod ToFile( | ||
| FileName As %String, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: method parameters should be in camelCase, not PascalCase |
||
| CaseStatus As %String = "", | ||
| TestIndex As %Integer = {$order(^UnitTest.Result(""),-1)}) As %Status [ Abstract ] | ||
| { | ||
| } | ||
|
|
||
| ClassMethod OutputToDevice( | ||
| TestIndex As %Integer = {$order(^UnitTest.Result(""),-1)}, | ||
| TestStatus As %String = "") [ Abstract ] | ||
| { | ||
| } | ||
|
|
||
| Query FilteredTestResults( | ||
| Instance As %Integer, | ||
| TestStatus) As %SQLQuery(ROWSPEC = "TotalCounts:%Integer,namespace:%String,duration:%String,testDateTime:%String,suiteName:%String,testcaseName:%String,methodName:%String,testMethod:%String,assertAction:%String,assertCounter:%Integer,assertDescription:%String,assertLocation:%String", SELECTMODE = "DISPLAY") | ||
| { | ||
| SELECT | ||
| count(*) as TotalCounts, | ||
| tinstance.Namespace AS namespace, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: no need for t- prefixes here either |
||
| tinstance.Duration AS duration, | ||
| tinstance.DateTime AS testDateTime, | ||
| tsuite.Name AS suiteName, | ||
| tcase.Name AS testcaseName, | ||
| tmethod.Name AS methodName, | ||
| tassert.TestMethod AS testMethod, | ||
| tassert.Action AS assertAction, | ||
| tassert.Counter AS assertCounter, | ||
| tassert.Description AS assertDescription, | ||
| tassert.Location AS assertLocation | ||
| FROM | ||
| %UnitTest_Result.TestInstance tinstance | ||
| JOIN %UnitTest_Result.TestSuite tsuite ON tsuite.TestInstance=tinstance.ID | ||
| JOIN %UnitTest_Result.TestCase tcase ON tcase.TestSuite=tsuite.ID | ||
| JOIN %UnitTest_Result.TestMethod tmethod ON tmethod.TestCase=tcase.ID | ||
| JOIN %UnitTest_Result.TestAssert tassert ON tassert.TestMethod=tmethod.ID | ||
| WHERE tinstance.ID=:Instance AND tassert.Status=:TestStatus | ||
| } | ||
|
|
||
| Query GetAllTestResults(Instance As %Integer) As %SQLQuery(ROWSPEC = "TotalCounts:%String,namespace:%String,duration:%String,testDateTime:%String,suiteName:%String,testcaseName:%String,methodName:%String,testMethod:%String,assertAction:%String,assertCounter:%Integer,assertDescription:%String,assertLocation:%String", SELECTMODE = "DISPLAY") | ||
| { | ||
| SELECT | ||
| count(*) as TotalCounts, | ||
| tinstance.Namespace AS namespace, | ||
| tinstance.Duration AS duration, | ||
| tinstance.DateTime AS testDateTime, | ||
| tsuite.Name AS suiteName, | ||
| tcase.Name AS testcaseName, | ||
| tmethod.Name AS methodName, | ||
| tassert.TestMethod AS testMethod, | ||
| tassert.Action AS assertAction, | ||
| tassert.Counter AS assertCounter, | ||
| tassert.Description AS assertDescription, | ||
| tassert.Location AS assertLocation | ||
| FROM | ||
| %UnitTest_Result.TestInstance tinstance | ||
| JOIN %UnitTest_Result.TestSuite tsuite ON tsuite.TestInstance=tinstance.ID | ||
| JOIN %UnitTest_Result.TestCase tcase ON tcase.TestSuite=tsuite.ID | ||
| JOIN %UnitTest_Result.TestMethod tmethod ON tmethod.TestCase=tcase.ID | ||
| JOIN %UnitTest_Result.TestAssert tassert ON tassert.TestMethod=tmethod.ID | ||
| WHERE tinstance.ID=:Instance | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| Class %IPM.Test.JsonOutput Extends %IPM.Test.Abstract | ||
| { | ||
|
|
||
| ClassMethod ToFile( | ||
| FileName As %String, | ||
| TestStatus As %String = "", | ||
| TestIndex As %Integer = {$order(^UnitTest.Result(""),-1)}) As %Status | ||
| { | ||
| set sc = $$$OK | ||
| try { | ||
| set fileStream = ##class(%Stream.FileCharacter).%New() | ||
| set fileStream.TranslateTable = "UTF8" | ||
| $$$ThrowOnError(fileStream.LinkToFile(FileName)) | ||
| set responseJson = ..JSON(TestIndex, TestStatus) | ||
| if $isobject(responseJson) { | ||
| do fileStream.Write(responseJson.%ToJSON()) | ||
| } | ||
| $$$ThrowOnError(fileStream.%Save()) | ||
| } catch ex { | ||
| set sc = ex.AsStatus() | ||
| } | ||
| return sc | ||
| } | ||
|
|
||
| ClassMethod OutputToDevice( | ||
| TestIndex As %Integer = {$order(^UnitTest.Result(""),-1)}, | ||
| pCaseStatus As %String = "") As %Status | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: remove p- prefix and change to camelCase |
||
| { | ||
| set sc = $$$OK | ||
| try { | ||
| set responseJson = ..JSON(TestIndex, pCaseStatus) | ||
| write ! | ||
| if $isobject(responseJson) { | ||
| do responseJson.%ToJSON() | ||
| } | ||
| } catch ex { | ||
| set sc = ex.AsStatus() | ||
| } | ||
| return sc | ||
| } | ||
|
|
||
| ClassMethod JSON( | ||
| TestIndex As %Integer, | ||
| TestStatus As %String) As %DynamicObject | ||
| { | ||
| if TestStatus'="" { | ||
| set tResult = ..FilteredTestResultsFunc(TestIndex, TestStatus) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: remove the t-prefixes |
||
| } else { | ||
| set tResult = ..GetAllTestResultsFunc(TestIndex) | ||
| } | ||
| set unitTest = {} | ||
| set unitTest.results = [] | ||
| set (previousID,currentSuite,currentTestcase,suiteObj,testcaseObj) = "" | ||
|
|
||
| while tResult.%Next() { | ||
| if previousID = "" { | ||
| set unitTest.id = TestIndex | ||
| set unitTest.namespace = tResult.namespace | ||
| set unitTest.duration = tResult.duration | ||
| set unitTest.testDateTime = tResult.testDateTime | ||
| } | ||
| set previousID = TestIndex | ||
| if tResult.suiteName '= currentSuite { | ||
| set currentSuite = tResult.suiteName | ||
| set suiteObj = { | ||
| "suiteName": (currentSuite), | ||
| "testcases": [] | ||
| } | ||
| do unitTest.results.%Push(suiteObj) | ||
| set currentTestcase = "" | ||
| } | ||
| if tResult.testcaseName '= currentTestcase { | ||
| set currentTestcase = tResult.testcaseName | ||
| set testcaseObj = { | ||
| "testcaseName": (currentTestcase), | ||
| "methods": [] | ||
| } | ||
| do suiteObj.testcases.%Push(testcaseObj) | ||
| } | ||
| set methodObj = { | ||
| "methodName": (tResult.methodName), | ||
| "testMethod": (tResult.testMethod), | ||
| "assertAction": (tResult.assertAction), | ||
| "assertCounter": (tResult.assertCounter), | ||
| "assertDescription": (tResult.assertDescription), | ||
| "assertLocation": (tResult.assertLocation) | ||
| } | ||
| do testcaseObj.methods.%Push(methodObj) | ||
| } | ||
| return unitTest | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| Class %IPM.Test.ToonOutput Extends %IPM.Test.Abstract | ||
| { | ||
|
|
||
| ClassMethod ToFile( | ||
| FileName As %String, | ||
| TestStatus As %String = "", | ||
| TestIndex As %Integer = {$order(^UnitTest.Result(""),-1)}) As %Status | ||
| { | ||
| set sc = $$$OK | ||
| try { | ||
| set fileStream = ##class(%Stream.FileCharacter).%New() | ||
| set fileStream.TranslateTable = "UTF8" | ||
| $$$ThrowOnError(fileStream.LinkToFile(FileName)) | ||
|
|
||
| if TestStatus'="" { | ||
| set tResult = ..FilteredTestResultsFunc(TestIndex, TestStatus) | ||
| } else { | ||
| set tResult = ..GetAllTestResultsFunc(TestIndex) | ||
| } | ||
|
|
||
| set currentID="" | ||
| while tResult.%Next() { | ||
| if currentID = "" { | ||
| set currentID = TestIndex | ||
| do fileStream.WriteLine("unitTest:") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lots of statuses that need checking here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. Updated the code!
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still need to check the %Status returned by the WriteLine() calls |
||
| do fileStream.WriteLine(" id: "_TestIndex) | ||
| do fileStream.WriteLine(" namespace: "_tResult.namespace) | ||
| do fileStream.WriteLine(" duration: "_tResult.duration) | ||
| do fileStream.WriteLine(" testDateTime: "_tResult.testDateTime) | ||
| do fileStream.WriteLine() | ||
| do fileStream.WriteLine("results["_tResult.TotalCounts_"]{suiteName,testcaseName,methodName,status,assertAction,assertCounter,assertDescription,assertLocation}:") | ||
| } | ||
| set data = " "_tResult.suiteName_","_tResult.testcaseName_","_tResult.methodName_","_TestIndex_","_ | ||
| tResult.assertAction_","_tResult.assertCounter_","""_$translate(tResult.assertDescription,"""")_""","""_tResult.assertLocation_"""" | ||
| do fileStream.WriteLine(data) | ||
| } | ||
| $$$ThrowOnError(fileStream.%Save()) | ||
| } catch ex { | ||
| set sc = ex.AsStatus() | ||
| } | ||
| return sc | ||
| } | ||
|
|
||
| ClassMethod OutputToDevice( | ||
| TestIndex As %Integer = {$order(^UnitTest.Result(""),-1)}, | ||
| TestStatus As %String = "") As %Status | ||
| { | ||
| set sc = $$$OK | ||
| try { | ||
| if TestStatus'="" { | ||
| set tResult = ..FilteredTestResultsFunc(TestIndex, TestStatus) | ||
| } else { | ||
| set tResult = ..GetAllTestResultsFunc(TestIndex) | ||
| } | ||
| set currentID="" | ||
| while tResult.%Next() { | ||
| if currentID = "" { | ||
| set currentID = TestIndex | ||
| write !,"unitTest:" | ||
| write !," id: "_TestIndex | ||
| write !," namespace: "_tResult.namespace | ||
| write !," duration: "_tResult.duration | ||
| write !," testDateTime: "_tResult.testDateTime | ||
| write ! | ||
| write !,"results["_tResult.TotalCounts_"]{suiteName,testcaseName,methodName,status,assertAction,assertCounter,assertDescription,assertLocation}:" | ||
| } | ||
| set data = " "_tResult.suiteName_","_tResult.testcaseName_","_tResult.methodName_","_TestIndex_","_ | ||
| tResult.assertAction_","_tResult.assertCounter_","""_$translate(tResult.assertDescription,"""")_""","""_tResult.assertLocation_"""" | ||
| write !,data | ||
| } | ||
| } catch ex { | ||
| set sc = ex.AsStatus() | ||
| } | ||
| return sc | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: should be one line, i.e.
} else {