Skip to content

Commit

Permalink
chore: add TestsDebug parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
lemeurherve committed Jun 23, 2024
1 parent 974969e commit 22934df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
12 changes: 11 additions & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ Param(
[String] $AgentType = '',
[String] $BuildNumber = '1',
[switch] $DisableEnvProps = $false,
[switch] $DryRun = $false
[switch] $DryRun = $false,
# Output debug info for tests. Accepted values:
# - empty (no additional test output)
# - 'debug' (test cmd & stderr outputed)
# - 'verbose' (test cmd, stderr, stdout outputed)
[String] $TestsDebug = ''
)

$ErrorActionPreference = 'Stop'
Expand All @@ -27,6 +32,11 @@ $Repository = @{
'inbound-agent' = 'inbound-agent'
}

if(![String]::IsNullOrWhiteSpace($env:TESTS_DEBUG)) {
$TestsDebug = $env:TESTS_DEBUG
}
$env:TESTS_DEBUG = $TestsDebug

if(!$DisableEnvProps) {
Get-Content env.props | ForEach-Object {
$items = $_.Split("=")
Expand Down
15 changes: 9 additions & 6 deletions tests/test_helpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function Is-ContainerRunning($container='') {
}
}

function Run-Program($cmd, $params, $quiet=$true) {
function Run-Program($cmd, $params) {
if(-not $quiet) {
Write-Host "cmd & params: $cmd $params"
}
Expand All @@ -115,11 +115,14 @@ function Run-Program($cmd, $params, $quiet=$true) {
$stdout = $proc.StandardOutput.ReadToEnd()
$stderr = $proc.StandardError.ReadToEnd()
$proc.WaitForExit()
if(($proc.ExitCode -ne 0) -and (-not $quiet)) {
Write-Host "[err] stdout:`n$stdout"
Write-Host "[err] stderr:`n$stderr"
Write-Host "[err] cmd:`n$cmd"
Write-Host "[err] params:`n$param"
if(($env:TESTS_DEBUG -eq 'debug') -or ($env:TESTS_DEBUG -eq 'verbose')) {
Write-Host -ForegroundColor DarkBlue "[cmd] $cmd $params"
if ($env:TESTS_DEBUG -eq 'verbose') {
Write-Host -ForegroundColor DarkGray "[stdout] $stdout"
}
if($proc.ExitCode -ne 0){
Write-Host -ForegroundColor DarkRed "[stderr] $stderr"
}
}

return $proc.ExitCode, $stdout, $stderr
Expand Down

0 comments on commit 22934df

Please sign in to comment.