| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #!/usr/bin/env python3
- """
- Test script to verify that the execs object in MANIFEST.usm correctly reflects
- which scripts are actually present in the package.
- This tests the fix for the issue where "acquire" was always included in execs
- even when not generating an acquire script for local directories.
- """
- import json
- import tempfile
- import shutil
- from pathlib import Path
- from src.autusm.models import PackageInfo, BuildSystem, BuildSystemType
- from src.autusm.manifest import ManifestGenerator
- def test_execs_for_url():
- """Test that acquire is included in execs when processing a URL."""
- print("Testing execs for URL...")
-
- # Create package info with a URL (simulating URL processing)
- package_info = PackageInfo(
- name="test-package",
- version="1.0.0",
- summary="Test package for URL",
- url="https://example.com/test-package.tar.gz"
- )
-
- # Create build system
- build_system = BuildSystem(type=BuildSystemType.MAKE)
-
- # Generate manifest
- manifest_generator = ManifestGenerator()
- manifest = manifest_generator.generate(package_info, build_system)
-
- # Convert to dict to check the execs section
- manifest_dict = manifest.to_dict()
-
- # Check that acquire is included in execs
- assert "acquire" in manifest_dict["execs"], "acquire should be in execs for URLs"
- assert manifest_dict["execs"]["acquire"] == "scripts/acquire", "acquire path should be scripts/acquire"
-
- print("✓ URL test passed: acquire is included in execs")
- return True
- def test_execs_for_local_directory():
- """Test that acquire is NOT included in execs when processing a local directory."""
- print("Testing execs for local directory...")
-
- # Create package info without a URL (simulating local directory processing)
- package_info = PackageInfo(
- name="test-package",
- version="1.0.0",
- summary="Test package for local directory",
- url="" # Empty URL indicates local directory
- )
-
- # Create build system
- build_system = BuildSystem(type=BuildSystemType.MAKE)
-
- # Generate manifest
- manifest_generator = ManifestGenerator()
- manifest = manifest_generator.generate(package_info, build_system)
-
- # Convert to dict to check the execs section
- manifest_dict = manifest.to_dict()
-
- # Check that acquire is NOT included in execs
- assert "acquire" not in manifest_dict["execs"], "acquire should NOT be in execs for local directories"
-
- print("✓ Local directory test passed: acquire is NOT included in execs")
- return True
- def test_manifest_json_output():
- """Test the actual JSON output to ensure it's correct."""
- print("Testing manifest JSON output...")
-
- # Create a temporary directory for testing
- with tempfile.TemporaryDirectory() as temp_dir:
- temp_path = Path(temp_dir)
-
- # Test 1: URL case
- print("\n1. Testing URL case JSON output:")
- url_package_info = PackageInfo(
- name="url-test",
- version="1.0.0",
- summary="Test URL package",
- url="https://example.com/url-test.tar.gz"
- )
- build_system = BuildSystem(type=BuildSystemType.CMAKE)
-
- manifest_generator = ManifestGenerator()
- url_manifest = manifest_generator.generate(url_package_info, build_system)
- url_manifest_dict = url_manifest.to_dict()
-
- print(json.dumps(url_manifest_dict["execs"], indent=2))
- assert "acquire" in url_manifest_dict["execs"]
-
- # Test 2: Local directory case
- print("\n2. Testing local directory case JSON output:")
- local_package_info = PackageInfo(
- name="local-test",
- version="1.0.0",
- summary="Test local package",
- url="" # Empty URL
- )
-
- local_manifest = manifest_generator.generate(local_package_info, build_system)
- local_manifest_dict = local_manifest.to_dict()
-
- print(json.dumps(local_manifest_dict["execs"], indent=2))
- assert "acquire" not in local_manifest_dict["execs"]
-
- print("✓ JSON output test passed")
- return True
- def main():
- """Run all tests."""
- print("Testing execs fix for manifest generation...\n")
-
- try:
- test_execs_for_url()
- test_execs_for_local_directory()
- test_manifest_json_output()
-
- print("\n✅ All tests passed! The fix is working correctly.")
- print("\nSummary:")
- print("- For URLs: acquire script is included in execs")
- print("- For local directories: acquire script is NOT included in execs")
-
- except AssertionError as e:
- print(f"\n❌ Test failed: {e}")
- return 1
- except Exception as e:
- print(f"\n❌ Unexpected error: {e}")
- import traceback
- traceback.print_exc()
- return 1
-
- return 0
- if __name__ == "__main__":
- exit(main())
|