Skip to content

Commit

Permalink
place summary columns next to each other in actions summary
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinafyi committed Jul 11, 2024
1 parent af7b5f0 commit 1f36069
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/test/scala/SystemTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ trait SystemTests extends AnyFunSuite {
}
}

/**
* Writes test result data into .csv and .md files named according to given filename.
*/
def summary(filename: String): Unit = {
val csv: String = "testCase," + TestResult.csvHeader + System.lineSeparator() + testResults.map(r => s"${r._1},${r._2.toCsv}").mkString(System.lineSeparator())
log(csv, testPath + "full-" + filename + ".csv")
Expand Down Expand Up @@ -73,14 +76,30 @@ trait SystemTests extends AnyFunSuite {
val summaryRow = summaryMap.values.mkString(",") + System.lineSeparator
log(summaryHeader + summaryRow, testPath + "summary-" + filename + ".csv")

val summaryMarkdown = s"""
|## $filename
|
|| Metric | Value |
||--------|-------|
// generates a markdown table in separate parts.
// the complete markdown file can be constructed by horizontal (line-wise)
// concatenation of leftMarkdown and one or more partMarkdown.
val leftMarkdown =
s"""
|| Metric |
||--------|
|""".stripMargin
+ summaryMap.map((k,v) => s"| $k | $v |${System.lineSeparator}").mkString
+ summaryMap.map((k,_) => s"| $k |${System.lineSeparator}").mkString

val partMarkdown =
s"""
| $filename |
|-------|
|""".stripMargin
+ summaryMap.map((k,v) => s" $v |${System.lineSeparator}").mkString

val summaryMarkdown = leftMarkdown.linesIterator
.zip(partMarkdown.linesIterator)
.map(_++_)
.mkString("", System.lineSeparator, System.lineSeparator)

log(partMarkdown, testPath + "summary-" + filename + ".md.part")
log(leftMarkdown, testPath + "headers.md.part") // XXX likely not thread-safe
log(summaryMarkdown, testPath + "summary-" + filename + ".md")
}

Expand Down Expand Up @@ -168,7 +187,10 @@ trait SystemTests extends AnyFunSuite {
* the names all subdirectories of the given parent directory
*/
def getSubdirectories(directoryName: String): Array[String] = {
File(directoryName).listFiles.filter(_.isDirectory).map(_.getName)
Option(File(directoryName).listFiles(_.isDirectory)) match {
case None => throw java.io.IOException(s"failed to read directory '$directoryName'")
case Some(subdirs) => subdirs.map(_.getName)
}
}

def log(text: String, path: String): Unit = {
Expand Down

0 comments on commit 1f36069

Please sign in to comment.