Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1d3bf70 authored by Adrian Roos's avatar Adrian Roos
Browse files

AndroidPackageParsingTestBase: Re-throw failures in setUpPackages in individual tests

Throwing in an @BeforeClass method breaks our test runner, due to
not reporting any results for the tests therein, leading to a difference
between actual and expected test counts.

The tool failure also obscured the fact that these tests
were already failing.

Bug: 153058196
Test: atest AndroidPackageInfoFlagBehaviorTest AndroidPackageParsingEquivalenceTest
Change-Id: Id0c1ebe2c99ff58451c1a1ccc20c6f9e355a725f
parent f0059d21
Loading
Loading
Loading
Loading
+30 −12
Original line number Diff line number Diff line
@@ -91,10 +91,14 @@ open class AndroidPackageParsingTestBase {

        lateinit var newPackages: List<AndroidPackage>

        var failureInBeforeClass: Throwable? = null

        @Suppress("ConstantConditionIf")
        @JvmStatic
        @BeforeClass
        fun setUpPackages() {
            failureInBeforeClass = null
            try {
                this.oldPackages = apks.map {
                    packageParser.parsePackage(it, PackageParser.PARSE_IS_SYSTEM_DIR, false)
                }
@@ -106,10 +110,17 @@ open class AndroidPackageParsingTestBase {
                if (DUMP_HPROF_TO_EXTERNAL) {
                    System.gc()
                    Environment.getExternalStorageDirectory()
                        .resolve("${AndroidPackageParsingTestBase::class.java.simpleName}.hprof")
                            .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
            }
        }

        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
    // 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