diff --git a/eng/common/scripts/job-matrix/job-matrix-functions.ps1 b/eng/common/scripts/job-matrix/job-matrix-functions.ps1 index d801c0527..102ea9d37 100644 --- a/eng/common/scripts/job-matrix/job-matrix-functions.ps1 +++ b/eng/common/scripts/job-matrix/job-matrix-functions.ps1 @@ -474,7 +474,7 @@ function GenerateFullMatrix( [Hashtable]$displayNamesLookup = @{} ) { # Handle when the config does not have a matrix specified (e.g. only the include field is specified) - if ($parameters.Count -eq 0) { + if (!$parameters) { return @() } diff --git a/eng/common/scripts/job-matrix/tests/job-matrix-functions.modification.tests.ps1 b/eng/common/scripts/job-matrix/tests/job-matrix-functions.modification.tests.ps1 index cd721c351..699b16229 100644 --- a/eng/common/scripts/job-matrix/tests/job-matrix-functions.modification.tests.ps1 +++ b/eng/common/scripts/job-matrix/tests/job-matrix-functions.modification.tests.ps1 @@ -404,4 +404,26 @@ Describe "Platform Matrix Replace" -Tag "replace" { $matrix[1].name | Should -Be "foo2_barReplacedBar2" $matrix[1].parameters.Bar | Should -Be "barReplacedBar2" } + + It "Should only fully match a string for replace" { + $matrixJson = @' +{ + "matrix": { + "Foo": [ "foo1", "foo2" ], + "Bar": "bar1" + } +} +'@ + + $importConfig = GetMatrixConfigFromJson $matrixJson + + $replace = @("Foo=foo/shouldNotReplaceFoo", "B=bar1/shouldNotReplaceBar") + $matrix = GenerateMatrix -config $importConfig -selectFromMatrixType "sparse" -replace $replace + + $matrix.Length | Should -Be 2 + $matrix[0].parameters.Foo | Should -Be "foo1" + $matrix[0].parameters.Bar | Should -Be "bar1" + $matrix[1].parameters.Foo | Should -Be "foo2" + $matrix[1].parameters.Bar | Should -Be "bar1" + } } diff --git a/eng/common/scripts/job-matrix/tests/job-matrix-functions.tests.ps1 b/eng/common/scripts/job-matrix/tests/job-matrix-functions.tests.ps1 index 500d3d363..d751fe86e 100644 --- a/eng/common/scripts/job-matrix/tests/job-matrix-functions.tests.ps1 +++ b/eng/common/scripts/job-matrix/tests/job-matrix-functions.tests.ps1 @@ -466,6 +466,40 @@ Describe "Platform Matrix Post Transformation" -Tag "transform" { $matrix[7].parameters.operatingSystem | Should -Be "windows-2019" $matrix[7].parameters.additionalArguments | Should -Be "--enableWindowsFoo" } + + It "Should parse a config with an empty base matrix" { + $matrixConfigForIncludeOnly = @" +{ + "include": [ + { + "operatingSystem": "windows-2019", + "framework": "net461" + } + ] +} +"@ + + $config = GetMatrixConfigFromJson $matrixConfigForIncludeOnly + [Array]$matrix = GenerateMatrix $config "all" + $matrix.Length | Should -Be 1 + $matrix[0].name | Should -Be "windows2019_net461" + } + + It "Should parse a config with an empty include" { + $matrixConfigForIncludeOnly = @" +{ + "matrix": { + "operatingSystem": "windows-2019", + "framework": "net461" + } +} +"@ + + $config = GetMatrixConfigFromJson $matrixConfigForIncludeOnly + [Array]$matrix = GenerateMatrix $config "all" + $matrix.Length | Should -Be 1 + $matrix[0].name | Should -Be "windows2019_net461" + } } Describe "Platform Matrix Generation With Object Fields" -Tag "objectfields" {