diff --git a/tools/devops/automation/scripts/TestConfiguration.Tests.ps1 b/tools/devops/automation/scripts/TestConfiguration.Tests.ps1 index 574f3c5b9ec2..092cc23a6c6a 100644 --- a/tools/devops/automation/scripts/TestConfiguration.Tests.ps1 +++ b/tools/devops/automation/scripts/TestConfiguration.Tests.ps1 @@ -335,4 +335,75 @@ Describe 'Get-TestConfiguration' { "@ } + Context 'macOS tests excluded when platforms disabled' { + It "excludes mac tests when neither macOS nor MacCatalyst is enabled" { + $macTestConfigs = @" +[ + { + "label": "cecil", + "splitByPlatforms": "false", + "testPrefix": "simulator_tests" + }, + { + "label": "mac_monterey", + "displayName": "Tests on macOS Monterey (12)", + "splitByPlatforms": "false", + "testPrefix": "mac_12_m1", + "testStage": "mac_12_m1", + "isMacTest": true + } +] +"@ + $supportedPlatforms = @" +[ + { "platform": "iOS" }, + { "platform": "tvOS" } +] +"@ + # Only tvOS enabled — no macOS or MacCatalyst + $result = Get-TestConfiguration ` + -TestConfigurations $macTestConfigs ` + -SupportedPlatforms $supportedPlatforms ` + -EnabledPlatforms "tvOS" ` + -TestsLabels "test-labels" ` + -StatusContext "ctx" ` + -StageFilter "" + + $parsed = $result | ConvertFrom-Json + # cecil should be present, mac_monterey should not + $parsed.cecil | Should -Not -BeNullOrEmpty + $parsed.PSObject.Properties.Name | Should -Not -Contain "mac_monterey" + } + + It "includes mac tests when macOS is enabled" { + $macTestConfigs = @" +[ + { + "label": "mac_monterey", + "displayName": "Tests on macOS Monterey (12)", + "splitByPlatforms": "false", + "testPrefix": "mac_12_m1", + "testStage": "mac_12_m1", + "isMacTest": true + } +] +"@ + $supportedPlatforms = @" +[ + { "platform": "macOS" } +] +"@ + $result = Get-TestConfiguration ` + -TestConfigurations $macTestConfigs ` + -SupportedPlatforms $supportedPlatforms ` + -EnabledPlatforms "macOS" ` + -TestsLabels "test-labels" ` + -StatusContext "ctx" ` + -StageFilter "" + + $parsed = $result | ConvertFrom-Json + $parsed.mac_monterey | Should -Not -BeNullOrEmpty + } + } + } diff --git a/tools/devops/automation/scripts/TestConfiguration.psm1 b/tools/devops/automation/scripts/TestConfiguration.psm1 index 148db8f7e1eb..55d91a2f93e6 100644 --- a/tools/devops/automation/scripts/TestConfiguration.psm1 +++ b/tools/devops/automation/scripts/TestConfiguration.psm1 @@ -42,6 +42,15 @@ class TestConfiguration { Write-Host "Test $label with testStage '$testStage' is included, because there's no stage filter set" } + # Skip macOS tests if neither macOS nor MacCatalyst platforms are enabled + if ($config.isMacTest -eq "true" -or $config.isMacTest -eq $true) { + $hasMacPlatform = ($this.enabledPlatforms -contains "macOS") -or ($this.enabledPlatforms -contains "MacCatalyst") + if (-not $hasMacPlatform) { + Write-Host "Skipping mac test $label - neither macOS nor MacCatalyst platforms are enabled" + continue + } + } + $vars = [ordered]@{} # set common variables $vars["LABEL"] = $label diff --git a/tools/devops/automation/templates/mac/stage.yml b/tools/devops/automation/templates/mac/stage.yml index bbe10a52975f..a7fc6657df50 100644 --- a/tools/devops/automation/templates/mac/stage.yml +++ b/tools/devops/automation/templates/mac/stage.yml @@ -58,7 +58,7 @@ stages: dependsOn: - build_macos_tests - configure_build - condition: and(succeeded(), eq(stageDependencies.configure_build.outputs['configure.decisions.RUN_MAC_TESTS'], 'true')) + condition: and(succeeded(), eq(dependencies.configure_build.outputs['configure.decisions.RUN_MAC_TESTS'], 'true')) variables: GITHUB_FAILURE_COMMENT_FILE: $(System.DefaultWorkingDirectory)/github-comment-file.md