Skip to content
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

Fix large number merging on iOS #477

Merged
merged 1 commit into from
Jan 25, 2019
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
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