fix Connect-To bug #41
@ -24,7 +24,6 @@ image: Visual Studio 2017
|
||||
|
||||
install:
|
||||
- ps: Import-Module .\tools\AppVeyor.psm1
|
||||
- ps: Import-Module .\tools\CoverallsIO.psm1
|
||||
- ps: Invoke-InstallDependencies
|
||||
|
||||
environment:
|
||||
|
@ -122,7 +122,7 @@
|
||||
ReleaseNotes = 'This is a pre-release version!. Do not use in production!'
|
||||
|
||||
# Prerelease string of this module
|
||||
Prerelease = 'alpha1'
|
||||
Prerelease = 'preview'
|
||||
|
||||
# Flag to indicate whether the module requires explicit user acceptance for install/update
|
||||
# RequireLicenseAcceptance = $false
|
||||
|
@ -70,6 +70,11 @@ function Resolve-Dependency {
|
||||
|
||||
process {
|
||||
$SelectedDependency = $Dependency.Optional | Where-Object {$_.Name -match $Name}
|
||||
# return true if there is no dependency defined
|
||||
if ($null -eq $SelectedDependency) {
|
||||
return $true
|
||||
}
|
||||
|
||||
$res = @()
|
||||
foreach ($Module in $SelectedDependency.Modules) {
|
||||
$res += Test-Module -Name $Module
|
||||
|
@ -19,8 +19,8 @@ Describe "Resolve-Dependency" {
|
||||
{ Resolve-Dependency -Name 'awesome'} | Should -Not -Throw
|
||||
}
|
||||
|
||||
It "Missing dependency file should return false" {
|
||||
Resolve-Dependency -Name 'awesome' | Should -Be $false
|
||||
It "Missing dependency file should return true" {
|
||||
Resolve-Dependency -Name 'awesome' | Should -Be $true
|
||||
}
|
||||
}
|
||||
Context "Testing input variations" {
|
||||
|
@ -21,8 +21,8 @@ Function Invoke-InstallDependencies() {
|
||||
Import-PackageProvider -Name NuGet -RequiredVersion '2.8.5.208' -Force
|
||||
Install-Module -Name 'Pester' -Scope CurrentUser -RequiredVersion '4.4.2' -Force -SkipPublisherCheck -AllowClobber
|
||||
Install-Module -Name 'posh-git' -Scope CurrentUser -RequiredVersion '1.0.0-beta2' -Force -SkipPublisherCheck -AllowClobber -AllowPrerelease
|
||||
# Install-Module -Name 'PSCoverage' -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber
|
||||
Import-Module -Name 'Pester', 'posh-git' #, 'PSCoverage'
|
||||
Install-Module -Name 'PSCoverage' -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber -RequiredVersion '1.0.78'
|
||||
Import-Module -Name 'Pester', 'posh-git' , 'PSCoverage'
|
||||
}
|
||||
Catch {
|
||||
$MsgParams = @{
|
||||
|
@ -1,178 +0,0 @@
|
||||
function Get-GitInfo {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$BranchName
|
||||
)
|
||||
|
||||
if ($Env:AppVeyor) {
|
||||
return [PSCustomObject]@{
|
||||
head = [PSCustomObject]@{
|
||||
id = $Env:APPVEYOR_REPO_COMMIT
|
||||
author_name = $Env:APPVEYOR_REPO_COMMIT_AUTHOR
|
||||
author_email = $Env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL
|
||||
comitter_name = $Env:APPVEYOR_REPO_COMMIT_AUTHOR
|
||||
comitter_email = $Env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL
|
||||
message = $Env:APPVEYOR_REPO_COMMIT_MESSAGE
|
||||
}
|
||||
branch = $Env:APPVEYOR_REPO_BRANCH
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (-not $BranchName) {
|
||||
$BranchName = (git rev-parse --abbrev-ref HEAD)
|
||||
}
|
||||
return [PSCustomObject]@{
|
||||
head = [PSCustomObject]@{
|
||||
id = (git log --format="%H" HEAD -1)
|
||||
author_name = (git log --format="%an" HEAD -1)
|
||||
author_email = (git log --format="%ae" HEAD -1)
|
||||
committer_name = (git log --format="%cn" HEAD -1)
|
||||
committer_email = (git log --format="%ce" HEAD -1)
|
||||
message = (git log --format="%s" HEAD -1)
|
||||
}
|
||||
branch = $BranchName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function New-CoverageReport {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[PSCustomObject]$CodeCoverage,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$RepoToken,
|
||||
|
||||
[Parameter(Mandatory = $false)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$ModuleRoot = $(Get-Location)
|
||||
)
|
||||
begin {
|
||||
$CoverReport = [PSCustomObject]@{
|
||||
repo_token = $RepoToken
|
||||
commit_sha = (git log --format="%H" HEAD -1)
|
||||
git = Get-GitInfo
|
||||
service_name = 'appveyor'
|
||||
source_files = @()
|
||||
}
|
||||
}
|
||||
|
||||
process {
|
||||
# Find all files with hit commands -> These file have pester tests
|
||||
$UsedFiles = $CodeCoverage.AnalyzedFiles | Where-Object {
|
||||
$CodeCoverage.HitCommands.File -contains $_
|
||||
}
|
||||
|
||||
foreach ($SourceFile in $UsedFiles) {
|
||||
$Lines = (Get-Content -Path $SourceFile | Measure-Object).Count
|
||||
Write-Verbose ("SourceFile: {0} | LinesCount: {1}" -f $SourceFile, $Lines)
|
||||
$CoverageArray = @()
|
||||
$Hits = 0
|
||||
$Missed = 0
|
||||
|
||||
for ($LinePointer = 1; $LinePointer -le $Lines; $LinePointer++) {
|
||||
|
||||
# Get only hit commands from current src file
|
||||
$curHits = $CodeCoverage.HitCommands | Where-Object {
|
||||
$_.File -eq $SourceFile
|
||||
}
|
||||
[int]$Hits = (
|
||||
$curHits | Where-Object {
|
||||
$_.Line -eq $LinePointer
|
||||
} | Measure-Object
|
||||
).Count
|
||||
|
||||
# again filter only missed commands from the curent file
|
||||
$curMissed = $CodeCoverage.MissedCommands | Where-Object {
|
||||
$_.File -eq $SourceFile
|
||||
}
|
||||
[int]$Missed = (
|
||||
$curMissed | Where-Object {
|
||||
$_.Line -eq $LinePointer
|
||||
} | Measure-Object
|
||||
).Count
|
||||
|
||||
Write-Verbose ("SourceFile:{0} | Line: {1} | Hits: {2} | Missed: {3}" -f $SourceFile, $LinePointer, $Hits, $Missed)
|
||||
if ((-not $Hits -gt 0) -and (-not $Missed -gt 0)) {
|
||||
$CoverageArray += 'null'
|
||||
}
|
||||
else {
|
||||
if ($Hits -gt 0) {
|
||||
$CoverageArray += $Hits
|
||||
}
|
||||
elseif ($Missed -gt 0) {
|
||||
$CoverageArray += 0
|
||||
}
|
||||
}
|
||||
}
|
||||
# Get rid of the quotation
|
||||
$CoverageArray = $CoverageArray -Replace '"', ''
|
||||
$CoverageSourceFile = [PSCustomObject]@{
|
||||
name = $SourceFile.Replace($ModuleRoot, '').Replace('\', '/')
|
||||
source_digest = (Get-FileHash -Path $SourceFile -Algorithm MD5).Hash
|
||||
coverage = $CoverageArray
|
||||
}
|
||||
If ($CoverageSourceFile.Name.StartsWith('/')) {
|
||||
$CoverageSourceFile.Name = $CoverageSourceFile.Name.Remove(0, 1)
|
||||
}
|
||||
$CoverReport.source_files += $CoverageSourceFile
|
||||
}
|
||||
|
||||
# Find all untested files to create a null coverage file
|
||||
$UnUsedFiles = $CodeCoverage.AnalyzedFiles | Where-Object {
|
||||
$CodeCoverage.HitCommands.File -notcontains $_
|
||||
}
|
||||
|
||||
foreach ($UnUsedFile in $UnUsedFiles) {
|
||||
$Lines = (Get-Content -Path $UnUsedFile | Measure-Object).Count
|
||||
$CoverageArray = @()
|
||||
for ($LinePointer = 1; $LinePointer -le $Lines; $LinePointer++) {
|
||||
$CoverageArray += '0'
|
||||
}
|
||||
$CoverageSourceFile = [PSCustomObject]@{
|
||||
name = $UnUsedFile.Replace($ModuleRoot, '').Replace('\', '/')
|
||||
source_digest = (Get-FileHash -Path $UnUsedFile -Algorithm MD5).Hash
|
||||
coverage = $CoverageArray
|
||||
}
|
||||
if ($CoverageSourceFile.Name.StartsWith('/')) {
|
||||
$CoverageSourceFile.Name = $CoverageSourceFile.Name.Remove(0, 1)
|
||||
}
|
||||
$CoverReport.source_files += $CoverageSourceFile
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
Write-Output $CoverReport
|
||||
}
|
||||
}
|
||||
|
||||
function Publish-CoverageReport () {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory = $True)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[PSCustomObject]$CoverageReport
|
||||
)
|
||||
begin {
|
||||
Add-Type -AssemblyName System.Net.Http
|
||||
}
|
||||
|
||||
process {
|
||||
$CoverageJSON = ConvertTo-Json $CoverageReport -Depth 5
|
||||
# Try to fix null elements in coverage array.
|
||||
$CoverageJSON = $CoverageJSON.Replace('"null"', 'null')
|
||||
$stringContent = New-Object System.Net.Http.StringContent ($CoverageJSON)
|
||||
$httpClient = New-Object System.Net.Http.Httpclient
|
||||
$formdata = New-Object System.Net.Http.MultipartFormDataContent
|
||||
$formData.Add($stringContent, "json_file", "coverage.json")
|
||||
$result = $httpClient.PostAsync('https://coveralls.io/api/v1/jobs', $formData).Result
|
||||
$content = $result.Content.ReadAsStringAsync()
|
||||
}
|
||||
|
||||
end {
|
||||
Write-Output $Content
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user