fix(tester): parse bare Android package identity
This commit is contained in:
@@ -304,6 +304,10 @@ def android_identity(path: Path, context: RuntimeContext) -> str:
|
|||||||
result = run_command(command, context=context)
|
result = run_command(command, context=context)
|
||||||
if result.code == 0:
|
if result.code == 0:
|
||||||
match = re.search(r"(?:name|application-id)[=:]['\"]?([A-Za-z0-9_.]+)", result.output)
|
match = re.search(r"(?:name|application-id)[=:]['\"]?([A-Za-z0-9_.]+)", result.output)
|
||||||
|
if not match:
|
||||||
|
# apkanalyzer manifest application-id prints the bare package
|
||||||
|
# name, while aapt/aapt2 print a package: name=... record.
|
||||||
|
match = re.fullmatch(r"\s*([A-Za-z0-9_.]+)\s*", result.output)
|
||||||
if match:
|
if match:
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
raise EnvironmentFailure("APK 身份读取失败;请检查 Android SDK build-tools")
|
raise EnvironmentFailure("APK 身份读取失败;请检查 Android SDK build-tools")
|
||||||
|
|||||||
@@ -146,6 +146,16 @@ matrix:
|
|||||||
self.assertTrue(result["verified"])
|
self.assertTrue(result["verified"])
|
||||||
self.assertTrue(any("install" in call for call in calls))
|
self.assertTrue(any("install" in call for call in calls))
|
||||||
|
|
||||||
|
def test_android_identity_accepts_bare_apkanalyzer_output(self):
|
||||||
|
with tempfile.TemporaryDirectory() as temp:
|
||||||
|
apk = Path(temp) / "app.apk"
|
||||||
|
apk.write_bytes(b"apk")
|
||||||
|
context = bundle.RuntimeContext(Path(temp))
|
||||||
|
with mock.patch.object(bundle.shutil, "which", side_effect=lambda name: "apkanalyzer" if name == "apkanalyzer" else None), mock.patch.object(
|
||||||
|
bundle, "run_command", return_value=bundle.CommandResult(0, "page.writes\n")
|
||||||
|
):
|
||||||
|
self.assertEqual(bundle.android_identity(apk, context), "page.writes")
|
||||||
|
|
||||||
def test_android_missing_device_is_environment_failure(self):
|
def test_android_missing_device_is_environment_failure(self):
|
||||||
context = bundle.RuntimeContext(Path("."))
|
context = bundle.RuntimeContext(Path("."))
|
||||||
with mock.patch.object(bundle.shutil, "which", return_value="/sdk/adb"), mock.patch.object(
|
with mock.patch.object(bundle.shutil, "which", return_value="/sdk/adb"), mock.patch.object(
|
||||||
|
|||||||
Reference in New Issue
Block a user