From 582e48bcf21dedd80693d73955c0f8226e1de202 Mon Sep 17 00:00:00 2001 From: "Bryan Wang (PSHCT)" Date: Fri, 8 Sep 2017 17:04:01 -0700 Subject: [PATCH 1/8] Write exceptions in generated commands, some fixes for core CLR test pass --- PSSwagger/PSSwagger.Constants.ps1 | 16 +++++++++++++++- PSSwagger/PSSwagger.psm1 | 1 + Tests/PSSwaggerScenario.Tests.ps1 | 6 +++--- Tests/TestUtilities.psm1 | 3 +-- Tests/run-tests.ps1 | 5 ++++- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/PSSwagger/PSSwagger.Constants.ps1 b/PSSwagger/PSSwagger.Constants.ps1 index 1a4094e..069377b 100644 --- a/PSSwagger/PSSwagger.Constants.ps1 +++ b/PSSwagger/PSSwagger.Constants.ps1 @@ -247,7 +247,21 @@ $getTaskResultBlock = @' if(`$taskResult.IsFaulted) { Write-Verbose -Message 'Operation failed.' - Throw "`$(`$taskResult.Exception.InnerExceptions | Out-String)" + if (`$taskResult.Exception) + { + if ((Get-Member -InputObject `$taskResult.Exception -Name 'InnerExceptions') -and `$taskResult.Exception.InnerExceptions) + { + foreach (`$ex in `$taskResult.Exception.InnerExceptions) + { + Write-Error -Exception `$ex + } + } elseif ((Get-Member -InputObject `$taskResult.Exception -Name 'InnerException') -and `$taskResult.Exception.InnerException) + { + Write-Error -Exception `$taskResult.Exception.InnerException + } else { + Write-Error -Exception `$taskResult.Exception + } + } } elseif (`$taskResult.IsCanceled) { diff --git a/PSSwagger/PSSwagger.psm1 b/PSSwagger/PSSwagger.psm1 index 81bdc62..806bebe 100644 --- a/PSSwagger/PSSwagger.psm1 +++ b/PSSwagger/PSSwagger.psm1 @@ -926,6 +926,7 @@ function ConvertTo-CsharpCode $microsoftRestClientRuntimeAzureRequiredVersion = if ($dependencies.ContainsKey('Microsoft.Rest.ClientRuntime.Azure')) { $dependencies['Microsoft.Rest.ClientRuntime.Azure'].RequiredVersion } else { '' } $command = @" + `$env:PSModulePath = `"$env:PSModulePath`"; `$AddPSSwaggerClientType_params = @{ OutputAssemblyName = '$outAssembly' ClrPath = '$clrPath' diff --git a/Tests/PSSwaggerScenario.Tests.ps1 b/Tests/PSSwaggerScenario.Tests.ps1 index 41b5d6e..d17ac7a 100644 --- a/Tests/PSSwaggerScenario.Tests.ps1 +++ b/Tests/PSSwaggerScenario.Tests.ps1 @@ -512,7 +512,7 @@ Describe "Composite Swagger Tests" -Tag @('Composite','ScenarioTest') { Import-Module $PsSwaggerPath -Force if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "powershell.exe" -command "& {`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$global:fullPowerShellPath\powershell.exe" -command "& {`$env:Path = '$global:fullPowerShellPath;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module (Join-Path `"$PsSwaggerPath`" `"PSSwagger.psd1`") -Force -ArgumentList `$true; New-PSSwaggerModule -SpecificationPath $SwaggerSpecPath -Name $ModuleName -UseAzureCsharpGenerator -Path $Path -NoAssembly -Verbose -ConfirmBootstrap; }" @@ -807,7 +807,7 @@ Describe "Header scenario tests" -Tag @('Header','ScenarioTest') { $GeneratedModuleVersionPath = Join-Path -Path $GeneratedModuleBase -ChildPath $ModuleVersion $Header = '__Custom_HEADER_Content__' if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "powershell.exe" -command "& {`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$global:fullPowerShellPath\powershell.exe" -command "& {`$env:Path = '$global:fullPowerShellPath;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module '$PsSwaggerPath' -Force -ArgumentList `$true; New-PSSwaggerModule -SpecificationPath '$SwaggerSpecPath' -Name $ModuleName -Version '$ModuleVersion' -UseAzureCsharpGenerator -Path '$GeneratedPath' -NoAssembly -Verbose -ConfirmBootstrap -Header '$Header'; }" @@ -828,7 +828,7 @@ Describe "Header scenario tests" -Tag @('Header','ScenarioTest') { $ModuleVersion = '2.2.2.2' $GeneratedModuleVersionPath = Join-Path -Path $GeneratedModuleBase -ChildPath $ModuleVersion if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "powershell.exe" -command "& {`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$global:fullPowerShellPath\powershell.exe" -command "& {`$env:Path = '$global:fullPowerShellPath;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module '$PsSwaggerPath' -Force -ArgumentList `$true; New-PSSwaggerModule -SpecificationPath '$SwaggerSpecPath' -Name $ModuleName -Version '$ModuleVersion' -UseAzureCsharpGenerator -Path '$GeneratedPath' -NoAssembly -Verbose -ConfirmBootstrap; }" diff --git a/Tests/TestUtilities.psm1 b/Tests/TestUtilities.psm1 index c681dd1..d7be948 100644 --- a/Tests/TestUtilities.psm1 +++ b/Tests/TestUtilities.psm1 @@ -132,9 +132,8 @@ function Initialize-Test { # Module generation part needs to happen in full powershell Write-Verbose "Generating module" if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "powershell.exe" -command "& {`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$global:fullPowerShellPath\powershell.exe" -command "& {`$env:Path = '$global:fullPowerShellPath;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module (Join-Path `"$PsSwaggerPath`" `"PSSwagger.psd1`") -Force; - Import-Module (Join-Path `"$PsSwaggerPath`" `"PSSwaggerUtility`") -Force; Initialize-PSSwaggerDependencies -AllFrameworks -AcceptBootstrap -Azure:`$$UseAzureCSharpGenerator; New-PSSwaggerModule -SpecificationPath (Join-Path -Path `"$testCaseDataLocation`" -ChildPath $TestSpecFileName) -Path "$generatedModulesPath" -Name $GeneratedModuleName -Verbose -NoAssembly -UseAzureCSharpGenerator:`$$UseAzureCSharpGenerator -ConfirmBootstrap; }" diff --git a/Tests/run-tests.ps1 b/Tests/run-tests.ps1 index 097d03c..93e0b1b 100644 --- a/Tests/run-tests.ps1 +++ b/Tests/run-tests.ps1 @@ -135,6 +135,8 @@ if (-not $azureRmProfile) { } $powershellFolder = $null +$srcPath = Join-Path -Path $PSScriptRoot -ChildPath .. | Join-Path -ChildPath PSSwagger +$srcPath += [System.IO.Path]::DirectorySeparatorChar if ("netstandard1.7" -eq $TestFramework) { # beta > alpha $powershellCore = Get-Package -Name PowerShell* -ProviderName msi | Sort-Object -Property Name -Descending | Select-Object -First 1 -ErrorAction Ignore @@ -143,7 +145,8 @@ if ("netstandard1.7" -eq $TestFramework) { } $psVersion = $powershellCore.Name.Substring(11) $powershellFolder = "$Env:ProgramFiles\PowerShell\$($psVersion)" - $executeTestsCommand += ";`$env:PSModulePath_Backup=`"$env:PSModulePath`"" + $fullPowerShellPath = Split-Path (Get-Command powershell).Path -Parent + $executeTestsCommand += ";`$env:PSModulePath_Backup=`"$srcPath;$env:PSModulePath`";`$global:fullPowerShellPath=`"$fullPowerShellPath`"" } if ($EnableTracing) { From 894feb97e9e25dfd656d579a1a0f2ee1d8b5528e Mon Sep 17 00:00:00 2001 From: "Bryan Wang (PSHCT)" Date: Fri, 8 Sep 2017 17:22:38 -0700 Subject: [PATCH 2/8] Fix spacing --- PSSwagger/PSSwagger.Constants.ps1 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/PSSwagger/PSSwagger.Constants.ps1 b/PSSwagger/PSSwagger.Constants.ps1 index 069377b..8618451 100644 --- a/PSSwagger/PSSwagger.Constants.ps1 +++ b/PSSwagger/PSSwagger.Constants.ps1 @@ -248,20 +248,20 @@ $getTaskResultBlock = @' { Write-Verbose -Message 'Operation failed.' if (`$taskResult.Exception) - { - if ((Get-Member -InputObject `$taskResult.Exception -Name 'InnerExceptions') -and `$taskResult.Exception.InnerExceptions) - { - foreach (`$ex in `$taskResult.Exception.InnerExceptions) - { - Write-Error -Exception `$ex - } - } elseif ((Get-Member -InputObject `$taskResult.Exception -Name 'InnerException') -and `$taskResult.Exception.InnerException) - { - Write-Error -Exception `$taskResult.Exception.InnerException - } else { + { + if ((Get-Member -InputObject `$taskResult.Exception -Name 'InnerExceptions') -and `$taskResult.Exception.InnerExceptions) + { + foreach (`$ex in `$taskResult.Exception.InnerExceptions) + { + Write-Error -Exception `$ex + } + } elseif ((Get-Member -InputObject `$taskResult.Exception -Name 'InnerException') -and `$taskResult.Exception.InnerException) + { + Write-Error -Exception `$taskResult.Exception.InnerException + } else { Write-Error -Exception `$taskResult.Exception } - } + } } elseif (`$taskResult.IsCanceled) { From 259d159821455d70d7a836dace6e9af498bf5117 Mon Sep 17 00:00:00 2001 From: "Bryan Wang (PSHCT)" Date: Mon, 11 Sep 2017 17:10:55 -0700 Subject: [PATCH 3/8] Fixes for PSCore test run (only expected failures remain) --- PSSwagger/PSSwagger.psm1 | 4 +- Tests/PSSwaggerScenario.Tests.ps1 | 13 ++++-- Tests/TestUtilities.psm1 | 67 +++++++++++++++++++++++++++++-- Tests/run-tests.ps1 | 6 ++- 4 files changed, 80 insertions(+), 10 deletions(-) diff --git a/PSSwagger/PSSwagger.psm1 b/PSSwagger/PSSwagger.psm1 index 806bebe..1987d3a 100644 --- a/PSSwagger/PSSwagger.psm1 +++ b/PSSwagger/PSSwagger.psm1 @@ -779,6 +779,7 @@ function ConvertTo-CsharpCode $tempCodeGenSettingsPath = '' # Latest AutoRest inconsistently appends 'Client' to the specified infoName to generated the client name. # We need to override the client name to ensure that generated PowerShell cmdlets work fine. + # Note: -ClientName doesn't seem to work for legacy invocation $ClientName = $info['ClientTypeName'] try { if ($info.ContainsKey('CodeGenFileRequired') -and $info.CodeGenFileRequired) { @@ -833,7 +834,6 @@ function ConvertTo-CsharpCode Write-Verbose -Message $LocalizedData.InvokingAutoRestWithParams Write-Verbose -Message $($autoRestParams | Out-String) - $autorestMessages = & AutoRest $autoRestParams if ($autorestMessages) { Write-Verbose -Message $($autorestMessages | Out-String) @@ -925,6 +925,7 @@ function ConvertTo-CsharpCode $dependencies = Get-PSSwaggerExternalDependencies -Azure:$codeCreatedByAzureGenerator -Framework 'netstandard1' $microsoftRestClientRuntimeAzureRequiredVersion = if ($dependencies.ContainsKey('Microsoft.Rest.ClientRuntime.Azure')) { $dependencies['Microsoft.Rest.ClientRuntime.Azure'].RequiredVersion } else { '' } + # In some cases, PSCore doesn't inherit this process's PSModulePath $command = @" `$env:PSModulePath = `"$env:PSModulePath`"; `$AddPSSwaggerClientType_params = @{ @@ -937,6 +938,7 @@ function ConvertTo-CsharpCode CodeCreatedByAzureGenerator = `$$codeCreatedByAzureGenerator BootstrapConsent = `$$UserConsent } + `$env:PSModulePath += '$env:PSModulePath' PSSwaggerUtility\Add-PSSwaggerClientType @AddPSSwaggerClientType_params "@ $success = & "$PowerShellCorePath" -command "& {$command}" diff --git a/Tests/PSSwaggerScenario.Tests.ps1 b/Tests/PSSwaggerScenario.Tests.ps1 index d17ac7a..fbdd3ab 100644 --- a/Tests/PSSwaggerScenario.Tests.ps1 +++ b/Tests/PSSwaggerScenario.Tests.ps1 @@ -521,6 +521,11 @@ Describe "Composite Swagger Tests" -Tag @('Composite','ScenarioTest') { } $ModulePath = Join-Path -Path $Path -ChildPath $ModuleName + # Destroy the full and core CLR requirements so that AzureRM modules aren't required + # For now, composite swagger specs don't work without the -UseAzureCsharpGenerator flag because of AutoRest naming inconsistency + "" | Out-File -FilePath (Join-Path -Path $ModulePath -ChildPath "0.0.1" | Join-Path -ChildPath "Test-CoreRequirements.ps1") + "" | Out-File -FilePath (Join-Path -Path $ModulePath -ChildPath "0.0.1" | Join-Path -ChildPath "Test-FullRequirements.ps1") + Get-Module -ListAvailable -Name $ModulePath | Should BeOfType 'System.Management.Automation.PSModuleInfo' # Import generated module @@ -973,7 +978,7 @@ Describe "Pre-compiled SDK Assmebly scenario tests" -Tag @('SDKAssembly','Scenar Verbose = $true } Invoke-NewPSSwaggerModuleCommand -NewPSSwaggerModuleParameters $NewPSSwaggerModule_params -ErrorVariable 'ev' -ErrorAction 'SilentlyContinue' - $ev.FullyQualifiedErrorId | Should Be 'AssemblyNotFound,New-PSSwaggerModule' + (Remove-TestErrorId -FullyQualifiedErrorId $ev.FullyQualifiedErrorId) | Should Be 'AssemblyNotFound,New-PSSwaggerModule' } It 'Should fail when client type name is not found in pre-compiled SDK assembly scenario' { @@ -999,7 +1004,7 @@ Describe "Pre-compiled SDK Assmebly scenario tests" -Tag @('SDKAssembly','Scenar Verbose = $true } Invoke-NewPSSwaggerModuleCommand -NewPSSwaggerModuleParameters $NewPSSwaggerModule_params -ErrorVariable 'ev' -ErrorAction 'SilentlyContinue' - $ev.FullyQualifiedErrorId | Should Be 'UnableToExtractDetailsFromSdkAssembly,Update-PathFunctionDetails' + (Remove-TestErrorId -FullyQualifiedErrorId $ev.FullyQualifiedErrorId) | Should Be 'UnableToExtractDetailsFromSdkAssembly,Update-PathFunctionDetails' } It 'Should fail when incorrect namespace in client type name is specified in pre-compiled SDK assembly scenario' { @@ -1025,7 +1030,7 @@ Describe "Pre-compiled SDK Assmebly scenario tests" -Tag @('SDKAssembly','Scenar Verbose = $true } Invoke-NewPSSwaggerModuleCommand -NewPSSwaggerModuleParameters $NewPSSwaggerModule_params -ErrorVariable 'ev' -ErrorAction 'SilentlyContinue' - $ev.FullyQualifiedErrorId | Should Be 'UnableToExtractDetailsFromSdkAssembly,Update-PathFunctionDetails' + (Remove-TestErrorId -FullyQualifiedErrorId $ev.FullyQualifiedErrorId) | Should Be 'UnableToExtractDetailsFromSdkAssembly,Update-PathFunctionDetails' } It 'Should fail when incorrect client type name is specified in pre-compiled SDK assembly scenario' { @@ -1051,6 +1056,6 @@ Describe "Pre-compiled SDK Assmebly scenario tests" -Tag @('SDKAssembly','Scenar Verbose = $true } Invoke-NewPSSwaggerModuleCommand -NewPSSwaggerModuleParameters $NewPSSwaggerModule_params -ErrorVariable 'ev' -ErrorAction 'SilentlyContinue' - $ev.FullyQualifiedErrorId | Should Be 'UnableToExtractDetailsFromSdkAssembly,Update-PathFunctionDetails' + (Remove-TestErrorId -FullyQualifiedErrorId $ev.FullyQualifiedErrorId) | Should Be 'UnableToExtractDetailsFromSdkAssembly,Update-PathFunctionDetails' } } diff --git a/Tests/TestUtilities.psm1 b/Tests/TestUtilities.psm1 index d7be948..4cda031 100644 --- a/Tests/TestUtilities.psm1 +++ b/Tests/TestUtilities.psm1 @@ -93,16 +93,77 @@ function Invoke-NewPSSwaggerModuleCommand { elseif ($_.Value -ne $false) { $ParametersString += " -$($_.Name) '$($_.Value)'" } - } - & "powershell.exe" -command "& { + } + # For now this hides Exception and ErrorObject + $command = "& { + `$env:Path = '$global:fullPowerShellPath;$env:Path'; `$env:PSModulePath=`$env:PSModulePath_Backup; - New-PSSwaggerModule $ParametersString + New-PSSwaggerModule $ParametersString -ErrorVariable evtemp + foreach (`$ev in `$evtemp) { + `$returnEv = `$false + `$evEncoded = 'ErrorVariable: ' + if (`$ev.FullyQualifiedErrorId) { + `$evEncoded += 'ErrorId=' + `$evEncoded += `$ev.FullyQualifiedErrorId + `$evEncoded += ';' + `$returnEv = `$true + } + + if (`$ev.CategoryInfo) { + `$evEncoded += 'ErrorCategory=' + `$evEncoded += `$ev.CategoryInfo.Category + `$evEncoded += ';' + `$returnEv = `$true + } + + if (`$returnEv) { + `$evEncoded + } + } }" + $result = & "$global:fullPowerShellPath\powershell.exe" -command $command + if ($PSBoundParameters.ContainsKey("ErrorVariable")) { + foreach ($resultLine in $result) { + if ($resultLine.StartsWith("ErrorVariable: ")) { + $errorVariableInfoTokenPairs = $resultLine.Substring(15).Split(';') + $errorId = '' + $errorCategory = '' + for ($i = 0; $i -lt $errorVariableInfoTokenPairs.Length; $i++) { + $errorVariableInfoTokens = $errorVariableInfoTokenPairs[$i].Split('=') + if ($errorVariableInfoTokens[0] -eq 'ErrorId') { + $errorId = $errorVariableInfoTokens[1] + } elseif ($errorVariableInfoTokens[0] -eq 'ErrorCategory') { + $errorCategory = $errorVariableInfoTokens[1] + } + } + + Write-Error -Message 'New-PSSwaggerModule remote error' -ErrorId $errorId -Category $errorCategory + } + } + } + $result } else { New-PSSwaggerModule @NewPSSwaggerModuleParameters } } + +function Remove-TestErrorId { + [CmdletBinding()] + param( + [string]$FullyQualifiedErrorId + ) + + $errorIds = $FullyQualifiedErrorId.Split(',') + $NewFullyQualifiedErrorId = '' + for ($i = 0; $i -lt $errorIds.Length; $i++) { + if ($errorIds[$i] -ne 'Invoke-NewPSSwaggerModuleCommand') { + $NewFullyQualifiedErrorId += "$($errorIds[$i])," + } + } + + return $NewFullyQualifiedErrorId.Substring(0, $NewFullyQualifiedErrorId.Length - 1) +} function Initialize-Test { [CmdletBinding()] param( diff --git a/Tests/run-tests.ps1 b/Tests/run-tests.ps1 index 93e0b1b..97ba516 100644 --- a/Tests/run-tests.ps1 +++ b/Tests/run-tests.ps1 @@ -137,6 +137,8 @@ if (-not $azureRmProfile) { $powershellFolder = $null $srcPath = Join-Path -Path $PSScriptRoot -ChildPath .. | Join-Path -ChildPath PSSwagger $srcPath += [System.IO.Path]::DirectorySeparatorChar +$modulePath = Join-Path -Path $PSScriptRoot -ChildPath .. +$modulePath += [System.IO.Path]::DirectorySeparatorChar if ("netstandard1.7" -eq $TestFramework) { # beta > alpha $powershellCore = Get-Package -Name PowerShell* -ProviderName msi | Sort-Object -Property Name -Descending | Select-Object -First 1 -ErrorAction Ignore @@ -146,7 +148,7 @@ if ("netstandard1.7" -eq $TestFramework) { $psVersion = $powershellCore.Name.Substring(11) $powershellFolder = "$Env:ProgramFiles\PowerShell\$($psVersion)" $fullPowerShellPath = Split-Path (Get-Command powershell).Path -Parent - $executeTestsCommand += ";`$env:PSModulePath_Backup=`"$srcPath;$env:PSModulePath`";`$global:fullPowerShellPath=`"$fullPowerShellPath`"" + $executeTestsCommand += ";`$env:PSModulePath_Backup=`"$srcPath;$modulePath;$env:PSModulePath`";`$global:fullPowerShellPath=`"$fullPowerShellPath`"" } if ($EnableTracing) { @@ -157,7 +159,7 @@ $srcPath = Join-Path -Path $PSScriptRoot -ChildPath .. | Join-Path -ChildPath PS $srcPath += [System.IO.Path]::DirectorySeparatorChar $executeTestsCommand += @" ;`$verbosepreference=`'continue`'; - `$env:PSModulePath=`"$srcPath;`$env:PSModulePath`"; + `$env:PSModulePath=`"$srcPath;$modulePath;`$env:PSModulePath`"; Invoke-Pester -Script `'$PSScriptRoot`' -ExcludeTag KnownIssue -OutputFormat NUnitXml -OutputFile ScenarioTestResults.xml -Verbose; "@ # Set up Pester params From 98af42489479dbb539fe6d803ae45fa9d61d3916 Mon Sep 17 00:00:00 2001 From: "Bryan Wang (PSHCT)" Date: Mon, 11 Sep 2017 17:32:53 -0700 Subject: [PATCH 4/8] PR comments --- PSSwagger/PSSwagger.Constants.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PSSwagger/PSSwagger.Constants.ps1 b/PSSwagger/PSSwagger.Constants.ps1 index 8618451..7fc0640 100644 --- a/PSSwagger/PSSwagger.Constants.ps1 +++ b/PSSwagger/PSSwagger.Constants.ps1 @@ -51,7 +51,9 @@ else { `$ClrPath = Join-Path -Path `$PSScriptRoot -ChildPath 'ref' | Join-Path -ChildPath `$clr $DynamicAssemblyGenerationCode `$allDllsPath = Join-Path -Path `$ClrPath -ChildPath '*.dll' -Get-ChildItem -Path `$allDllsPath -File | ForEach-Object { Add-Type -Path `$_.FullName -ErrorAction SilentlyContinue } +if (Test-Path -Path `$ClrPath) { + Get-ChildItem -Path `$allDllsPath -File | ForEach-Object { Add-Type -Path `$_.FullName -ErrorAction SilentlyContinue } +} . (Join-Path -Path `$PSScriptRoot -ChildPath 'New-ServiceClient.ps1') . (Join-Path -Path `$PSScriptRoot -ChildPath 'GeneratedHelpers.ps1') From 63b765f74312efdf327910bc80a423e5f09d5498 Mon Sep 17 00:00:00 2001 From: "Bryan Wang (PSHCT)" Date: Tue, 12 Sep 2017 08:22:26 -0700 Subject: [PATCH 5/8] Assume path of full powershell.exe --- Tests/PSSwaggerScenario.Tests.ps1 | 6 +++--- Tests/TestUtilities.psm1 | 6 +++--- Tests/run-tests.ps1 | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Tests/PSSwaggerScenario.Tests.ps1 b/Tests/PSSwaggerScenario.Tests.ps1 index fbdd3ab..bd92493 100644 --- a/Tests/PSSwaggerScenario.Tests.ps1 +++ b/Tests/PSSwaggerScenario.Tests.ps1 @@ -512,7 +512,7 @@ Describe "Composite Swagger Tests" -Tag @('Composite','ScenarioTest') { Import-Module $PsSwaggerPath -Force if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "$global:fullPowerShellPath\powershell.exe" -command "& {`$env:Path = '$global:fullPowerShellPath;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module (Join-Path `"$PsSwaggerPath`" `"PSSwagger.psd1`") -Force -ArgumentList `$true; New-PSSwaggerModule -SpecificationPath $SwaggerSpecPath -Name $ModuleName -UseAzureCsharpGenerator -Path $Path -NoAssembly -Verbose -ConfirmBootstrap; }" @@ -812,7 +812,7 @@ Describe "Header scenario tests" -Tag @('Header','ScenarioTest') { $GeneratedModuleVersionPath = Join-Path -Path $GeneratedModuleBase -ChildPath $ModuleVersion $Header = '__Custom_HEADER_Content__' if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "$global:fullPowerShellPath\powershell.exe" -command "& {`$env:Path = '$global:fullPowerShellPath;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module '$PsSwaggerPath' -Force -ArgumentList `$true; New-PSSwaggerModule -SpecificationPath '$SwaggerSpecPath' -Name $ModuleName -Version '$ModuleVersion' -UseAzureCsharpGenerator -Path '$GeneratedPath' -NoAssembly -Verbose -ConfirmBootstrap -Header '$Header'; }" @@ -833,7 +833,7 @@ Describe "Header scenario tests" -Tag @('Header','ScenarioTest') { $ModuleVersion = '2.2.2.2' $GeneratedModuleVersionPath = Join-Path -Path $GeneratedModuleBase -ChildPath $ModuleVersion if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "$global:fullPowerShellPath\powershell.exe" -command "& {`$env:Path = '$global:fullPowerShellPath;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module '$PsSwaggerPath' -Force -ArgumentList `$true; New-PSSwaggerModule -SpecificationPath '$SwaggerSpecPath' -Name $ModuleName -Version '$ModuleVersion' -UseAzureCsharpGenerator -Path '$GeneratedPath' -NoAssembly -Verbose -ConfirmBootstrap; }" diff --git a/Tests/TestUtilities.psm1 b/Tests/TestUtilities.psm1 index 4cda031..aec7f4b 100644 --- a/Tests/TestUtilities.psm1 +++ b/Tests/TestUtilities.psm1 @@ -96,7 +96,7 @@ function Invoke-NewPSSwaggerModuleCommand { } # For now this hides Exception and ErrorObject $command = "& { - `$env:Path = '$global:fullPowerShellPath;$env:Path'; + `$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe;$env:Path'; `$env:PSModulePath=`$env:PSModulePath_Backup; New-PSSwaggerModule $ParametersString -ErrorVariable evtemp foreach (`$ev in `$evtemp) { @@ -121,7 +121,7 @@ function Invoke-NewPSSwaggerModuleCommand { } } }" - $result = & "$global:fullPowerShellPath\powershell.exe" -command $command + $result = & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command $command if ($PSBoundParameters.ContainsKey("ErrorVariable")) { foreach ($resultLine in $result) { if ($resultLine.StartsWith("ErrorVariable: ")) { @@ -193,7 +193,7 @@ function Initialize-Test { # Module generation part needs to happen in full powershell Write-Verbose "Generating module" if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "$global:fullPowerShellPath\powershell.exe" -command "& {`$env:Path = '$global:fullPowerShellPath;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module (Join-Path `"$PsSwaggerPath`" `"PSSwagger.psd1`") -Force; Initialize-PSSwaggerDependencies -AllFrameworks -AcceptBootstrap -Azure:`$$UseAzureCSharpGenerator; New-PSSwaggerModule -SpecificationPath (Join-Path -Path `"$testCaseDataLocation`" -ChildPath $TestSpecFileName) -Path "$generatedModulesPath" -Name $GeneratedModuleName -Verbose -NoAssembly -UseAzureCSharpGenerator:`$$UseAzureCSharpGenerator -ConfirmBootstrap; diff --git a/Tests/run-tests.ps1 b/Tests/run-tests.ps1 index 97ba516..6440b44 100644 --- a/Tests/run-tests.ps1 +++ b/Tests/run-tests.ps1 @@ -147,8 +147,7 @@ if ("netstandard1.7" -eq $TestFramework) { } $psVersion = $powershellCore.Name.Substring(11) $powershellFolder = "$Env:ProgramFiles\PowerShell\$($psVersion)" - $fullPowerShellPath = Split-Path (Get-Command powershell).Path -Parent - $executeTestsCommand += ";`$env:PSModulePath_Backup=`"$srcPath;$modulePath;$env:PSModulePath`";`$global:fullPowerShellPath=`"$fullPowerShellPath`"" + $executeTestsCommand += ";`$env:PSModulePath_Backup=`"$srcPath;$modulePath;$env:PSModulePath`"" } if ($EnableTracing) { From 817681e7cab19c018be3f7726dd3ef130fdf570a Mon Sep 17 00:00:00 2001 From: "Bryan Wang (PSHCT)" Date: Tue, 12 Sep 2017 08:28:19 -0700 Subject: [PATCH 6/8] PR comments --- PSSwagger/PSSwagger.Constants.ps1 | 2 +- PSSwagger/PSSwagger.psm1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PSSwagger/PSSwagger.Constants.ps1 b/PSSwagger/PSSwagger.Constants.ps1 index 7fc0640..d0cca21 100644 --- a/PSSwagger/PSSwagger.Constants.ps1 +++ b/PSSwagger/PSSwagger.Constants.ps1 @@ -51,7 +51,7 @@ else { `$ClrPath = Join-Path -Path `$PSScriptRoot -ChildPath 'ref' | Join-Path -ChildPath `$clr $DynamicAssemblyGenerationCode `$allDllsPath = Join-Path -Path `$ClrPath -ChildPath '*.dll' -if (Test-Path -Path `$ClrPath) { +if (Test-Path -Path `$ClrPath -PathType Container) { Get-ChildItem -Path `$allDllsPath -File | ForEach-Object { Add-Type -Path `$_.FullName -ErrorAction SilentlyContinue } } diff --git a/PSSwagger/PSSwagger.psm1 b/PSSwagger/PSSwagger.psm1 index 1987d3a..fbe9cfd 100644 --- a/PSSwagger/PSSwagger.psm1 +++ b/PSSwagger/PSSwagger.psm1 @@ -938,7 +938,7 @@ function ConvertTo-CsharpCode CodeCreatedByAzureGenerator = `$$codeCreatedByAzureGenerator BootstrapConsent = `$$UserConsent } - `$env:PSModulePath += '$env:PSModulePath' + `$env:PSModulePath += ';$env:PSModulePath' PSSwaggerUtility\Add-PSSwaggerClientType @AddPSSwaggerClientType_params "@ $success = & "$PowerShellCorePath" -command "& {$command}" From d21cb3a417331715feeef0d6fcf1c0851ca93531 Mon Sep 17 00:00:00 2001 From: "Bryan Wang (PSHCT)" Date: Tue, 12 Sep 2017 11:04:02 -0700 Subject: [PATCH 7/8] Fix paths --- Tests/PSSwaggerScenario.Tests.ps1 | 4 ++-- Tests/TestUtilities.psm1 | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/PSSwaggerScenario.Tests.ps1 b/Tests/PSSwaggerScenario.Tests.ps1 index bd92493..36cd499 100644 --- a/Tests/PSSwaggerScenario.Tests.ps1 +++ b/Tests/PSSwaggerScenario.Tests.ps1 @@ -812,7 +812,7 @@ Describe "Header scenario tests" -Tag @('Header','ScenarioTest') { $GeneratedModuleVersionPath = Join-Path -Path $GeneratedModuleBase -ChildPath $ModuleVersion $Header = '__Custom_HEADER_Content__' if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module '$PsSwaggerPath' -Force -ArgumentList `$true; New-PSSwaggerModule -SpecificationPath '$SwaggerSpecPath' -Name $ModuleName -Version '$ModuleVersion' -UseAzureCsharpGenerator -Path '$GeneratedPath' -NoAssembly -Verbose -ConfirmBootstrap -Header '$Header'; }" @@ -833,7 +833,7 @@ Describe "Header scenario tests" -Tag @('Header','ScenarioTest') { $ModuleVersion = '2.2.2.2' $GeneratedModuleVersionPath = Join-Path -Path $GeneratedModuleBase -ChildPath $ModuleVersion if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module '$PsSwaggerPath' -Force -ArgumentList `$true; New-PSSwaggerModule -SpecificationPath '$SwaggerSpecPath' -Name $ModuleName -Version '$ModuleVersion' -UseAzureCsharpGenerator -Path '$GeneratedPath' -NoAssembly -Verbose -ConfirmBootstrap; }" diff --git a/Tests/TestUtilities.psm1 b/Tests/TestUtilities.psm1 index aec7f4b..2fc71c5 100644 --- a/Tests/TestUtilities.psm1 +++ b/Tests/TestUtilities.psm1 @@ -96,7 +96,7 @@ function Invoke-NewPSSwaggerModuleCommand { } # For now this hides Exception and ErrorObject $command = "& { - `$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe;$env:Path'; + `$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0;$env:Path'; `$env:PSModulePath=`$env:PSModulePath_Backup; New-PSSwaggerModule $ParametersString -ErrorVariable evtemp foreach (`$ev in `$evtemp) { @@ -193,7 +193,7 @@ function Initialize-Test { # Module generation part needs to happen in full powershell Write-Verbose "Generating module" if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module (Join-Path `"$PsSwaggerPath`" `"PSSwagger.psd1`") -Force; Initialize-PSSwaggerDependencies -AllFrameworks -AcceptBootstrap -Azure:`$$UseAzureCSharpGenerator; New-PSSwaggerModule -SpecificationPath (Join-Path -Path `"$testCaseDataLocation`" -ChildPath $TestSpecFileName) -Path "$generatedModulesPath" -Name $GeneratedModuleName -Verbose -NoAssembly -UseAzureCSharpGenerator:`$$UseAzureCSharpGenerator -ConfirmBootstrap; From c958ca5741332d2938c88e3143cb1148187624ae Mon Sep 17 00:00:00 2001 From: "Bryan Wang (PSHCT)" Date: Tue, 12 Sep 2017 11:35:42 -0700 Subject: [PATCH 8/8] Fix paths --- Tests/PSSwaggerScenario.Tests.ps1 | 6 +++--- Tests/TestUtilities.psm1 | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Tests/PSSwaggerScenario.Tests.ps1 b/Tests/PSSwaggerScenario.Tests.ps1 index 36cd499..c993cef 100644 --- a/Tests/PSSwaggerScenario.Tests.ps1 +++ b/Tests/PSSwaggerScenario.Tests.ps1 @@ -512,7 +512,7 @@ Describe "Composite Swagger Tests" -Tag @('Composite','ScenarioTest') { Import-Module $PsSwaggerPath -Force if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe" -command "& {`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module (Join-Path `"$PsSwaggerPath`" `"PSSwagger.psd1`") -Force -ArgumentList `$true; New-PSSwaggerModule -SpecificationPath $SwaggerSpecPath -Name $ModuleName -UseAzureCsharpGenerator -Path $Path -NoAssembly -Verbose -ConfirmBootstrap; }" @@ -812,7 +812,7 @@ Describe "Header scenario tests" -Tag @('Header','ScenarioTest') { $GeneratedModuleVersionPath = Join-Path -Path $GeneratedModuleBase -ChildPath $ModuleVersion $Header = '__Custom_HEADER_Content__' if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module '$PsSwaggerPath' -Force -ArgumentList `$true; New-PSSwaggerModule -SpecificationPath '$SwaggerSpecPath' -Name $ModuleName -Version '$ModuleVersion' -UseAzureCsharpGenerator -Path '$GeneratedPath' -NoAssembly -Verbose -ConfirmBootstrap -Header '$Header'; }" @@ -833,7 +833,7 @@ Describe "Header scenario tests" -Tag @('Header','ScenarioTest') { $ModuleVersion = '2.2.2.2' $GeneratedModuleVersionPath = Join-Path -Path $GeneratedModuleBase -ChildPath $ModuleVersion if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module '$PsSwaggerPath' -Force -ArgumentList `$true; New-PSSwaggerModule -SpecificationPath '$SwaggerSpecPath' -Name $ModuleName -Version '$ModuleVersion' -UseAzureCsharpGenerator -Path '$GeneratedPath' -NoAssembly -Verbose -ConfirmBootstrap; }" diff --git a/Tests/TestUtilities.psm1 b/Tests/TestUtilities.psm1 index 2fc71c5..d9d2781 100644 --- a/Tests/TestUtilities.psm1 +++ b/Tests/TestUtilities.psm1 @@ -96,7 +96,6 @@ function Invoke-NewPSSwaggerModuleCommand { } # For now this hides Exception and ErrorObject $command = "& { - `$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0;$env:Path'; `$env:PSModulePath=`$env:PSModulePath_Backup; New-PSSwaggerModule $ParametersString -ErrorVariable evtemp foreach (`$ev in `$evtemp) { @@ -193,7 +192,7 @@ function Initialize-Test { # Module generation part needs to happen in full powershell Write-Verbose "Generating module" if((Get-Variable -Name PSEdition -ErrorAction Ignore) -and ('Core' -eq $PSEdition)) { - & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:Path = '$env:SystemRoot\System32\WindowsPowerShell\v1.0;$env:Path';`$env:PSModulePath=`$env:PSModulePath_Backup; + & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\PowerShell.exe" -command "& {`$env:PSModulePath=`$env:PSModulePath_Backup; Import-Module (Join-Path `"$PsSwaggerPath`" `"PSSwagger.psd1`") -Force; Initialize-PSSwaggerDependencies -AllFrameworks -AcceptBootstrap -Azure:`$$UseAzureCSharpGenerator; New-PSSwaggerModule -SpecificationPath (Join-Path -Path `"$testCaseDataLocation`" -ChildPath $TestSpecFileName) -Path "$generatedModulesPath" -Name $GeneratedModuleName -Verbose -NoAssembly -UseAzureCSharpGenerator:`$$UseAzureCSharpGenerator -ConfirmBootstrap;