function Test-Line { param([string]$ReportType, [string]$Result, [string]$Pattern) if(-Not ($Result | Select-String -Quiet -Pattern $Pattern)) { throw "**FAILED**: $ReportType report is missing: $Pattern" } else { Write-Host "**PASS** $ReportType report has: $Pattern" } } function Test-Report { param([string]$ReportType, [string]$Result, [string[]]$Patterns) ForEach($Pattern in $Patterns) { Test-Line $ReportType $Result $Pattern } } $Filename = .\Get-Binary-Name.ps1 $Lines_To_Find = @( "detected java code. we recommend using Corretto" "detected python code. min version 3.7.5 is required" "detected python code. if you need pip, version 19.3 or above is recommended" "dependency library numpy is present. min version 1.19.0 is required" "detected java code. min version 8 is required. version 11 or above is recommended" "using dependency library snappy-java version 1.1.3. upgrade to at least version 1.1.4" "using dependency library hadoop-lzo. this library requires a manual build" "dependency library: leveldbjni-all is not supported on Graviton" "detected go code. min version 1.16 is required. version 1.18 or above is recommended" "using dependency library github.com/golang/snappy version 0.0.1. upgrade to at least version 0.0.2" ) Write-Host "Running samples to console" $ResultConsole = Invoke-Expression ".\dist\$Filename\$Filename.exe .\sample-projects" Test-Report "Console" $ResultConsole $Lines_To_Find Write-Host "Running samples to HTML report" Invoke-Expression ".\dist\$Filename\$Filename.exe .\sample-projects --output test.html" $ResultHtml = Get-Content -Path test.html Test-Report "HTML" $ResultHtml $Lines_To_Find Remove-Item -Path test.html Write-Host "Running samples to Dependency Report" $Dependencies = @( "componentversionoriginfilename" "junit4.8.2" "zstd-jni1.1.0" "snappy-java1.1.3" "lz4-java1.4.0" "hadoop-lzo0.4.17" "leveldbjni-all1.8" "CommandLineParser2.8.0" "Microsoft.Build.Utilities.Core17.1.0" "Microsoft.Extensions.Logging.Console6.0.0" "Microsoft.NET.Test.Sdk16.5.0" "Microsoft.VisualStudio.Setup.Configuration.Interop3.1.2196" "System.Linq.Async6.0.1" "xunit2.4.1" "coverlet.collector1.2.0" "SciPy" "NumPy" "FakeDependency1.2.3" "cors2.8.5" "express4.18.1" "rxjs7.5.6" "socket.io4.5.1" "@codechecks/client0.1.12" "@commitlint/cli17.0.3" "eslint7.32.0" "typescript4.7.4" "github.com/aws/aws-sdk-go" "github.com/golang/snappy" "rails6.1.6.1" "rake11.1" "actionpack" "bcrypt3.1" "cucumber4.1" "gc_tracer" "gssapi" "mail" "turbo-rails" "httpclient" "jruby-openssl" ) Invoke-Expression ".\dist\$Filename\$Filename.exe .\sample-projects --output test.xlsx --output-format dependencies" # xlsx files are compressed files, so we need to unzip them and then compare them Expand-Archive test.xlsx -DestinationPath temp $ResultXlsx = Get-Content ".\temp\xl\sharedStrings.xml" Test-Report "Dependencies" $ResultXlsx $Dependencies Remove-Item -Path test.xlsx Remove-Item -LiteralPath ".\temp" -Force -Recurse Write-Host "--- Running negative tests ---" Write-Host "Running missing arguments test" $MissingArgumentError = $( $Result = & Invoke-Expression ".\dist\$Filename\$Filename.exe" ) 2>&1 if(-Not ($MissingArgumentError | Select-String -Quiet -Pattern "porting-advisor: error: the following arguments are required: DIRECTORY")) { throw "**FAILED**: missing arguments test" } else { Write-Host "**PASSED** missing arguments test" } Write-Host "Running directory not found test" $DirectoryNotFoundError = $( $Result = & Invoke-Expression ".\dist\$Filename\$Filename.exe unexisting_directory" ) 2>&1 if(-Not ($DirectoryNotFoundError | Select-String -Quiet -Pattern "unexisting_directory: directory not found.")) { throw "**FAILED**: directory not found test" } else { Write-Host "**PASSED** directory not found test" } exit 0