Skip to content

Commit

Permalink
fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cklutz committed Sep 6, 2017
1 parent e64e7ce commit 57c0a9a
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 31 deletions.
10 changes: 5 additions & 5 deletions Tasks/RunOpenCover/Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function Get-InstalledVisualStudioInfo {
}

# If the type has already been loaded once, then it is not loaded again.
Write-Host "Adding Visual Studio setup helpers."
Write-Verbose "Adding Visual Studio setup helpers."
Add-Type -Debug:$false -TypeDefinition @'
namespace CapabilityHelpers.VisualStudio.Setup
{
Expand Down Expand Up @@ -205,16 +205,16 @@ namespace CapabilityHelpers.VisualStudio.Setup.Com
}
}
'@
Write-Host "Getting Visual Studio setup instances."
Write-Verbose "Getting Visual Studio setup instances."
$instances = @( [CapabilityHelpers.VisualStudio.Setup.Instance]::GetInstances() )
Write-Host "Found $($instances.Count) instances."
Write-Host ($instances | Format-List * | Out-String)
Write-Verbose "Found $($instances.Count) instances."
Write-Verbose ($instances | Format-List * | Out-String)
return $instances |
Where-Object { $_.Version.Major -eq $major } |
Sort-Object -Descending -Property Version |
Select-Object -First 1
} catch {
Write-Host ($_ | Out-String)
Write-Verbose ($_ | Out-String)
}
}

Expand Down
6 changes: 3 additions & 3 deletions Tasks/RunOpenCover/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ Use the following options to select tests and control how the tests are run and

