From 53ffcc9b5c210389053fc7561e485270a8b6f239 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 3 May 2018 23:30:07 +0200 Subject: [PATCH] Extend run-tests.ps1 by a warning if submodules are not synced I'm contributing to ImageSharp since around a week, and I saw 3 people (myself included) stumbling over failing tests due to the submodule for test data being out of sync. With this commit the run-tests.ps1 test script is extended by the following behaviour: - if something fails during the script run, the submodule status is checked. A warning is printed if - any submodule is not initialized or - any submodule is not synchronized - git could not be called to check the submodule status. --- run-tests.ps1 | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/run-tests.ps1 b/run-tests.ps1 index e13c8fa648..f6279118d4 100644 --- a/run-tests.ps1 +++ b/run-tests.ps1 @@ -15,6 +15,30 @@ function VerifyPath($path, $errorMessage) { } } +function CheckSubmoduleStatus() { + $submoduleStatus = (git submodule status) | Out-String + # if the result string is empty, the command failed to run (we didn't capture the error stream) + if ($submoduleStatus) { + # git has been called successfully, what about the status? + if ($submoduleStatus -contains '-') + { + # submodule has not been initialized! + return 2; + } elseif ($submoduleStatus -contains '+') + { + # submodule is not synced: + return 1; + } else { + # everything fine: + return 0; + } + } else { + # git call failed, so we should warn + return 3; + } +} + + if ( ($targetFramework -eq "netcoreapp2.0") -and ($env:CI -eq "True") -and ($is32Bit -ne "True")) { # We execute CodeCoverage.cmd only for one specific job on CI (netcoreapp2.0 + 64bit ) $testRunnerCmd = ".\tests\CodeCoverage\CodeCoverage.cmd" @@ -64,4 +88,22 @@ Invoke-Expression $testRunnerCmd cd $PSScriptRoot + +if (0 -ne ([int]$LASTEXITCODE)) { + # check submodule status + $submoduleStatus = CheckSubmoduleStatus + if ([int]$submoduleStatus -eq 1) { + # not synced + Write-Host -ForegroundColor Yellow "Check if submodules are up to date. You can use 'git submodule update' to fix this"; + } elseif ($submoduleStatus -eq 2) { + # not initialized + Write-Host -ForegroundColor Yellow "Check if submodules are initialized. You can run 'git submodule init' to initialize them." + } elseif ($submoduleStatus -eq 3) { + # git not found, maybe submodules not synced? + Write-Host -ForegroundColor Yellow "Could not check if submodules are initialized correctly. Maybe git is not installed?" + } else { + #Write-Host "Submodules are up to date"; + } +} + exit $LASTEXITCODE