@@ -442,3 +442,50 @@ class SPDX30Check(SPDX3CheckBase, OESelftestTestCase):
f"External references {'found' if found_external_refs else 'not found'} "
f"in SPDX output (defensive handling verified)"
)
+
+ def test_version_extraction_patterns(self):
+ """
+ Test that version extraction works for various package formats.
+
+ This test verifies that version patterns correctly extract versions from:
+ 1. Rust crates (.crate files)
+ 2. Go modules
+ 3. Python packages (PyPI)
+ 4. Generic tarball formats
+ 5. Git revision hashes
+ """
+ # Build a package that has dependencies with various formats
+ objset = self.check_recipe_spdx(
+ "tar",
+ "{DEPLOY_DIR_SPDX}/{SSTATE_PKGARCH}/recipes/recipe-tar.spdx.json",
+ )
+
+ # Collect all packages with versions
+ packages_with_versions = []
+ for pkg in objset.foreach_type(oe.spdx30.software_Package):
+ if hasattr(pkg, 'version') and pkg.version:
+ packages_with_versions.append((pkg.name, pkg.version))
+
+ self.assertGreater(
+ len(packages_with_versions), 0,
+ "Should find packages with extracted versions"
+ )
+
+ self.logger.info(f"Found {len(packages_with_versions)} packages with versions")
+
+ # Log some examples for debugging
+ for name, version in packages_with_versions[:5]:
+ self.logger.info(f" {name}: {version}")
+
+ # Verify that versions follow expected patterns
+ for name, version in packages_with_versions:
+ # Version should not be empty
+ self.assertIsNotNone(version)
+ self.assertNotEqual(version, "")
+
+ # Version should contain digits
+ self.assertRegex(
+ version,
+ r'\d',
+ f"Version '{version}' for package '{name}' should contain digits"
+ )