Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the AutoRestUpgrade.ps1 for different Powershell version #642

Merged
merged 5 commits into from
Jul 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions tests-upgrade/AutoRestUpgradeTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,13 @@ function CompareGeneratedCode([string]$inputSourcePath,[string]$inputTargetPath,
$ignoreResult = IsNeedIgnore -inputFileName $initFile.FullName -ignoreArray $initIgnoreFileList
if(!$ignoreResult)
{
# if(!$initFile.FullName.Startswith($initIgnoreFileList)){
$obj = "what" | Select-Object -Property HashCode, Status
#create an object with HashCode, Status
$obj = New-Object psobject | Select-Object -Property HashCode, Status
#if the file is not filefolder
if($initFile.mode -eq '-a---')
if(!((Get-Item $initFile.PSPath) -is [System.IO.DirectoryInfo]))
{
#get the hashcode of the file
$hashTable = $initFile.PSPath.Replace('Microsoft.PowerShell.Core\FileSystem::','') | get-filehash
# $initFile.FullName
# $hashTable
$obj.HashCode = $hashTable.Hash
#get the path of the file
Expand All @@ -131,9 +130,9 @@ function CompareGeneratedCode([string]$inputSourcePath,[string]$inputTargetPath,
$ignoreResult = IsNeedIgnore -inputFileName $targetFile.FullName -ignoreArray $targetIgnoreFileList
if(!$ignoreResult)
{
$obj = "waht2" | Select-Object -Property HashCode, Status
$obj = New-Object psobject | Select-Object -Property HashCode, Status
#if the file is not filefolder
if($targetFile.mode -eq '-a---')
if(!((Get-Item $targetFile.PSPath) -is [System.IO.DirectoryInfo]))
{
#get the hashcode of the file
$hashTable = $targetFile.PSPath.Replace('Microsoft.PowerShell.Core\FileSystem::','') | get-filehash
Expand All @@ -152,7 +151,7 @@ function CompareGeneratedCode([string]$inputSourcePath,[string]$inputTargetPath,
# 2 the hashcode of the file is different from that in another filefolder
foreach($initDictDetail in $initialDict.Keys)
{
$difDetail = "what"| Select-Object -Property fileName,Path,fileFolderName,Status
$difDetail = New-Object psobject | Select-Object -Property fileName,Path,fileFolderName,Status
#if the file not exists in targetDict
if($targetDict[$initDictDetail] -eq $null)
{
Expand Down Expand Up @@ -194,7 +193,7 @@ function CompareGeneratedCode([string]$inputSourcePath,[string]$inputTargetPath,
#search those files which status is null
foreach($targetDetail in $targetDict.Keys)
{
$difDetail = "what"| Select-Object -Property fileName,Path,fileFolderName,Status
$difDetail = New-Object psobject | Select-Object -Property fileName,Path,fileFolderName,Status
if($targetDict[$targetDetail].Status -eq $null)
{
$difDetail.Path = $targetDetail
Expand All @@ -208,9 +207,9 @@ function CompareGeneratedCode([string]$inputSourcePath,[string]$inputTargetPath,
if($difArray.Count -gt 0)
{
$global:isError=$True
#Export the differ csv to the 'CompareResult' folder
$filename = $PSScriptRoot + '\CompareResult\' + $testFileName + (get-date -format 'yyyyMMddhhmmss')+'.csv'
$filename = Join-Path $PSScriptRoot 'CompareResult' ($testFileName + (get-date -format 'yyyyMMddhhmmss') + '.csv')
$difArray | Select-Object -Property fileName,Path,fileFolderName,Status | Export-CSV -path $filename
Write-Warning ('There are ' + $difArray.Count + ' different files')
}
}

Expand All @@ -220,14 +219,13 @@ $fileList = Get-ChildItem
if($TestName -ne $null -and ($TestName -ne ''))
{
cd ($PSScriptRoot+'\'+$TestName)
$deatilPath = $PSScriptRoot + 'generate'
try
{
$IsGenerateSuccess = GenerateCode
if(-not $Generate -and $IsGenerateSuccess)
{
$sourceFilePath = $PSScriptRoot +'\'+$TestName + '\generate\m3'
$targetFilePath = $PSScriptRoot +'\'+$TestName + '\generate\m4'
$sourceFilePath = Join-Path $PSScriptRoot $TestName 'generate\m3'
$targetFilePath = Join-Path $PSScriptRoot $TestName 'generate\m4'
CompareGeneratedCode -inputSourcePath $sourceFilePath -inputTargetPath $targetFilePath -testFileName $TestName
}
}
Expand All @@ -242,14 +240,13 @@ if($TestName -ne $null -and ($TestName -ne ''))
{
$eachTest
cd ($PSScriptRoot+'\'+$eachTest)
$deatilPath = $PSScriptRoot + 'generate'
try
{
$IsGenerateSuccess = GenerateCode
if(-not $Generate -and $IsGenerateSuccess)
{
$sourceFilePath = $PSScriptRoot +'\'+$eachTest + '\generate\m3'
$targetFilePath = $PSScriptRoot +'\'+$eachTest + '\generate\m4'
$sourceFilePath = Join-Path $PSScriptRoot $eachTest 'generate\m3'
$targetFilePath = Join-Path $PSScriptRoot $eachTest 'generate\m4'
CompareGeneratedCode -inputSourcePath $sourceFilePath -inputTargetPath $targetFilePath -testFileName $eachTest
}
}
Expand All @@ -265,17 +262,17 @@ if($TestName -ne $null -and ($TestName -ne ''))
{
foreach($blackTestName in $blackTestList)
{
if(($fileDetail.Mode -eq 'd----') -and (!$fileDetail.Name.Startswith($blackTestName)))

if(((Get-Item $fileDetail.PSPath) -is [System.IO.DirectoryInfo]) -and (!$fileDetail.Name.Startswith($blackTestName)))
{
try
{
cd ($PSScriptRoot+'\'+$fileDetail.Name)
$deatilPath = $PSScriptRoot + 'generate'
$IsGenerateSuccess = GenerateCode
if(-not $Generate -and $IsGenerateSuccess)
{
$sourceFilePath = $PSScriptRoot +'\'+$fileDetail.Name + '\generate\m3'
$targetFilePath = $PSScriptRoot +'\'+$fileDetail.Name + '\generate\m4'
$sourceFilePath = Join-Path $PSScriptRoot $fileDetail.Name 'generate\m3'
$targetFilePath = Join-Path $PSScriptRoot $fileDetail.Name 'generate\m4'
CompareGeneratedCode -inputSourcePath $sourceFilePath -inputTargetPath $targetFilePath -testFileName $fileDeatil.path
}
}
Expand All @@ -291,19 +288,19 @@ else
{
foreach($fileDetail in $fileList)
{
if($fileDetail.Mode -eq 'd----' -and (!$fileDetail.Name.Startswith('Compare')))
if(((Get-Item $fileDetail.PSPath) -is [System.IO.DirectoryInfo]) -and (!$fileDetail.Name.Startswith('Compare')))
{
$g1 = $PSScriptRoot +'\' +$fileDetail.Name
$g1 = Join-Path $PSScriptRoot $fileDetail.Name
cd ($PSScriptRoot +'\' +$fileDetail.Name)
$deatilPath = $PSScriptRoot +'\' +$fileDetail.Name
$deatilPath =Join-Path $PSScriptRoot $fileDetail.Name
try
{
Write-Host -ForegroundColor Blue $fileDetail.Name
$IsGenerateSuccess = GenerateCode
if(-not $Generate -and $IsGenerateSuccess)
{
$sourceFilePath = $deatilPath + '\generate\m3'
$targetFilePath = $deatilPath + '\generate\m4'
$sourceFilePath = Join-Path $deatilPath 'generate\m3'
$targetFilePath = Join-Path $deatilPath 'generate\m4'
CompareGeneratedCode -inputSourcePath $sourceFilePath -inputTargetPath $targetFilePath -testFileName $fileDetail.Name
}
}
Expand Down