Created
December 5, 2018 09:04
-
-
Save DanielSundberg/919aa09af577dfc778aae018defb15f0 to your computer and use it in GitHub Desktop.
Powershell Run a Command And Count Errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run command and count errors | |
# I use this to gather statistics about flaky tests: | |
# | |
# > RunCommandAndCountErrors "python -mpytest -ktest_some_flaky_test .\test_tests.py" 10 | |
# ... | |
# ... | |
# Test 10, nofErrors: 3 | |
# Nof test runs: 10, nof errors: 3 | |
# > _ | |
function RunCommandAndCountErrors($cmd, $reps) | |
{ | |
$nofErrors = 0 | |
$cnt = 0 | |
for ($i = 1; $i -le $reps; $i++) { | |
Invoke-Expression $cmd | |
$ec = $LASTEXITCODE | |
write-host "Last exit code: $ec" | |
$cnt++ | |
if ($ec -ne 0) { | |
$nofErrors++ | |
write-host "Increasing nofErrors: $nofErrors" | |
} | |
write-host "Test $cnt of $reps, nofErrors: $nofErrors" | |
} | |
write-host "Nof test runs: $cnt, nof errors: $nofErrors" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment