Merge "AndroidPackageParsingTestBase: Re-throw failures in setUpPackages in individual tests" into rvc-dev

This commit is contained in:
Adrian Roos
2020-04-02 16:33:51 +00:00
committed by Android (Google) Code Review

View File

@@ -91,24 +91,35 @@ open class AndroidPackageParsingTestBase {
lateinit var newPackages: List<AndroidPackage>
var failureInBeforeClass: Throwable? = null
@Suppress("ConstantConditionIf")
@JvmStatic
@BeforeClass
fun setUpPackages() {
this.oldPackages = apks.map {
packageParser.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false)
}
failureInBeforeClass = null
try {
this.oldPackages = apks.map {
packageParser.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false)
}
this.newPackages = apks.map {
packageParser2.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false)
}
this.newPackages = apks.map {
packageParser2.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false)
}
if (DUMP_HPROF_TO_EXTERNAL) {
System.gc()
Environment.getExternalStorageDirectory()
.resolve("${AndroidPackageParsingTestBase::class.java.simpleName}.hprof")
.absolutePath
.run(Debug::dumpHprofData)
if (DUMP_HPROF_TO_EXTERNAL) {
System.gc()
Environment.getExternalStorageDirectory()
.resolve(
"${AndroidPackageParsingTestBase::class.java.simpleName}.hprof")
.absolutePath
.run(Debug::dumpHprofData)
}
} catch (t: Throwable) {
// If we crash here we cause a tool failure (because we don't run any of the tests
// in the subclasses, leading to a difference between expected and actual test
// result counts).
failureInBeforeClass = t
}
}
@@ -137,6 +148,13 @@ open class AndroidPackageParsingTestBase {
}
}
@org.junit.Before
fun verifySetUpPackages() {
failureInBeforeClass?.let {
throw AssertionError("setUpPackages failed:", it)
}
}
// The following methods dump an exact set of fields from the object to compare, because
// 1. comprehensive equals/toStrings do not exist on all of the Info objects, and
// 2. the test must only verify fields that [PackageParser.Package] can actually fill, as