1 Import-Module Pester 2 3 BeforeAll { 4 . $PSScriptRoot/../job-matrix-functions.ps1 5 6 $matrixConfig = @" 7 { 8 "displayNames": { 9 "--enableFoo": "withfoo" 10 }, 11 "matrix": { 12 "operatingSystem": [ 13 "windows-2019", 14 "ubuntu-18.04", 15 "macOS-10.15" 16 ], 17 "framework": [ 18 "net461", 19 "netcoreapp2.1" 20 ], 21 "additionalArguments": [ 22 "", 23 "--enableFoo" 24 ] 25 }, 26 "include": [ 27 { 28 "operatingSystem": "windows-2019", 29 "framework": ["net461", "netcoreapp2.1", "net50"], 30 "additionalArguments": "--enableWindowsFoo" 31 } 32 ], 33 "exclude": [ 34 { 35 "operatingSystem": "windows-2019", 36 "framework": "net461" 37 }, 38 { 39 "operatingSystem": "macOS-10.15", 40 "framework": "netcoreapp2.1" 41 }, 42 { 43 "operatingSystem": ["macOS-10.15", "ubuntu-18.04"], 44 "additionalArguments": "--enableFoo" 45 } 46 ] 47 } 48 "@ 49 } 50 51 Describe "Matrix-Lookup" -Tag "lookup" { 52 It "Should navigate a 2d matrix: <row> <col>" -TestCases @( 53 @{ row = 0; col = 0; expected = 1 }, 54 @{ row = 0; col = 1; expected = 2 }, 55 @{ row = 1; col = 0; expected = 3 }, 56 @{ row = 1; col = 1; expected = 4 } 57 ) { 58 $dimensions = @(2, 2) 59 $matrix = @( 60 1, 2, 3, 4 61 ) 62 GetNdMatrixElement @($row, $col) $matrix $dimensions | Should -Be $expected 63 } 64 65 It "Should navigate a 3d matrix: <z> <row> <col>" -TestCases @( 66 @{ z = 0; row = 0; col = 0; expected = 1 } 67 @{ z = 0; row = 0; col = 1; expected = 2 } 68 @{ z = 0; row = 1; col = 0; expected = 3 } 69 @{ z = 0; row = 1; col = 1; expected = 4 } 70 @{ z = 1; row = 0; col = 0; expected = 5 } 71 @{ z = 1; row = 0; col = 1; expected = 6 } 72 @{ z = 1; row = 1; col = 0; expected = 7 } 73 @{ z = 1; row = 1; col = 1; expected = 8 } 74 ) { 75 $dimensions = @(2, 2, 2) 76 $matrix = @( 77 1, 2, 3, 4, 5, 6, 7, 8 78 ) 79 GetNdMatrixElement @($z, $row, $col) $matrix $dimensions | Should -Be $expected 80 } 81 82 It "Should navigate a 4d matrix: <t> <z> <row> <col>" -TestCases @( 83 @{ t = 0; z = 0; row = 0; col = 0; expected = 1 } 84 @{ t = 0; z = 0; row = 0; col = 1; expected = 2 } 85 @{ t = 0; z = 0; row = 1; col = 0; expected = 3 } 86 @{ t = 0; z = 0; row = 1; col = 1; expected = 4 } 87 @{ t = 0; z = 1; row = 0; col = 0; expected = 5 } 88 @{ t = 0; z = 1; row = 0; col = 1; expected = 6 } 89 @{ t = 0; z = 1; row = 1; col = 0; expected = 7 } 90 @{ t = 0; z = 1; row = 1; col = 1; expected = 8 } 91 @{ t = 1; z = 0; row = 0; col = 0; expected = 9 } 92 @{ t = 1; z = 0; row = 0; col = 1; expected = 10 } 93 @{ t = 1; z = 0; row = 1; col = 0; expected = 11 } 94 @{ t = 1; z = 0; row = 1; col = 1; expected = 12 } 95 @{ t = 1; z = 1; row = 0; col = 0; expected = 13 } 96 @{ t = 1; z = 1; row = 0; col = 1; expected = 14 } 97 @{ t = 1; z = 1; row = 1; col = 0; expected = 15 } 98 @{ t = 1; z = 1; row = 1; col = 1; expected = 16 } 99 ) { 100 $dimensions = @(2, 2, 2, 2) 101 $matrix = @( 102 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 103 ) 104 GetNdMatrixElement @($t, $z, $row, $col) $matrix $dimensions | Should -Be $expected 105 } 106 107 It "Should navigate a 4d matrix: <t> <z> <row> <col>" -TestCases @( 108 @{ t = 0; z = 0; row = 0; col = 0; expected = 1 } 109 @{ t = 0; z = 0; row = 0; col = 1; expected = 2 } 110 @{ t = 0; z = 0; row = 0; col = 2; expected = 3 } 111 @{ t = 0; z = 0; row = 0; col = 3; expected = 4 } 112 113 @{ t = 0; z = 0; row = 1; col = 0; expected = 5 } 114 @{ t = 0; z = 0; row = 1; col = 1; expected = 6 } 115 @{ t = 0; z = 0; row = 1; col = 2; expected = 7 } 116 @{ t = 0; z = 0; row = 1; col = 3; expected = 8 } 117 118 @{ t = 0; z = 1; row = 0; col = 0; expected = 9 } 119 @{ t = 0; z = 1; row = 0; col = 1; expected = 10 } 120 @{ t = 0; z = 1; row = 0; col = 2; expected = 11 } 121 @{ t = 0; z = 1; row = 0; col = 3; expected = 12 } 122 123 @{ t = 0; z = 1; row = 1; col = 0; expected = 13 } 124 @{ t = 0; z = 1; row = 1; col = 1; expected = 14 } 125 @{ t = 0; z = 1; row = 1; col = 2; expected = 15 } 126 @{ t = 0; z = 1; row = 1; col = 3; expected = 16 } 127 ) { 128 $dimensions = @(1, 2, 2, 4) 129 $matrix = @( 130 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 131 ) 132 GetNdMatrixElement @($t, $z, $row, $col) $matrix $dimensions | Should -Be $expected 133 } 134 135 # Skipping since by default wrapping behavior on indexing is disabled. 136 # Keeping here in case we want to enable it. 137 It -Skip "Should handle index wrapping: <row> <col>" -TestCases @( 138 @{ row = 2; col = 2; expected = 1 } 139 @{ row = 2; col = 3; expected = 2 } 140 @{ row = 4; col = 4; expected = 1 } 141 @{ row = 4; col = 5; expected = 2 } 142 ) { 143 $dimensions = @(2, 2) 144 $matrix = @( 145 1, 2, 3, 4 146 ) 147 GetNdMatrixElement @($row, $col) $matrix $dimensions | Should -Be $expected 148 } 149 } 150 151 Describe "Matrix-Reverse-Lookup" -Tag "lookup" { 152 It "Should lookup a 2d matrix index: <index>" -TestCases @( 153 @{ index = 0; expected = @(0,0) } 154 @{ index = 1; expected = @(0,1) } 155 @{ index = 2; expected = @(1,0) } 156 @{ index = 3; expected = @(1,1) } 157 ) { 158 $dimensions = @(2, 2) 159 $matrix = @(1, 2, 3, 4) 160 GetNdMatrixElement $expected $matrix $dimensions | Should -Be $matrix[$index] 161 GetNdMatrixIndex $index $dimensions | Should -Be $expected 162 } 163 164 It "Should lookup a 3d matrix index: <index>" -TestCases @( 165 @{ index = 0; expected = @(0,0,0) } 166 @{ index = 1; expected = @(0,0,1) } 167 @{ index = 2; expected = @(0,1,0) } 168 @{ index = 3; expected = @(0,1,1) } 169 170 @{ index = 4; expected = @(1,0,0) } 171 @{ index = 5; expected = @(1,0,1) } 172 @{ index = 6; expected = @(1,1,0) } 173 @{ index = 7; expected = @(1,1,1) } 174 ) { 175 $dimensions = @(2, 2, 2) 176 $matrix = @(0, 1, 2, 3, 4, 5, 6, 7) 177 GetNdMatrixElement $expected $matrix $dimensions | Should -Be $matrix[$index] 178 GetNdMatrixIndex $index $dimensions | Should -Be $expected 179 } 180 181 It "Should lookup a 3d matrix index: <index>" -TestCases @( 182 @{ index = 0; expected = @(0,0,0) } 183 @{ index = 1; expected = @(0,0,1) } 184 @{ index = 2; expected = @(0,0,2) } 185 186 @{ index = 3; expected = @(0,1,0) } 187 @{ index = 4; expected = @(0,1,1) } 188 @{ index = 5; expected = @(0,1,2) } 189 190 @{ index = 6; expected = @(1,0,0) } 191 @{ index = 7; expected = @(1,0,1) } 192 @{ index = 8; expected = @(1,0,2) } 193 194 @{ index = 9; expected = @(1,1,0) } 195 @{ index = 10; expected = @(1,1,1) } 196 @{ index = 11; expected = @(1,1,2) } 197 ) { 198 $dimensions = @(2, 2, 3) 199 $matrix = @(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) 200 GetNdMatrixElement $expected $matrix $dimensions | Should -Be $matrix[$index] 201 GetNdMatrixIndex $index $dimensions | Should -Be $expected 202 } 203 204 It "Should lookup a 3d matrix index: <index>" -TestCases @( 205 @{ index = 0; expected = @(0,0,0) } 206 @{ index = 1; expected = @(0,0,1) } 207 @{ index = 2; expected = @(0,1,0) } 208 @{ index = 3; expected = @(0,1,1) } 209 210 @{ index = 4; expected = @(1,0,0) } 211 @{ index = 5; expected = @(1,0,1) } 212 @{ index = 6; expected = @(1,1,0) } 213 @{ index = 7; expected = @(1,1,1) } 214 215 @{ index = 8; expected = @(2,0,0) } 216 @{ index = 9; expected = @(2,0,1) } 217 @{ index = 10; expected = @(2,1,0) } 218 @{ index = 11; expected = @(2,1,1) } 219 ) { 220 $dimensions = @(3, 2, 2) 221 $matrix = @(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) 222 GetNdMatrixElement $expected $matrix $dimensions | Should -Be $matrix[$index] 223 GetNdMatrixIndex $index $dimensions | Should -Be $expected 224 } 225 226 It "Should lookup a 4d matrix index: <index>" -TestCases @( 227 @{ index = 0; expected = @(0,0,0,0) } 228 @{ index = 1; expected = @(0,0,0,1) } 229 @{ index = 2; expected = @(0,0,0,2) } 230 @{ index = 3; expected = @(0,0,0,3) } 231 232 @{ index = 4; expected = @(0,0,1,0) } 233 @{ index = 5; expected = @(0,0,1,1) } 234 @{ index = 6; expected = @(0,0,1,2) } 235 @{ index = 7; expected = @(0,0,1,3) } 236 237 @{ index = 8; expected = @(0,1,0,0) } 238 @{ index = 9; expected = @(0,1,0,1) } 239 @{ index = 10; expected = @(0,1,0,2) } 240 @{ index = 11; expected = @(0,1,0,3) } 241 242 @{ index = 12; expected = @(0,1,1,0) } 243 @{ index = 13; expected = @(0,1,1,1) } 244 @{ index = 14; expected = @(0,1,1,2) } 245 @{ index = 15; expected = @(0,1,1,3) } 246 ) { 247 $dimensions = @(1, 2, 2, 4) 248 $matrix = @(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) 249 GetNdMatrixElement $expected $matrix $dimensions | Should -Be $matrix[$index] 250 GetNdMatrixIndex $index $dimensions | Should -Be $expected 251 } 252 } 253 254 Describe 'Matrix-Set' -Tag "set" { 255 It "Should set a matrix element" -TestCases @( 256 @{ value = "set"; index = @(0,0,0,0); arrayIndex = 0 } 257 @{ value = "ones"; index = @(0,1,1,1); arrayIndex = 13 } 258 ) { 259 $dimensions = @(1, 2, 2, 4) 260 $matrix = @(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) 261 262 SetNdMatrixElement $value $index $matrix $dimensions 263 $matrix[$arrayIndex] | Should -Be $value 264 } 265 } 266 267 Describe "Platform Matrix Generation" -Tag "generate" { 268 BeforeEach { 269 $matrixConfigForGenerate = @" 270 { 271 "displayNames": { 272 "--enableFoo": "withfoo" 273 }, 274 "matrix": { 275 "operatingSystem": [ 276 "windows-2019", 277 "ubuntu-18.04", 278 "macOS-10.15" 279 ], 280 "framework": [ 281 "net461", 282 "netcoreapp2.1" 283 ], 284 "additionalArguments": [ 285 "", 286 "--enableFoo" 287 ] 288 }, 289 "include": [ 290 { 291 "operatingSystem": "windows-2019", 292 "framework": "net461", 293 "additionalTestArguments": "/p:UseProjectReferenceToAzureClients=true" 294 } 295 ], 296 "exclude": [ 297 { 298 "foo": "bar" 299 }, 300 { 301 "foo2": "bar2" 302 } 303 ] 304 } 305 "@ 306 $generateConfig = GetMatrixConfigFromJson $matrixConfigForGenerate 307 } 308 309 It "Should get matrix dimensions from Nd parameters" { 310 GetMatrixDimensions $generateConfig.matrixParameters | Should -Be 3, 2, 2 311 } 312 313 It "Should use name overrides from displayNames" { 314 $dimensions = GetMatrixDimensions $generateConfig.matrixParameters 315 $matrix = GenerateFullMatrix $generateConfig.matrixParameters $generateconfig.displayNamesLookup 316 317 $element = GetNdMatrixElement @(0, 0, 0) $matrix $dimensions 318 $element.name | Should -Be "windows2019_net461" 319 320 $element = GetNdMatrixElement @(1, 1, 1) $matrix $dimensions 321 $element.name | Should -Be "ubuntu1804_netcoreapp21_withFoo" 322 323 $element = GetNdMatrixElement @(2, 1, 1) $matrix $dimensions 324 $element.name | Should -Be "macOS1015_netcoreapp21_withFoo" 325 } 326 327 It "Should initialize an N-dimensional matrix from all parameter permutations" { 328 $dimensions = GetMatrixDimensions $generateConfig.matrixParameters 329 $matrix = GenerateFullMatrix $generateConfig.matrixParameters $generateConfig.displayNamesLookup 330 $matrix.Count | Should -Be 12 331 332 $element = $matrix[0].parameters 333 $element.operatingSystem | Should -Be "windows-2019" 334 $element.framework | Should -Be "net461" 335 $element.additionalArguments | Should -Be "" 336 337 $element = GetNdMatrixElement @(1, 1, 1) $matrix $dimensions 338 $element.parameters.operatingSystem | Should -Be "ubuntu-18.04" 339 $element.parameters.framework | Should -Be "netcoreapp2.1" 340 $element.parameters.additionalArguments | Should -Be "--enableFoo" 341 342 $element = GetNdMatrixElement @(2, 1, 1) $matrix $dimensions 343 $element.parameters.operatingSystem | Should -Be "macOS-10.15" 344 $element.parameters.framework | Should -Be "netcoreapp2.1" 345 $element.parameters.additionalArguments | Should -Be "--enableFoo" 346 } 347 348 It "Should initialize a sparse matrix from an N-dimensional matrix" -TestCases @( 349 @{ i = 0; name = "windows2019_net461"; operatingSystem = "windows-2019"; framework = "net461"; additionalArguments = ""; } 350 @{ i = 1; name = "ubuntu1804_netcoreapp21_withfoo"; operatingSystem = "ubuntu-18.04"; framework = "netcoreapp2.1"; additionalArguments = "--enableFoo"; } 351 @{ i = 2; name = "macOS1015_net461"; operatingSystem = "macOS-10.15"; framework = "net461"; additionalArguments = ""; } 352 ) { 353 $sparseMatrix = GenerateSparseMatrix $generateConfig.matrixParameters $generateConfig.displayNamesLookup 354 $dimensions = GetMatrixDimensions $generateConfig.matrixParameters 355 $size = ($dimensions | Measure-Object -Maximum).Maximum 356 $sparseMatrix.Count | Should -Be $size 357 358 $sparseMatrix[$i].name | Should -Be $name 359 $element = $sparseMatrix[$i].parameters 360 $element.operatingSystem | Should -Be $operatingSystem 361 $element.framework | Should -Be $framework 362 $element.additionalArguments | Should -Be $additionalArguments 363 } 364 365 It "Should generate a sparse matrix from an N-dimensional matrix config" { 366 $sparseMatrix = GenerateMatrix $generateConfig "sparse" 367 $sparseMatrix.Length | Should -Be 4 368 } 369 370 It "Should initialize a full matrix from an N-dimensional matrix config" { 371 $matrix = GenerateMatrix $generateConfig "all" 372 $matrix.Length | Should -Be 13 373 } 374 } 375 376 Describe "Config File Object Conversion" -Tag "convert" { 377 BeforeEach { 378 $config = GetMatrixConfigFromJson $matrixConfig 379 } 380 381 It "Should convert a matrix config" { 382 $config.matrixParameters[0].Name | Should -Be "operatingSystem" 383 $config.matrixParameters[0].Flatten()[0].Value | Should -Be "windows-2019" 384 385 $config.displayNamesLookup | Should -BeOfType [Hashtable] 386 $config.displayNamesLookup["--enableFoo"] | Should -Be "withFoo" 387 388 $config.include.Length | Should -Be 1 389 $config.exclude.Length | Should -Be 3 390 } 391 } 392 393 Describe "Platform Matrix Post Transformation" -Tag "transform" { 394 BeforeEach { 395 $config = GetMatrixConfigFromJson $matrixConfig 396 } 397 398 It "Should match partial matrix elements" -TestCases @( 399 @{ source = [Ordered]@{ a = 1; b = 2; }; target = [Ordered]@{ a = 1 }; expected = $true } 400 @{ source = [Ordered]@{ a = 1; b = 2; }; target = [Ordered]@{ a = 1; b = 2 }; expected = $true } 401 @{ source = [Ordered]@{ a = 1; b = 2; }; target = [Ordered]@{ a = 1; b = 2; c = 3 }; expected = $false } 402 @{ source = [Ordered]@{ a = 1; b = 2; }; target = [Ordered]@{ }; expected = $false } 403 @{ source = [Ordered]@{ }; target = [Ordered]@{ a = 1; b = 2; }; expected = $false } 404 ) { 405 MatrixElementMatch $source $target | Should -Be $expected 406 } 407 408 It "Should remove matrix elements based on exclude filters" { 409 $matrix = GenerateFullMatrix $config.matrixParameters $config.displayNamesLookup 410 $withExclusion = ProcessExcludes $matrix $config.exclude 411 $withExclusion.Length | Should -Be 5 412 413 $matrix = GenerateSparseMatrix $config.matrixParameters $config.displayNamesLookup 414 [array]$withExclusion = ProcessExcludes $matrix $config.exclude 415 $withExclusion.Length | Should -Be 1 416 } 417 418 It "Should add matrix elements based on include elements" { 419 $matrix = GenerateFullMatrix $config.matrixParameters $config.displayNamesLookup 420 $withInclusion = ProcessIncludes $config $matrix "all" 421 $withInclusion.Length | Should -Be 15 422 } 423 424 It "Should include and exclude values with a matrix" { 425 [Array]$matrix = GenerateMatrix $config "all" 426 $matrix.Length | Should -Be 8 427 428 $matrix[0].name | Should -Be "windows2019_netcoreapp21" 429 $matrix[0].parameters.operatingSystem | Should -Be "windows-2019" 430 $matrix[0].parameters.framework | Should -Be "netcoreapp2.1" 431 $matrix[0].parameters.additionalArguments | Should -Be "" 432 433 $matrix[1].name | Should -Be "windows2019_netcoreapp21_withfoo" 434 $matrix[1].parameters.operatingSystem | Should -Be "windows-2019" 435 $matrix[1].parameters.framework | Should -Be "netcoreapp2.1" 436 $matrix[1].parameters.additionalArguments | Should -Be "--enableFoo" 437 438 $matrix[2].name | Should -Be "ubuntu1804_net461" 439 $matrix[2].parameters.framework | Should -Be "net461" 440 $matrix[2].parameters.operatingSystem | Should -Be "ubuntu-18.04" 441 $matrix[2].parameters.additionalArguments | Should -Be "" 442 443 $matrix[4].name | Should -Be "macOS1015_net461" 444 $matrix[4].parameters.framework | Should -Be "net461" 445 $matrix[4].parameters.operatingSystem | Should -Be "macOS-10.15" 446 $matrix[4].parameters.additionalArguments | Should -Be "" 447 448 $matrix[7].name | Should -Be "windows2019_net50_enableWindowsFoo" 449 $matrix[7].parameters.framework | Should -Be "net50" 450 $matrix[7].parameters.operatingSystem | Should -Be "windows-2019" 451 $matrix[7].parameters.additionalArguments | Should -Be "--enableWindowsFoo" 452 } 453 454 It "Should parse a config with an empty base matrix" { 455 $matrixConfigForIncludeOnly = @" 456 { 457 "include": [ 458 { 459 "operatingSystem": "windows-2019", 460 "framework": "net461" 461 } 462 ] 463 } 464 "@ 465 466 $config = GetMatrixConfigFromJson $matrixConfigForIncludeOnly 467 [Array]$matrix = GenerateMatrix $config "all" 468 $matrix.Length | Should -Be 1 469 $matrix[0].name | Should -Be "windows2019_net461" 470 } 471 472 It "Should parse a config with an empty include" { 473 $matrixConfigForIncludeOnly = @" 474 { 475 "matrix": { 476 "operatingSystem": "windows-2019", 477 "framework": "net461" 478 } 479 } 480 "@ 481 482 $config = GetMatrixConfigFromJson $matrixConfigForIncludeOnly 483 [Array]$matrix = GenerateMatrix $config "all" 484 $matrix.Length | Should -Be 1 485 $matrix[0].name | Should -Be "windows2019_net461" 486 } 487 } 488 489 Describe "Platform Matrix Generation With Object Fields" -Tag "objectfields" { 490 BeforeEach { 491 $matrixConfigForObject = @" 492 { 493 "matrix": { 494 "testObject": { 495 "testObjectName1": { "testObject1Value1": "1", "testObject1Value2": "2" }, 496 "testObjectName2": { "testObject2Value1": "1", "testObject2Value2": "2" } 497 }, 498 "secondTestObject": { 499 "secondTestObjectName1": { "secondTestObject1Value1": "1", "secondTestObject1Value2": "2" } 500 }, 501 "testField": [ "footest", "bartest" ] 502 }, 503 "include": [ 504 { 505 "testObjectInclude": { 506 "testObjectIncludeName": { "testObjectValue1": "1", "testObjectValue2": "2" } 507 }, 508 "testField": "footest" 509 } 510 ] 511 } 512 "@ 513 $objectFieldConfig = GetMatrixConfigFromJson $matrixConfigForObject 514 } 515 516 It "Should parse dimensions properly" { 517 [Array]$dimensions = GetMatrixDimensions $objectFieldConfig.matrixParameters 518 $dimensions.Length | Should -Be 3 519 $dimensions[0] | Should -Be 2 520 $dimensions[1] | Should -Be 1 521 $dimensions[2] | Should -Be 2 522 } 523 524 It "Should populate a sparse matrix dimensions properly" { 525 [Array]$matrix = GenerateMatrix $objectFieldConfig "sparse" 526 $matrix.Length | Should -Be 3 527 528 $matrix[0].name | Should -Be "testObjectName1_secondTestObjectName1_footest" 529 $matrix[0].parameters.testField | Should -Be "footest" 530 $matrix[0].parameters.testObject1Value1 | Should -Be "1" 531 $matrix[0].parameters.testObject1Value2 | Should -Be "2" 532 $matrix[0].parameters.secondTestObject1Value1 | Should -Be "1" 533 $matrix[0].parameters.Count | Should -Be 5 534 535 $matrix[1].name | Should -Be "testObjectName2_secondTestObjectName1_bartest" 536 $matrix[1].parameters.testField | Should -Be "bartest" 537 $matrix[1].parameters.testObject2Value1 | Should -Be "1" 538 $matrix[1].parameters.testObject2Value2 | Should -Be "2" 539 $matrix[1].parameters.secondTestObject1Value1 | Should -Be "1" 540 $matrix[1].parameters.Count | Should -Be 5 541 542 $matrix[2].name | Should -Be "testObjectIncludeName_footest" 543 $matrix[2].parameters.testField | Should -Be "footest" 544 $matrix[2].parameters.testObjectValue1 | Should -Be "1" 545 $matrix[2].parameters.testObjectValue2 | Should -Be "2" 546 $matrix[2].parameters.Count | Should -Be 3 547 } 548 549 It "Should splat matrix entries that are objects into key/values" { 550 [Array]$matrix = GenerateMatrix $objectFieldConfig "all" 551 $matrix.Length | Should -Be 5 552 553 $matrix[0].name | Should -Be "testObjectName1_secondTestObjectName1_footest" 554 $matrix[0].parameters.testField | Should -Be "footest" 555 $matrix[0].parameters.testObject1Value1 | Should -Be "1" 556 $matrix[0].parameters.testObject1Value2 | Should -Be "2" 557 $matrix[0].parameters.secondTestObject1Value1 | Should -Be "1" 558 $matrix[0].parameters.Count | Should -Be 5 559 560 $matrix[3].name | Should -Be "testObjectName2_secondTestObjectName1_bartest" 561 $matrix[3].parameters.testField | Should -Be "bartest" 562 $matrix[3].parameters.testObject2Value1 | Should -Be "1" 563 $matrix[3].parameters.testObject2Value2 | Should -Be "2" 564 $matrix[3].parameters.secondTestObject1Value1 | Should -Be "1" 565 $matrix[3].parameters.Count | Should -Be 5 566 567 $matrix[4].name | Should -Be "testObjectIncludeName_footest" 568 $matrix[4].parameters.testField | Should -Be "footest" 569 $matrix[4].parameters.testObjectValue1 | Should -Be "1" 570 $matrix[4].parameters.testObjectValue2 | Should -Be "2" 571 $matrix[4].parameters.Count | Should -Be 3 572 } 573 } 574 575 Describe "Platform Matrix Display Names" -Tag "displaynames" { 576 BeforeEach { 577 $matrixConfigForGenerate = @" 578 { 579 "displayNames": { 580 "--enableFoo": "withfoo" 581 }, 582 "matrix": { 583 "operatingSystem": "ubuntu-18.04", 584 "framework": [ 585 "net461", 586 "netcoreapp2.1" 587 ], 588 "TestNullField": null, 589 "TestObjectField": { 590 "TestObjectValueName": { 591 "foo": "bar", 592 "baz": "qux" 593 } 594 } 595 } 596 } 597 "@ 598 $generateConfig = GetMatrixConfigFromJson $matrixConfigForGenerate 599 } 600 601 It "Should enforce valid display name format" { 602 $generateconfig.displayNamesLookup["net461"] = '123.Some.456.Invalid_format-name$(foo)' 603 $generateconfig.displayNamesLookup["netcoreapp2.1"] = (New-Object string[] 150) -join "a" 604 $dimensions = GetMatrixDimensions $generateConfig.matrixParameters 605 $matrix = GenerateFullMatrix $generateconfig.matrixParameters $generateconfig.displayNamesLookup 606 607 $matrix[0].name | Should -Be "ubuntu1804_123some456invalid_formatnamefoo_TestObjectValueName" 608 609 $matrix[1].name.Length | Should -Be 100 610 # The withfoo part of the argument gets cut off at the character limit 611 $matrix[1].name | Should -BeLike "ubuntu1804_aaaaaaaaaaaaaaaaa*" 612 } 613 614 It "Should generate a display name with null and object values" { 615 $matrix = GenerateMatrix $generateConfig "sparse" 616 $matrix[0].name | Should -Be "ubuntu1804_net461_TestObjectValueName" 617 } 618 } 619