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

Change-Id: I52dc7c78bba4a4b92a7d3cb170771275a2790ff0
This commit is contained in:
Adrian Roos
2020-04-02 16:41:58 +00:00
committed by Automerger Merge Worker

View File

@@ -91,10 +91,14 @@ open class AndroidPackageParsingTestBase {
lateinit var newPackages: List<AndroidPackage> lateinit var newPackages: List<AndroidPackage>
var failureInBeforeClass: Throwable? = null
@Suppress("ConstantConditionIf") @Suppress("ConstantConditionIf")
@JvmStatic @JvmStatic
@BeforeClass @BeforeClass
fun setUpPackages() { fun setUpPackages() {
failureInBeforeClass = null
try {
this.oldPackages = apks.map { this.oldPackages = apks.map {
packageParser.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false) packageParser.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false)
} }
@@ -106,10 +110,17 @@ open class AndroidPackageParsingTestBase {
if (DUMP_HPROF_TO_EXTERNAL) { if (DUMP_HPROF_TO_EXTERNAL) {
System.gc() System.gc()
Environment.getExternalStorageDirectory() Environment.getExternalStorageDirectory()
.resolve("${AndroidPackageParsingTestBase::class.java.simpleName}.hprof") .resolve(
"${AndroidPackageParsingTestBase::class.java.simpleName}.hprof")
.absolutePath .absolutePath
.run(Debug::dumpHprofData) .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
}
} }
fun oldAppInfo(pkg: PackageParser.Package, flags: Int = 0): ApplicationInfo? { fun oldAppInfo(pkg: PackageParser.Package, flags: Int = 0): ApplicationInfo? {
@@ -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 // 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 // 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 // 2. the test must only verify fields that [PackageParser.Package] can actually fill, as