From ccded3d7c6c64ca5496a086957c0f2701fdc3c95 Mon Sep 17 00:00:00 2001 From: Youri Date: Fri, 24 Jul 2020 16:16:24 +0800 Subject: [PATCH 1/4] Change the script --- tests-upgrade/AutoRestUpgradeTest.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests-upgrade/AutoRestUpgradeTest.ps1 b/tests-upgrade/AutoRestUpgradeTest.ps1 index c5d01e2116..aaaad9bab7 100644 --- a/tests-upgrade/AutoRestUpgradeTest.ps1 +++ b/tests-upgrade/AutoRestUpgradeTest.ps1 @@ -54,7 +54,7 @@ function IsNeedIgnore([string]$inputFileName , [Array]$ignoreArray) #Code generation function GenerateCode() { - $GenerateResult=$Ture + $GenerateResult=$True #source and generate codes all need to be generated if((-not $SourceVersion) -and (-not $TargetVersion)) { @@ -208,10 +208,10 @@ 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' + $difArray | Select-Object -Property fileName,Path,fileFolderName,Status | Export-CSV -path $filename } - #Export the differ csv to the 'CompareResult' folder - $filename = $PSScriptRoot + '\CompareResult\' + $testFileName + (get-date -format 'yyyyMMddhhmmss')+'.csv' - $difArray | Select-Object -Property fileName,Path,fileFolderName,Status | Export-CSV -path $filename } $currentPath = Get-Location From cae54d507a698ddcc82ef613e5c36946a847c186 Mon Sep 17 00:00:00 2001 From: Youri Date: Fri, 24 Jul 2020 17:03:06 +0800 Subject: [PATCH 2/4] add script tips --- tests-upgrade/AutoRestUpgradeTest.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/tests-upgrade/AutoRestUpgradeTest.ps1 b/tests-upgrade/AutoRestUpgradeTest.ps1 index aaaad9bab7..57f854249f 100644 --- a/tests-upgrade/AutoRestUpgradeTest.ps1 +++ b/tests-upgrade/AutoRestUpgradeTest.ps1 @@ -205,6 +205,7 @@ function CompareGeneratedCode([string]$inputSourcePath,[string]$inputTargetPath, $difArray+=$difDetail } } + Write-Host -ForegroundColor yellow $difArray.Count if($difArray.Count -gt 0) { $global:isError=$True From 674b70b1399c4522f759e173f13d61d93564debd Mon Sep 17 00:00:00 2001 From: Youri Date: Mon, 27 Jul 2020 13:32:25 +0800 Subject: [PATCH 3/4] fix the powershell version issue --- tests-upgrade/AutoRestUpgradeTest.ps1 | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests-upgrade/AutoRestUpgradeTest.ps1 b/tests-upgrade/AutoRestUpgradeTest.ps1 index 57f854249f..e24fda7eb3 100644 --- a/tests-upgrade/AutoRestUpgradeTest.ps1 +++ b/tests-upgrade/AutoRestUpgradeTest.ps1 @@ -105,14 +105,12 @@ 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 #if the file is not filefolder - if($initFile.mode -eq '-a---') + if($initFile.mode.Startswith('-a')) { #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 @@ -131,9 +129,9 @@ function CompareGeneratedCode([string]$inputSourcePath,[string]$inputTargetPath, $ignoreResult = IsNeedIgnore -inputFileName $targetFile.FullName -ignoreArray $targetIgnoreFileList if(!$ignoreResult) { - $obj = "waht2" | Select-Object -Property HashCode, Status + $obj = "what2" | Select-Object -Property HashCode, Status #if the file is not filefolder - if($targetFile.mode -eq '-a---') + if($targetFile.mode.Startswith('-a')) { #get the hashcode of the file $hashTable = $targetFile.PSPath.Replace('Microsoft.PowerShell.Core\FileSystem::','') | get-filehash @@ -266,7 +264,7 @@ if($TestName -ne $null -and ($TestName -ne '')) { foreach($blackTestName in $blackTestList) { - if(($fileDetail.Mode -eq 'd----') -and (!$fileDetail.Name.Startswith($blackTestName))) + if(($fileDetail.Mode.Startswith('d')) -and (!$fileDetail.Name.Startswith($blackTestName))) { try { @@ -292,7 +290,7 @@ else { foreach($fileDetail in $fileList) { - if($fileDetail.Mode -eq 'd----' -and (!$fileDetail.Name.Startswith('Compare'))) + if($fileDetail.Mode.Startswith('d') -and (!$fileDetail.Name.Startswith('Compare'))) { $g1 = $PSScriptRoot +'\' +$fileDetail.Name cd ($PSScriptRoot +'\' +$fileDetail.Name) From b6e223518bed0781fe76dbcc3cc085800b70a91b Mon Sep 17 00:00:00 2001 From: Youri Date: Mon, 27 Jul 2020 16:44:38 +0800 Subject: [PATCH 4/4] Fix formatting issues --- tests-upgrade/AutoRestUpgradeTest.ps1 | 46 +++++++++++++-------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/tests-upgrade/AutoRestUpgradeTest.ps1 b/tests-upgrade/AutoRestUpgradeTest.ps1 index e24fda7eb3..1d847ee0d7 100644 --- a/tests-upgrade/AutoRestUpgradeTest.ps1 +++ b/tests-upgrade/AutoRestUpgradeTest.ps1 @@ -105,9 +105,10 @@ function CompareGeneratedCode([string]$inputSourcePath,[string]$inputTargetPath, $ignoreResult = IsNeedIgnore -inputFileName $initFile.FullName -ignoreArray $initIgnoreFileList if(!$ignoreResult) { - $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.Startswith('-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 @@ -129,9 +130,9 @@ function CompareGeneratedCode([string]$inputSourcePath,[string]$inputTargetPath, $ignoreResult = IsNeedIgnore -inputFileName $targetFile.FullName -ignoreArray $targetIgnoreFileList if(!$ignoreResult) { - $obj = "what2" | Select-Object -Property HashCode, Status + $obj = New-Object psobject | Select-Object -Property HashCode, Status #if the file is not filefolder - if($targetFile.mode.Startswith('-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 @@ -150,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) { @@ -192,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 @@ -203,13 +204,12 @@ function CompareGeneratedCode([string]$inputSourcePath,[string]$inputTargetPath, $difArray+=$difDetail } } - Write-Host -ForegroundColor yellow $difArray.Count 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') } } @@ -219,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 } } @@ -241,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 } } @@ -264,17 +262,17 @@ if($TestName -ne $null -and ($TestName -ne '')) { foreach($blackTestName in $blackTestList) { - if(($fileDetail.Mode.Startswith('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 } } @@ -290,19 +288,19 @@ else { foreach($fileDetail in $fileList) { - if($fileDetail.Mode.Startswith('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 } }