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> lateinit var newPackages: List<AndroidPackage>
var failureInBeforeClass: Throwable? = null
@Suppress("ConstantConditionIf") @Suppress("ConstantConditionIf")
@JvmStatic @JvmStatic
@BeforeClass @BeforeClass
fun setUpPackages() { fun setUpPackages() {
this.oldPackages = apks.map { failureInBeforeClass = null
packageParser.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false) try {
} this.oldPackages = apks.map {
packageParser.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false)
}
this.newPackages = apks.map { this.newPackages = apks.map {
packageParser2.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false) packageParser2.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false)
} }
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(
.absolutePath "${AndroidPackageParsingTestBase::class.java.simpleName}.hprof")
.run(Debug::dumpHprofData) .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 // 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