Skip to content

Commit

Permalink
Changes to common tests
Browse files Browse the repository at this point in the history
- When common tests are running on another repository than DscResource.Tests the
  DscResource.Tests unit and integration tests are removed from the list of tests
  to run (issue PowerShell#189).
  • Loading branch information
johlju committed Aug 31, 2017
1 parent 8457973 commit a630afb
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 31 deletions.
34 changes: 25 additions & 9 deletions AppVeyor.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,27 @@ function Invoke-AppveyorTestScriptTask
}
}

$getChildItemParameters = @{
Path = $env:APPVEYOR_BUILD_FOLDER
Recurse = $true
}

# Get all tests '*.Tests.ps1'.
$getChildItemParameters['Filter'] = '*.Tests.ps1'
$testFiles = Get-ChildItem @getChildItemParameters

<#
If it is another repository other than DscResource.Tests
then remove the DscResource.Tests unit tests from the list
of tests to run. Issue #189.
#>
if( -not (Test-IsRepositoryDscResourceTests))
{
$testFiles = $testFiles | Where-Object -FilterScript {
$_.FullName -notmatch 'DSCResource.Tests\\Tests'
}
}

if ($RunTestInOrder)
{
<#
Expand All @@ -275,15 +296,6 @@ function Invoke-AppveyorTestScriptTask
#>
$testObjects = @()

$getChildItemParameters = @{
Path = $env:APPVEYOR_BUILD_FOLDER
Recurse = $true
}

# Get all tests '*.Tests.ps1'.
$getChildItemParameters['Filter'] = '*.Tests.ps1'
$testFiles = Get-ChildItem @getChildItemParameters

# Add all tests to the array with order number set to $null
foreach ($testFile in $testFiles)
{
Expand Down Expand Up @@ -380,6 +392,10 @@ function Invoke-AppveyorTestScriptTask
}
else
{
$pesterParameters += @{
Path = $testFiles.FullName
}

$results = Invoke-Pester @pesterParameters
}

Expand Down
24 changes: 3 additions & 21 deletions Meta.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,13 @@ $errorActionPreference = 'Stop'
$testHelperModulePath = Join-Path -Path $PSScriptRoot -ChildPath 'TestHelper.psm1'
Import-Module -Name $testHelperModulePath

$moduleRootFilePath = Split-Path -Path $PSScriptRoot -Parent

<#
This is a workaround to be able to run these common test on DscResource.Tests
module, for testing itself.
We need to determine if we are running the code on the repository
DscResource.Tests or some other resource module.
If the parent folder does NOT contain a module manifest we will assume that
DscResource.Test is the module being tested.
Example:
Current folder: c:\source\DscResource.Tests
Parent folder: c:\source
Module manifest: $null
If the parent folder do contain a module manifest we will assume that
DscResource.Test has been cloned into another resource module and it is
that resource module that is being tested.
Example:
Current folder: c:\source\xSQLServer\DscResource.Tests
Parent folder: c:\source\xSQLServer
Module manifest: c:\source\xSQLServer\xSQLServer.psd1
#>
$moduleRootFilePath = Split-Path -Path $PSScriptRoot -Parent

$moduleManifestExistInModuleRootFilePath = Get-ChildItem -Path $moduleRootFilePath -Filter '*.psd1'
if (-not $moduleManifestExistInModuleRootFilePath)
if (Test-IsRepositoryDscResourceTests)
{
$moduleRootFilePath = $PSScriptRoot

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ Configuration MSFT_xSQLServerAlwaysOnService_EnableAlwaysOn_Config
without having to merge the pull request before seeing the result.
* Add opt-in parameter RunTestInOrder for the helper function Invoke-AppveyorTestScriptTask
which enables running integration tests in order ([issue #184](https://github.com/PowerShell/DscResource.Tests/issues/184)).
* When common tests are running on another repository than DscResource.Tests the
DscResource.Tests unit and integration tests are removed from the list of tests
to run ([issue #189](https://github.com/PowerShell/DscResource.Tests/issues/189)).

### 0.2.0.0

Expand Down
49 changes: 48 additions & 1 deletion TestHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,52 @@ function Get-DscIntegrationTestOrderNumber
return $returnValue
}

<#
.SYNOPSIS
Returns $true if the current repository being tested is
DscResource.Tests, otherwise the value returned will be
$false.
#>
function Test-IsRepositoryDscResourceTests
{
[CmdletBinding()]
[OutputType([System.Boolean])]
param
(
)

<#
We need to determine if we are running the code on the repository
DscResource.Tests or some other resource module.
If the parent folder does NOT contain a module manifest we will assume that
DscResource.Test is the module being tested.
Example:
Current folder: c:\source\DscResource.Tests
Parent folder: c:\source
Module manifest: $null
If the parent folder do contain a module manifest we will assume that
DscResource.Test has been cloned into another resource module and it is
that resource module that is being tested.
Example:
Current folder: c:\source\xSQLServer\DscResource.Tests
Parent folder: c:\source\xSQLServer
Module manifest: c:\source\xSQLServer\xSQLServer.psd1
#>
$moduleRootFilePath = Split-Path -Path $PSScriptRoot -Parent

$moduleManifestExistInModuleRootFilePath = Get-ChildItem -Path $moduleRootFilePath -Filter '*.psd1'
if (-not $moduleManifestExistInModuleRootFilePath)
{
return $true
}
else
{
return $false
}
}

Export-ModuleMember -Function @(
'New-Nuspec', `
'Install-ModuleFromPowerShellGallery', `
Expand All @@ -1344,5 +1390,6 @@ Export-ModuleMember -Function @(
'Get-RelativePathFromModuleRoot',
'Get-ResourceModulesInConfiguration',
'Install-DependentModule',
'Get-DscIntegrationTestOrderNumber'
'Get-DscIntegrationTestOrderNumber',
'Test-IsRepositoryDscResourceTests'
)

0 comments on commit a630afb

Please sign in to comment.