Skip to content

Commit

Permalink
Workaround critical bug in JUnit file parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
omaus committed Oct 16, 2024
1 parent 9f3ccc5 commit 72aba15
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
78 changes: 77 additions & 1 deletion integrationTests_script.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
open Xunit
open Fake.Core

open System.Xml


let runTool (tool: string) (args: string []) (dir:string) =
CreateProcess.fromRawCommand tool args
Expand All @@ -14,4 +16,78 @@ let runTool (tool: string) (args: string []) (dir:string) =


//let result = runTool "dotnet" [|"fsi"; @"C:\Repos\nfdi4plants\arc-validation-packages\validation_packages\invenio\[email protected]"|] @"C:\Repos\nfdi4plants\arc-validation-packages\tests\fixtures\testARC_empty\"
let result = runTool "dotnet" [|"fsi"; @"C:\Repos\nfdi4plants\arc-validation-packages\validation_packages\invenio\[email protected]"|] @"C:\Repos\nfdi4plants\arc-validation-packages\tests\fixtures\testARC_emptyContactsColumn\"
let result = runTool "dotnet" [|"fsi"; @"C:\Repos\nfdi4plants\arc-validation-packages\validation_packages\invenio\[email protected]"|] @"C:\Repos\nfdi4plants\arc-validation-packages\tests\fixtures\testARC_emptyContactsColumn\"


type JUnitResults = {
PassedTests: string list
FailedTests: string list
ErroredTests: string list
} with
static member fromJUnitFile (path:string) =
let doc = new XmlDocument()
doc.Load(path)
let suite = doc.SelectNodes("/testsuites/testsuite[@name='arc-validate']").Item(0);
let testCases = suite.SelectNodes("testcase") |> Seq.cast<XmlNode>
{
PassedTests =
testCases
|> Seq.filter (fun tc -> tc.SelectNodes("failure").Count = 0)
|> Seq.map (fun tc -> tc.Attributes.["name"].Value)
|> Seq.toList
|> List.sort

FailedTests =
testCases
|> Seq.filter (fun tc -> tc.SelectNodes("failure").Count > 0)
|> Seq.map (fun tc -> tc.Attributes.["name"].Value)
|> Seq.toList
|> List.sort

ErroredTests =
testCases
|> Seq.filter (fun tc -> tc.SelectNodes("error").Count > 0)
|> Seq.map (fun tc -> tc.Attributes.["name"].Value)
|> Seq.toList
|> List.sort
}

static member getTotalTestCount (res : JUnitResults) =
res.ErroredTests.Length + res.FailedTests.Length + res.PassedTests.Length


let jUnitRes = JUnitResults.fromJUnitFile @"C:\Repos\nfdi4plants\arc-validation-packages\tests\fixtures\ArcPrototype\.arc-validate-results\[email protected]\validation_report.xml"

null = null

let doc = new XmlDocument()
doc.Load(@"C:\Repos\nfdi4plants\arc-validation-packages\tests\fixtures\ArcPrototype\.arc-validate-results\[email protected]\validation_report.xml")
let suite =
doc.SelectNodes("/testsuites/testsuite[@name='arc-validate']").Item(0)
|> fun r ->
if isNull r then
doc.SelectNodes("/testsuites/testsuite[@name='fsi']").Item(0)
else r
let testCases = suite.SelectNodes("testcase") |> Seq.cast<XmlNode>
{
PassedTests =
testCases
|> Seq.filter (fun tc -> tc.SelectNodes("failure").Count = 0)
|> Seq.map (fun tc -> tc.Attributes.["name"].Value)
|> Seq.toList
|> List.sort

FailedTests =
testCases
|> Seq.filter (fun tc -> tc.SelectNodes("failure").Count > 0)
|> Seq.map (fun tc -> tc.Attributes.["name"].Value)
|> Seq.toList
|> List.sort

ErroredTests =
testCases
|> Seq.filter (fun tc -> tc.SelectNodes("error").Count > 0)
|> Seq.map (fun tc -> tc.Attributes.["name"].Value)
|> Seq.toList
|> List.sort
}
7 changes: 6 additions & 1 deletion tests/TestUtils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ type JUnitResults = {
static member fromJUnitFile (path : string) =
let doc = new XmlDocument()
doc.Load(path)
let suite = doc.SelectNodes("/testsuites/testsuite[@name='arc-validate']").Item(0)
let suite =
doc.SelectNodes("/testsuites/testsuite[@name='arc-validate']").Item(0)
|> fun r ->
if isNull r then
doc.SelectNodes("/testsuites/testsuite[@name='fsi']").Item(0)
else r
let testCases = suite.SelectNodes("testcase") |> Seq.cast<XmlNode>
{
PassedTests =
Expand Down

0 comments on commit 72aba15

Please sign in to comment.