diff --git a/tests-upgrade/AutoRestUpgradeTest.ps1 b/tests-upgrade/AutoRestUpgradeTest.ps1 index aaaad9bab70..1d847ee0d73 100644 --- a/tests-upgrade/AutoRestUpgradeTest.ps1 +++ b/tests-upgrade/AutoRestUpgradeTest.ps1 @@ -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 @@ -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 @@ -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) { @@ -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 @@ -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') } } @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 } }