From 17596d26236d01882882e1ad8f2273a69238d2ed Mon Sep 17 00:00:00 2001 From: Jvr for school <109031036+Jvr2022@users.noreply.github.com> Date: Sat, 10 Jun 2023 01:06:29 +0200 Subject: [PATCH] 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. --- .github/actions/spelling/expect/expect.txt | 1 + build/scripts/Run-Tests.ps1 | 41 +++++++++++++--------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/.github/actions/spelling/expect/expect.txt b/.github/actions/spelling/expect/expect.txt index 24a772ad0a..20c920b407 100644 --- a/.github/actions/spelling/expect/expect.txt +++ b/.github/actions/spelling/expect/expect.txt @@ -986,6 +986,7 @@ KVM langid LANGUAGELIST lasterror +LASTEXITCODE lastexitcode LAYOUTRTL lbl diff --git a/build/scripts/Run-Tests.ps1 b/build/scripts/Run-Tests.ps1 index ea69396569..1e52a8757e 100644 --- a/build/scripts/Run-Tests.ps1 +++ b/build/scripts/Run-Tests.ps1 @@ -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