Improve Run-Tests.ps1's maintainability and readability (#15407)
Improvements and explanations: * Added proper indentation and spacing for better readability. * Added comments to explain the purpose of different sections of the code. * Utilized the $LASTEXITCODE variable instead of $lastexitcode to ensure consistency. * Changed the variable name from $testdlls to $testDlls for better naming convention. * Moved the Exit 0 statement to the end (outside the if condition). * Since Exit statements terminate the script immediately, it's better to have them at the end of the script to ensure that all necessary cleanup or additional operations are performed before exiting. * These improvements enhance the code's readability, maintainability, and adherence to best practices.
This commit is contained in:
parent
37e8aff967
commit
17596d2623
|
@ -986,6 +986,7 @@ KVM
|
|||
langid
|
||||
LANGUAGELIST
|
||||
lasterror
|
||||
LASTEXITCODE
|
||||
lastexitcode
|
||||
LAYOUTRTL
|
||||
lbl
|
||||
|
|
|
@ -1,27 +1,36 @@
|
|||
[CmdLetBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true, Position=0)][string]$MatchPattern,
|
||||
[Parameter(Mandatory=$true, Position=1)][string]$Platform,
|
||||
[Parameter(Mandatory=$true, Position=2)][string]$Configuration,
|
||||
[Parameter(Mandatory=$false, Position=3)][string]$LogPath,
|
||||
[Parameter(Mandatory=$false)][string]$Root = ".\bin\$Platform\$Configuration"
|
||||
[Parameter(Mandatory=$true, Position=0)]
|
||||
[string]$MatchPattern,
|
||||
[Parameter(Mandatory=$true, Position=1)]
|
||||
[string]$Platform,
|
||||
[Parameter(Mandatory=$true, Position=2)]
|
||||
[string]$Configuration,
|
||||
[Parameter(Mandatory=$false, Position=3)]
|
||||
[string]$LogPath,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]$Root = ".\bin\$Platform\$Configuration"
|
||||
)
|
||||
|
||||
$testdlls = Get-ChildItem -Path "$Root" -Recurse -Filter $MatchPattern
|
||||
# Find test DLLs based on the provided root, match pattern, and recursion
|
||||
$testDlls = Get-ChildItem -Path $Root -Recurse -Filter $MatchPattern
|
||||
|
||||
$args = @()
|
||||
|
||||
$args = @();
|
||||
|
||||
if ($LogPath)
|
||||
{
|
||||
$args += '/enablewttlogging';
|
||||
$args += '/appendwttlogging';
|
||||
$args += "/logFile:$LogPath";
|
||||
Write-Host "Wtt Logging Enabled";
|
||||
# Check if the LogPath parameter is provided and enable WTT logging
|
||||
if ($LogPath) {
|
||||
$args += '/enablewttlogging'
|
||||
$args += '/appendwttlogging'
|
||||
$args += "/logFile:$LogPath"
|
||||
Write-Host "WTT Logging Enabled"
|
||||
}
|
||||
|
||||
&"$Root\te.exe" $args $testdlls.FullName
|
||||
# Invoke the te.exe executable with arguments and test DLLs
|
||||
& "$Root\te.exe" $args $testDlls.FullName
|
||||
|
||||
if ($lastexitcode -Ne 0) { Exit $lastexitcode }
|
||||
# Check the exit code of the te.exe process and exit accordingly
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Exit $LASTEXITCODE
|
||||
}
|
||||
|
||||
Exit 0
|
||||
|
|
Loading…
Reference in New Issue