Skip to content

Commit

Permalink
Fix large number merging on iOS (#477)
Browse files Browse the repository at this point in the history
  • Loading branch information
bootstraponline authored Jan 25, 2019
1 parent a089621 commit b74fdab
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,22 @@ data class JUnitTestSuite(
val systemErr: Any? // <system-err />
) {

/**
* Strips all characters except numbers and a period
* Returns 0 when the string is null
*
* Example: z1,23.45 => 123.45 */
private fun String?.clean(): String {
if (this == null) return "0"
return this.replace(Regex("""[^0-9\\.]"""), "")
}

private fun mergeInt(a: String?, b: String?): String {
return ((a ?: "0").toInt() + (b ?: "0").toInt()).toString()
return (a.clean().toInt() + b.clean().toInt()).toString()
}

private fun mergeDouble(a: String?, b: String?): String {
return "%.3f".format(((a ?: "0").toDouble() + (b ?: "0").toDouble()))
return "%.3f".format((a.clean().toDouble() + b.clean().toDouble()))
}

fun merge(other: JUnitTestSuite): JUnitTestSuite {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version='1.0' encoding='UTF-8'?>
<testsuites>
<testsuite name='EarlGreyExampleSwiftTests' hostname='localhost' tests='a99,999' failures='z99,999' errors='t99,999' time='o99,999.881'>
<properties />
<testcase name='testBasicSelectionActionAssert()' classname='EarlGreyExampleSwiftTests' time='0' />
<system-out />
<system-err />
</testsuite>
</testsuites>
24 changes: 22 additions & 2 deletions test_runner/src/test/kotlin/ftl/reports/xml/JUnitXmlTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class JUnitXmlTest {
val androidFailXml = Paths.get("$xmlRoot/android_fail.xml")!!
val iosPassXml = Paths.get("$xmlRoot/ios_pass.xml")!!
val iosFailXml = Paths.get("$xmlRoot/ios_fail.xml")!!
val iosLargeNum = Paths.get("$xmlRoot/ios_large_num.xml")!!
val androidSkipped = """
<testsuite name="" tests="2" failures="0" errors="0" skipped="1" time="0.026" timestamp="2018-10-26T19:57:28" hostname="localhost">
<properties/>
Expand Down Expand Up @@ -89,6 +90,23 @@ junit.framework.Assert.fail(Assert.java:50)</failure>
assertThat(merged).isEqualTo(expected)
}

@Test
fun `Merge iOS large time`() {
val merged = parseAllSuitesXml(iosLargeNum).merge(parseAllSuitesXml(iosLargeNum)).xmlToString()

val expected = """
<?xml version='1.0' encoding='UTF-8' ?>
<testsuites>
<testsuite name="EarlGreyExampleSwiftTests" tests="199998" failures="199998" errors="199998" skipped="0" time="199999.762" hostname="localhost">
<testcase name="testBasicSelectionActionAssert()" classname="EarlGreyExampleSwiftTests" time="0"/>
<testcase name="testBasicSelectionActionAssert()" classname="EarlGreyExampleSwiftTests" time="0"/>
</testsuite>
</testsuites>
""".trimIndent()
assertThat(merged).isEqualTo(expected)
}

@Test
fun parse_androidSkipped() {
val parsed = parseOneSuiteXml(androidSkipped)
Expand All @@ -101,7 +119,8 @@ junit.framework.Assert.fail(Assert.java:50)</failure>
merged.merge(merged)
val actual = merged.xmlToString()

assertThat(actual).isEqualTo("""
assertThat(actual).isEqualTo(
"""
<?xml version='1.0' encoding='UTF-8' ?>
<testsuites>
<testsuite name="" tests="4" failures="0" errors="0" skipped="2" time="0.052" timestamp="2018-10-26T19:57:28" hostname="localhost">
Expand All @@ -116,7 +135,8 @@ junit.framework.Assert.fail(Assert.java:50)</failure>
</testsuite>
</testsuites>
""".trimIndent())
""".trimIndent()
)
}

@Test
Expand Down

0 comments on commit b74fdab

Please sign in to comment.