@@ -41,6 +41,10 @@ subroutine collect_manifest(testsuite)
4141 & new_unittest(" dependency-features-present" , test_dependency_features_present), &
4242 & new_unittest(" dependency-features-absent" , test_dependency_features_absent), &
4343 & new_unittest(" dependency-features-empty" , test_dependency_features_empty), &
44+ & new_unittest(" dependency-profile-present" , test_dependency_profile_present), &
45+ & new_unittest(" dependency-profile-absent" , test_dependency_profile_absent), &
46+ & new_unittest(" dependency-profile-features-conflict" , &
47+ & test_dependency_profile_features_conflict, should_fail= .true. ), &
4448 & new_unittest(" dependency-wrongkey" , test_dependency_wrongkey, should_fail= .true. ), &
4549 & new_unittest(" dependencies-empty" , test_dependencies_empty), &
4650 & new_unittest(" dependencies-typeerror" , test_dependencies_typeerror, should_fail= .true. ), &
@@ -1809,4 +1813,129 @@ subroutine test_features_demo_serialization(error)
18091813 end subroutine test_features_demo_serialization
18101814
18111815
1816+ ! > Test that a dependency with "profile" key is parsed correctly
1817+ subroutine test_dependency_profile_present (error )
1818+ ! > Error handling
1819+ type (error_t), allocatable , intent (out ) :: error
1820+
1821+ type (package_config_t) :: package
1822+ character (:), allocatable :: temp_file
1823+ integer :: unit, i, idx_dep0, idx_dep1
1824+
1825+ allocate (temp_file, source= get_temp_filename())
1826+
1827+ open (file= temp_file, newunit= unit)
1828+ write (unit, ' (a)' ) &
1829+ & ' name = "example"' , &
1830+ & ' version = "0.1.0"' , &
1831+ & ' [dependencies]' , &
1832+ & ' "dep0" = { path = "local/dep0", profile = "release" }' , &
1833+ & ' "dep1" = { path = "local/dep1" }'
1834+ close (unit)
1835+
1836+ call get_package_data(package, temp_file, error)
1837+ if (allocated (error)) return
1838+
1839+ if (.not. allocated (package% dependency)) then
1840+ call test_failed(error, ' No dependencies parsed from manifest' )
1841+ return
1842+ end if
1843+
1844+ idx_dep0 = 0 ; idx_dep1 = 0
1845+ do i = 1 , size (package% dependency)
1846+ select case (package% dependency(i)% name)
1847+ case (' dep0' ); idx_dep0 = i
1848+ case (' dep1' ); idx_dep1 = i
1849+ end select
1850+ end do
1851+
1852+ if (idx_dep0 == 0 .or. idx_dep1 == 0 ) then
1853+ call test_failed(error, ' Expected dependencies dep0/dep1 not found' )
1854+ return
1855+ end if
1856+
1857+ ! dep0: profile = "release"
1858+ if (.not. allocated (package% dependency(idx_dep0)% profile)) then
1859+ call test_failed(error, ' dep0 profile not allocated' )
1860+ return
1861+ end if
1862+ if (package% dependency(idx_dep0)% profile /= ' release' ) then
1863+ call test_failed(error, ' dep0 profile value mismatch, expected "release"' )
1864+ return
1865+ end if
1866+ ! dep0 should NOT have features allocated
1867+ if (allocated (package% dependency(idx_dep0)% features)) then
1868+ if (size (package% dependency(idx_dep0)% features) > 0 ) then
1869+ call test_failed(error, ' dep0 features should not be present when profile is used' )
1870+ return
1871+ end if
1872+ end if
1873+
1874+ ! dep1: no profile key -> should be NOT allocated
1875+ if (allocated (package% dependency(idx_dep1)% profile)) then
1876+ call test_failed(error, ' dep1 profile should be unallocated when key is absent' )
1877+ return
1878+ end if
1879+ end subroutine test_dependency_profile_present
1880+
1881+
1882+ ! > Ensure a dependency without "profile" key leaves it unallocated
1883+ subroutine test_dependency_profile_absent (error )
1884+ ! > Error handling
1885+ type (error_t), allocatable , intent (out ) :: error
1886+
1887+ type (package_config_t) :: package
1888+ character (:), allocatable :: temp_file
1889+ integer :: unit, i
1890+
1891+ allocate (temp_file, source= get_temp_filename())
1892+
1893+ open (file= temp_file, newunit= unit)
1894+ write (unit, ' (a)' ) &
1895+ & ' name = "example"' , &
1896+ & ' [dependencies]' , &
1897+ & ' "a" = { path = "a" }' , &
1898+ & ' "b" = { git = "https://example.org/b.git", branch = "main" }'
1899+ close (unit)
1900+
1901+ call get_package_data(package, temp_file, error)
1902+ if (allocated (error)) return
1903+
1904+ if (.not. allocated (package% dependency)) then
1905+ call test_failed(error, ' No dependencies parsed from manifest' )
1906+ return
1907+ end if
1908+
1909+ do i = 1 , size (package% dependency)
1910+ if (allocated (package% dependency(i)% profile)) then
1911+ call test_failed(error, ' profile should be unallocated when not specified' )
1912+ return
1913+ end if
1914+ end do
1915+ end subroutine test_dependency_profile_absent
1916+
1917+
1918+ ! > Specifying both "features" and "profile" should be an error
1919+ subroutine test_dependency_profile_features_conflict (error )
1920+ ! > Error handling
1921+ type (error_t), allocatable , intent (out ) :: error
1922+
1923+ type (package_config_t) :: package
1924+ character (:), allocatable :: temp_file
1925+ integer :: unit
1926+
1927+ allocate (temp_file, source= get_temp_filename())
1928+
1929+ open (file= temp_file, newunit= unit)
1930+ write (unit, ' (a)' ) &
1931+ & ' name = "example"' , &
1932+ & ' [dependencies]' , &
1933+ & ' "bad" = { path = "bad", features = ["f1"], profile = "release" }'
1934+ close (unit)
1935+
1936+ call get_package_data(package, temp_file, error)
1937+
1938+ end subroutine test_dependency_profile_features_conflict
1939+
1940+
18121941end module test_manifest
0 commit comments