Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion public/Invoke-DbaPfRelog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,11 @@ function Invoke-DbaPfRelog {
$allpaths = $allpaths | Where-Object { $_ -match '.blg' } | Select-Object -Unique

if (-not $allpaths) {
Stop-Function -Message "Could not find matching .blg files" -Target $file -Continue
# No -Continue here: the end block has no enclosing loop, so the continue escaped the
# command before the return below ever ran and ate an iteration of the caller's loop.
# The -Continue calls inside the script block below are different: they are caught by the
# per-file foreach that invokes the script block and skip to the next file as intended.
Stop-Function -Message "Could not find matching .blg files" -Target $file
return
}

Expand Down
21 changes: 16 additions & 5 deletions tests/Invoke-DbaPfRelog.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,19 @@ Describe $CommandName -Tag UnitTests {
}
}
}
<#
Integration test should appear below and are custom to the command you are writing.
Read https://github.com/dataplat/dbatools/blob/development/contributing.md#tests
for more guidence.
#>
Describe $CommandName -Tag IntegrationTests {
Context "When no matching blg files exist" {
It "Warns without eating an iteration of the caller's loop" {
# The no-files guard used to run Stop-Function -Continue in the end block, where no loop
# encloses it - the continue escaped the command before its own return statement ran and
# consumed an iteration of this very loop, so the counter fell short (#10638).
$loopCount = 0
foreach ($i in 1..3) {
$null = Invoke-DbaPfRelog -Path "$env:TEMP\dbatoolsci-does-not-exist.txt" -WarningAction SilentlyContinue
$loopCount++
}
$loopCount | Should -Be 3
$WarnVar | Should -BeLike "*Could not find matching*"
}
}
}