mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-15 07:43:23 +00:00
Add manifest check to tests
This commit is contained in:
16
CI/PS-CI.ps1
16
CI/PS-CI.ps1
@@ -28,7 +28,7 @@ Param(
|
|||||||
[Parameter(ParameterSetName = 'Scope')]
|
[Parameter(ParameterSetName = 'Scope')]
|
||||||
[switch]$CleanModuleDir
|
[switch]$CleanModuleDir
|
||||||
)
|
)
|
||||||
Function Show-warning {
|
Function Show-Warning {
|
||||||
param(
|
param(
|
||||||
[Parameter(Position=0,ValueFromPipeline=$true)]
|
[Parameter(Position=0,ValueFromPipeline=$true)]
|
||||||
$message
|
$message
|
||||||
@@ -49,8 +49,10 @@ if (-not $psdpath -or $psdpath.count -gt 1) {
|
|||||||
throw "Did not find a unique PSD file "
|
throw "Did not find a unique PSD file "
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
try {$settings = Test-ModuleManifest -Path $psdpath -ErrorAction stop}
|
||||||
|
catch {throw $_ ; return}
|
||||||
$ModuleName = $psdpath.Name -replace '\.psd1$' , ''
|
$ModuleName = $psdpath.Name -replace '\.psd1$' , ''
|
||||||
$Settings = $(& ([scriptblock]::Create(($psdpath | Get-Content -Raw))))
|
# $Settings = $(& ([scriptblock]::Create(($psdpath | Get-Content -Raw))))
|
||||||
$approvedVerbs = Get-Verb | Select-Object -ExpandProperty verb
|
$approvedVerbs = Get-Verb | Select-Object -ExpandProperty verb
|
||||||
$script:warningfile = Join-Path -Path $pwd -ChildPath "warnings.txt"
|
$script:warningfile = Join-Path -Path $pwd -ChildPath "warnings.txt"
|
||||||
}
|
}
|
||||||
@@ -61,7 +63,7 @@ if (-not $SkipPreChecks) {
|
|||||||
#Check files in the manifest are present
|
#Check files in the manifest are present
|
||||||
foreach ($file in $Settings.FileList) {
|
foreach ($file in $Settings.FileList) {
|
||||||
if (-not (Test-Path $file)) {
|
if (-not (Test-Path $file)) {
|
||||||
show-warning "File $file in the manifest file list is not present"
|
Show-Warning "File $file in the manifest file list is not present"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +87,7 @@ if (-not $SkipPreChecks) {
|
|||||||
$name = $file.name -replace(".ps1","")
|
$name = $file.name -replace(".ps1","")
|
||||||
if ($name -notmatch ("(\w+)-\w+")) {Show-Warning "$name in the public folder is not a verb-noun name"}
|
if ($name -notmatch ("(\w+)-\w+")) {Show-Warning "$name in the public folder is not a verb-noun name"}
|
||||||
elseif ($Matches[1] -notin $approvedVerbs) {Show-Warning "$name in the public folder does not start with an approved verb"}
|
elseif ($Matches[1] -notin $approvedVerbs) {Show-Warning "$name in the public folder does not start with an approved verb"}
|
||||||
if(-not ($Settings.FunctionsToExport -ceq $name)) {
|
if(-not ($Settings.ExportedFunctions.Keys -ceq $name)) {
|
||||||
Show-Warning ('File {0} in the public folder does not match an exported function in the manifest' -f $file.name)
|
Show-Warning ('File {0} in the public folder does not match an exported function in the manifest' -f $file.name)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -102,7 +104,7 @@ if (-not $SkipPreChecks) {
|
|||||||
if ($m2.value -match "(?<!#\s*)\[\s*Alias\(\s*.([\w-]+).\s*\)\s*\]") {
|
if ($m2.value -match "(?<!#\s*)\[\s*Alias\(\s*.([\w-]+).\s*\)\s*\]") {
|
||||||
foreach ($a in ($Matches[1] -split '\s*,\s*')) {
|
foreach ($a in ($Matches[1] -split '\s*,\s*')) {
|
||||||
$a = $a -replace "'","" -replace '"',''
|
$a = $a -replace "'","" -replace '"',''
|
||||||
if (-not ($Settings.AliasesToExport -eq $a)) {
|
if (-not ($Settings.ExportedAliases.Keys -eq $a)) {
|
||||||
Show-Warning "Function $name has alias $a which is not in the manifest"
|
Show-Warning "Function $name has alias $a which is not in the manifest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,7 +117,7 @@ if (-not $SkipPreChecks) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#Warn about functions which are exported but not found in public
|
#Warn about functions which are exported but not found in public
|
||||||
$notFromPublic = $Settings.FunctionsToExport.where({-not (Test-Path ".\public\$_.ps1")})
|
$notFromPublic = $Settings.ExportedFunctions.Keys.Where({-not (Test-Path ".\public\$_.ps1")})
|
||||||
If ($notFromPublic) {Show-Warning ('Exported function(s) {0} are not loaded from the Public folder' -f ($notFromPublic -join ', '))}
|
If ($notFromPublic) {Show-Warning ('Exported function(s) {0} are not loaded from the Public folder' -f ($notFromPublic -join ', '))}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +133,7 @@ try {
|
|||||||
else { $dir = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::ProgramFiles) }
|
else { $dir = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::ProgramFiles) }
|
||||||
$ModulePath = ($env:PSModulePath -split $ModulePathSeparator).where({$_ -like "$dir*"},"First",1)
|
$ModulePath = ($env:PSModulePath -split $ModulePathSeparator).where({$_ -like "$dir*"},"First",1)
|
||||||
$ModulePath = Join-Path -Path $ModulePath -ChildPath $ModuleName
|
$ModulePath = Join-Path -Path $ModulePath -ChildPath $ModuleName
|
||||||
$ModulePath = Join-Path -Path $ModulePath -ChildPath $Settings.ModuleVersion
|
$ModulePath = Join-Path -Path $ModulePath -ChildPath $Settings.Version.ToString()
|
||||||
}
|
}
|
||||||
|
|
||||||
# Clean-up / Create Directory
|
# Clean-up / Create Directory
|
||||||
|
|||||||
@@ -10,17 +10,20 @@ Describe "Tests" {
|
|||||||
$data = Import-Excel $PSScriptRoot\Simple.xlsx
|
$data = Import-Excel $PSScriptRoot\Simple.xlsx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
It "Should have a valid manifest".PadRight(90){
|
||||||
It "Should have two items".PadRight(90) {
|
{try {Test-ModuleManifest -Path $PSScriptRoot\..\..\ImportExcel.psd1 -ErrorAction stop}
|
||||||
|
catch {throw} } | should not throw
|
||||||
|
}
|
||||||
|
It "Should have two items in the imported simple data".PadRight(90) {
|
||||||
$data.count | Should be 2
|
$data.count | Should be 2
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should have items a and b".PadRight(90) {
|
It "Should have items a and b in the imported simple data".PadRight(90) {
|
||||||
$data[0].p1 | Should be "a"
|
$data[0].p1 | Should be "a"
|
||||||
$data[1].p1 | Should be "b"
|
$data[1].p1 | Should be "b"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should read fast < 2100 milliseconds".PadRight(90) {
|
It "Should read the simple xlsx in < 2100 milliseconds".PadRight(90) {
|
||||||
$timer.TotalMilliseconds | should BeLessThan 2100
|
$timer.TotalMilliseconds | should BeLessThan 2100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user