- **Run in Parallel:** If set, tests will run in parallel leveraging available cores of the machine. [Click here](https://aka.ms/paralleltestexecution) to learn more about how tests are run in parallel.

- **OpenCover Filter Criteria:** Filter what should be considered by OpenCover for code coverage. For example, "-\*[\*Tests.\*]".
- **OpenCover Filter Criteria:** Filter what should be considered by OpenCover for code coverage. For example, "-\*[\*Tests.\*]". [Click here](https://github.com/opencover/opencover/wiki/Usage#understanding-filters) to learn more about how OpenCover filters work.

- **Disable OpenCover:** This allows you to only run the tests and not run OpenCover. Thus, the tasks behaves similar to to stock VSTest task from TFS / VSTS.

#### Advanced Execution Options

- **VSTest version:** Choose which version of Visual Studio (vstest.console.exe) to run tests with.

- **Path to Custom Test Adapters:** Path to the testadapter for the framework in which the specified tests are written. Provided directory and all subdirectories are checked for testadapters. If there is a packages folder in the sources directory, it is automatically searched for testadapters. As a result, any testadapter downloaded as a Nuget package will be used without any input. For example, ‘$(Build.SourcesDirectory)\Fabrikam\packages’
- **Path to Custom Test Adapters:** Path to the testadapter for the framework in which the specified tests are written. Provided directory and all subdirectories are checked for testadapters. If there is a packages (or .packages) folder in the sources directory, it is automatically searched for testadapters. As a result, any testadapter downloaded as a Nuget package will be used without any input. For example, ‘$(Build.SourcesDirectory)\Fabrikam\packages’

- **Additional VSTest Options:** Other options that can be provided to vstest.console.exe.

- **Additional OpenConver Options:** Other options that can be provided to OpenCover.Console.exe. For example, `-threshold:1 -skipautoprops`.
- **Additional OpenCover Options:** Other options that can be provided to OpenCover.Console.exe. For example, `-threshold:1 -skipautoprops`.

- **OpenCover Tools:** Choose which version of OpenCover Tools (OpenCover.exe, ReportGenerator.exe and OpenCoverToCoberturaConverter.exe) is used. Either the version packaged with task, or versions located in a common base directory, which can be specified here.

Expand Down
51 changes: 37 additions & 14 deletions Tasks/RunOpenCover/RunOpenCover.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ if (!$taskMode) {
Import-Module "$PSScriptRoot\ps_modules\VstsTaskSdk"
}

function IsDebugEnabled {
return ($env:system_debug -ieq 'true')
}

function GetDiagFileName($vstestCommand, $runId) {
if (IsDebugEnabled) {
$versionInfo = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($vstestCommand)
if ($versionInfo.ProductMajorPart -gt 15 -Or `
($versionInfo.ProductMajorPart -eq 15 -And ($versionInfo.ProductMinorPart -gt 0 -or $versionInfo.ProductBuildPart -ge 25428)) ){
return [System.IO.Path]::GetTempFileName() + '-' + $runId + '-vstest.log'
}
}
return $null;
}

function UploadDiagFile($fileName) {
if ($fileName -And (Test-Path $fileName)) {
SendCommand 'task.uploadfile' $null $fileName
}
}

function SendCommand($commandName, $properties, $data) {
$command = '##vso['
$command += $commandName
Expand Down Expand Up @@ -62,12 +83,12 @@ function SendCommand($commandName, $properties, $data) {
}

function FindCommand ($directory, $commandName) {
Write-Host "Checking for '$commandName' in '$directory' tree"
Write-Verbose "Checking for '$commandName' in '$directory' tree"
$results = Get-ChildItem -Path $directory -Filter $commandName -Recurse -ErrorAction SilentlyContinue -Force
if (!$results -or $results.Length -eq 0) {
throw "Command '$commandName' not found in directory tree '$directory' (source directory)."
}
Write-Host "Using $($results[0].FullName)"
Write-Verbose "Using $($results[0].FullName)"
return $results[0].FullName
}

Expand All @@ -81,11 +102,12 @@ try {
}

if ($toolsBaseDirectory) {
Write-Verbose "Trying to find tools in $toolsBaseDirectory."
$openCoverConsoleExe = FindCommand $toolsBaseDirectory "OpenCover.Console.exe"
$coberturaConverterExe = FindCommand $toolsBaseDirectory "OpenCoverToCoberturaConverter.exe"
$reportGeneratorExe = FindCommand $toolsBaseDirectory "ReportGenerator.exe"
} else {
Write-Host "Using packaged tools."
Write-Verbose "Using packaged tools."
$openCoverConsoleExe = "$PSScriptRoot\tools\OpenCover\OpenCover.Console.exe"
$coberturaConverterExe = "$PSScriptRoot\tools\OpenCoverToCoberturaConverter\OpenCoverToCoberturaConverter.exe"
$reportGeneratorExe = "$PSScriptRoot\tools\ReportGenerator\ReportGenerator.exe"
Expand All @@ -96,7 +118,8 @@ try {
} else {
$vsconsoleExe = "$env:VS140COMNTOOLS\..\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
}
Write-Host "Using VSTest: $vsconsoleExe"

Write-Verbose "Using VSTest: $vsconsoleExe"

# resolve test assembly files (copied from VSTest.ps1)
$testAssemblyFiles = @()
Expand Down Expand Up @@ -134,36 +157,34 @@ try {
# Create tempDir underneath sources so that any publish-artificats task
# don't pick stuff up accidentally.
$tempDir = $sourcesDirectory + "\CoverageResults"
# if ($runTitle) {
# $tempDir += '\' + $runTitle
# }
# if (Test-Path $tempDir) {
# Remove-Item -Path $tempDir -Recurse -Force
# }

if (-Not (Test-Path $tempDir)) {
New-Item -Path $tempDir -ItemType Directory | Out-Null
}
$runId = $runTitle
if (!$runId) {
$runId = [Guid]::NewGuid().ToString("N")
}
Write-Verbose "Test run ID is ${runId}."

$trxDir = "$tempDir\$runId"
if (Test-path $trxDir) {
Remove-Item -Recurse -Path $trxDir | Out-Null
}
New-Item -Path $trxDir -ItemType Directory | Out-Null

$diagFileName = GetDiagFileName $vsconsoleExe $runId

$vsconsoleArgs = $testFilesString
if ($testAdapterPath) { $vsconsoleArgs += " /TestAdapterPath:""$testAdapterPath""" }
if ($testFilterCriteria) { $vsconsoleArgs += " /TestCaseFilter:""$testFiltercriteria""" }
if ($runSettingsFile) { $vsconsoleArgs += " /Settings:""$runSettingsFile""" }
if ($diagFileName) { $vsconsoleArgs += " /diag:""$diagFileName""" }
$vsconsoleArgs += " /logger:trx"
if ($testAdditionalCommandLine) {
if ($testAdditionalCommandLine) {
$vsconsoleArgs += " "
$vsconsoleArgs += $testAdditionalCommandLine
}

if (!$disableCodeCoverage) {
# According to "https://github.com/OpenCover/opencover/wiki/Usage",
# "Notes on Spaces in Arguments", to preserve quotes in -targetargs,
Expand All @@ -188,6 +209,7 @@ try {
$openCoverConsoleArgs += " -output:""$openCoverReport"""
$openCoverConsoleArgs += " -mergebyhash"
$openCoverConsoleArgs += " -returntargetcode"
if (IsDebugEnabled) { $openCoverConsoleArgs += " -log:Debug" }
if ($openCoverAdditionalCommandLine) {
$openCoverConsoleArgs += " "
$openCoverConsoleArgs += $openCoverAdditionalCommandLine
Expand Down Expand Up @@ -219,7 +241,8 @@ try {
}

SendCommand 'results.publish' $testResultParameters ''

UploadDiagFile $diagFileName

if (!$disableCodeCoverage) {
# Publish code coverage data.
$codeCoverageParameters = [ordered]@{
Expand Down
6 changes: 3 additions & 3 deletions Tasks/RunOpenCover/RunOpenCoverTask.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ try {
}
$vsTestCommand = $vstestLocation
} elseif ($vsTestVersion) {
Write-Host "Using specified VSTest version: $vsTestVersion"
Write-Verbose "Using specified VSTest version: $vsTestVersion"
if ($vsTestVersion -eq "14.0") {
$vs14Path = Get-VsVersionFolder -Version $vsTestVersion
if (!$vs14Path) {
Expand All @@ -86,7 +86,7 @@ try {
if (!$vsTestCommand) {
# Nothing found, fallback to latest
$vsPath = Get-LatestVsVersionFolder
Write-Host "Latest VS Version in $vsPath"
Write-Verbose "Latest VS Version in $vsPath"
if (!$vsPath) {
throw "Specified version '$vsTestVersion' not found. Couldn't find any installed Visual Studio version."
}
Expand Down Expand Up @@ -127,7 +127,7 @@ try {
} catch {

Write-Host "----------------------------------------------------------------------------"
$_ | format-list * -Force
$_ | format-list * -Force | Out-Host
Write-Host "----------------------------------------------------------------------------"

throw $_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"loc.input.help.testFiltercriteria": "Additional criteria to filter tests from Test assemblies. For example: Priority=1|Name=MyTestMethod",
"loc.input.label.runSettingsFile": "Run Settings File",
"loc.input.help.runSettingsFile": "Path to runsettings file to use with the tests. Use `$(Build.SourcesDirectory)` to access the Project folder.",
"loc.input.label.runInParallel": "Run In Parallel (Experimental)",
"loc.input.help.runInParallel": "Enable parallel execution of your tests (Experimental).",
"loc.input.label.runInParallel": "Run In Parallel",
"loc.input.help.runInParallel": "Enable parallel execution of your tests.",
"loc.input.label.openCoverFilters": "OpenCover Filter criteria",
"loc.input.help.openCoverFilters": "Additional criteria to filter what OpenCover considers.",
"loc.input.label.disableCodeCoverage": "Disable OpenCover",
Expand All @@ -26,7 +26,7 @@
"loc.input.label.vstestLocation": "Path to vstest.console.exe",
"loc.input.help.vstestLocation": "Optionally supply the path to VSTest.",
"loc.input.label.testAdapterPath": "Path to Custom Test Adapters",
"loc.input.help.testAdapterPath": "Directory path to custom test adapters. For example, `$(build.SourcesDirectory)\\packages`.",
"loc.input.help.testAdapterPath": "Directory path to custom test adapters. The folder and all subdirectories are search for adapters. `$(build.sourcesDirectory)\\packages` or `$(build.sourcesDirectory)\\.packages` are considered, if no input is specified.",
"loc.input.label.testAdditionalCommandLine": "Additional VSTest Options",
"loc.input.help.testAdditionalCommandLine": "Other Console options that can be passed to vstest.console.exe. See [MSDN](https://msdn.microsoft.com/en-us/library/jj155796.aspx) for more information.",
"loc.input.label.openCoverAdditionalCommandLine": "Additional OpenCover Options",
Expand Down
4 changes: 2 additions & 2 deletions Tasks/RunOpenCover/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 15
"Patch": 22
},
"minimumAgentVersion": "1.95.0",
"instanceNameFormat": "Tests/Coverage - $(testAssembly)",
Expand Down Expand Up @@ -145,7 +145,7 @@
"label": "Path to Custom Test Adapters",
"defaultValue": "",
"required": false,
"helpMarkDown": "Directory path to custom test adapters. For example, `$(build.SourcesDirectory)\\packages`.",
"helpMarkDown": "Directory path to custom test adapters. The folder and all subdirectories are search for adapters. `$(build.sourcesDirectory)\\packages` or `$(build.sourcesDirectory)\\.packages` are considered, if no input is specified.",
"groupName": "advancedExecutionOptions"
},
{
Expand Down
2 changes: 1 addition & 1 deletion Tasks/RunOpenCover/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"version": {
"Major": 1,
"Minor": 0,
"Patch": 15
"Patch": 22
},
"minimumAgentVersion": "1.95.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down
8 changes: 8 additions & 0 deletions build-full.cmd
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
@echo off
setlocal
set TFX_TRACE=1

call:exec npm install || exit /b 1
call:exec node make.js bump || exit /b 1
call:exec npm run build || exit /b 1
call:exec npm test || exit /b 1
call:exec node make.js package || exit /b 1

if /i ["%~1"] == ["--upload"] (
for /D %%i in ("%~dp0_build\Tasks\*") do (
call:exec tfx build tasks upload --task.path "%%~i" || exit /b 1
)
)

exit /b 0

:exec
Expand Down

0 comments on commit 57c0a9a

Please sign in to comment.