From 139a76890aecd4a78d42f8d06691b13430479931 Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Tue, 23 Mar 2021 12:00:57 -0400 Subject: [PATCH 1/2] Handle null values when generating display names --- .../job-matrix/job-matrix-functions.ps1 | 7 ++- .../tests/job-matrix-functions.tests.ps1 | 61 ++++++++++++++----- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/eng/common/scripts/job-matrix/job-matrix-functions.ps1 b/eng/common/scripts/job-matrix/job-matrix-functions.ps1 index 102ea9d373c1..07ac4030ef60 100644 --- a/eng/common/scripts/job-matrix/job-matrix-functions.ps1 +++ b/eng/common/scripts/job-matrix/job-matrix-functions.ps1 @@ -65,9 +65,12 @@ class MatrixParameter { [String]CreateDisplayName([Hashtable]$displayNamesLookup) { - $displayName = $this.Value.ToString() - if ($this.Value -is [PSCustomObject]) { + if ($null -eq $this.Value) { + $displayName = "" + } elseif ($this.Value -is [PSCustomObject]) { $displayName = $this.Name + } else { + $displayName = $this.Value.ToString() } if ($displayNamesLookup.ContainsKey($displayName)) { 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 d751fe86e1e6..d2deb82c7e71 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 @@ -324,22 +324,6 @@ Describe "Platform Matrix Generation" -Tag "generate" { $element.name | Should -Be "macOS1015_netcoreapp21_withFoo" } - It "Should enforce valid display name format" { - $generateconfig.displayNamesLookup["net461"] = '123.Some.456.Invalid_format-name$(foo)' - $generateconfig.displayNamesLookup["netcoreapp2.1"] = (New-Object string[] 150) -join "a" - $dimensions = GetMatrixDimensions $generateConfig.matrixParameters - $matrix = GenerateFullMatrix $generateconfig.matrixParameters $generateconfig.displayNamesLookup - - $element = GetNdMatrixElement @(0, 0, 0) $matrix $dimensions - $element.name | Should -Be "windows2019_123some456invalid_formatnamefoo" - - $element = GetNdMatrixElement @(1, 1, 1) $matrix $dimensions - $element.name.Length | Should -Be 100 - # The withfoo part of the argument gets cut off at the character limit - $element.name | Should -BeLike "ubuntu1804_aaaaaaaaaaaaaaaaa*" - } - - It "Should initialize an N-dimensional matrix from all parameter permutations" { $dimensions = GetMatrixDimensions $generateConfig.matrixParameters $matrix = GenerateFullMatrix $generateConfig.matrixParameters $generateConfig.displayNamesLookup @@ -587,3 +571,48 @@ Describe "Platform Matrix Generation With Object Fields" -Tag "objectfields" { $matrix[4].parameters.Count | Should -Be 3 } } + +Describe "Platform Matrix Display Names" -Tag "displaynames" { + BeforeEach { + $matrixConfigForGenerate = @" +{ + "displayNames": { + "--enableFoo": "withfoo" + }, + "matrix": { + "operatingSystem": "ubuntu-18.04", + "framework": [ + "net461", + "netcoreapp2.1" + ], + "TestNullField": null, + "TestObjectField": { + "TestObjectValueName": { + "foo": "bar", + "baz": "qux" + } + } + } +} +"@ + $generateConfig = GetMatrixConfigFromJson $matrixConfigForGenerate + } + + It "Should enforce valid display name format" { + $generateconfig.displayNamesLookup["net461"] = '123.Some.456.Invalid_format-name$(foo)' + $generateconfig.displayNamesLookup["netcoreapp2.1"] = (New-Object string[] 150) -join "a" + $dimensions = GetMatrixDimensions $generateConfig.matrixParameters + $matrix = GenerateFullMatrix $generateconfig.matrixParameters $generateconfig.displayNamesLookup + + $matrix[0].name | Should -Be "ubuntu1804_123some456invalid_formatnamefoo_TestObjectValueName" + + $matrix[1].name.Length | Should -Be 100 + # The withfoo part of the argument gets cut off at the character limit + $matrix[1].name | Should -BeLike "ubuntu1804_aaaaaaaaaaaaaaaaa*" + } + + It "Should generate a display name with null and object values" { + $matrix = GenerateMatrix $generateConfig "sparse" + $matrix[0].name | Should -Be "ubuntu1804_net461_TestObjectValueName" + } +} From 25ea33b35e6e43ce35dea76f19f961bb49159824 Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Tue, 23 Mar 2021 12:35:33 -0400 Subject: [PATCH 2/2] Fix issue processing matrices where the base matrix is only an import --- .../job-matrix/job-matrix-functions.ps1 | 2 +- ...ob-matrix-functions.modification.tests.ps1 | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/eng/common/scripts/job-matrix/job-matrix-functions.ps1 b/eng/common/scripts/job-matrix/job-matrix-functions.ps1 index 07ac4030ef60..adcdaf4bd963 100644 --- a/eng/common/scripts/job-matrix/job-matrix-functions.ps1 +++ b/eng/common/scripts/job-matrix/job-matrix-functions.ps1 @@ -350,7 +350,7 @@ function ProcessImport([MatrixParameter[]]$matrix, [String]$selection, [Hashtabl $importPath = $_.Value } } - if (!$matrix -or !$importPath) { + if ((!$matrix -and !$importPath) -or !$importPath) { return $matrix, @() } 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 699b16229558..676968f9b7a6 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 @@ -86,6 +86,49 @@ Describe "Platform Matrix nonSparse" -Tag "nonsparse" { } Describe "Platform Matrix Import" -Tag "import" { + It "Should generate a sparse matrix where the entire base matrix is imported" { + $matrixJson = @' +{ + "matrix": { + "$IMPORT": "./test-import-matrix.json" + }, + "include": [ + { + "fooinclude": "fooinclude" + } + ] +} +'@ + + $expectedMatrix = @' +[ + { + "parameters": { "Foo": "foo1", "Bar": "bar1" }, + "name": "foo1_bar1" + }, + { + "parameters": { "Foo": "foo2", "Bar": "bar2" }, + "name": "foo2_bar2" + }, + { + "parameters": { "Baz": "importedBaz" }, + "name": "importedBazName" + }, + { + "parameters": { "fooinclude": "fooinclude" }, + "name": "fooinclude" + }, +] +'@ + + $importConfig = GetMatrixConfigFromJson $matrixJson + $matrix = GenerateMatrix $importConfig "sparse" + $expected = $expectedMatrix | ConvertFrom-Json -AsHashtable + + $matrix.Length | Should -Be 4 + CompareMatrices $matrix $expected + } + It "Should generate a matrix with nonSparseParameters and an imported sparse matrix" { $matrixJson = @' {