diff --git a/CHANGELOG.md b/CHANGELOG.md index 41263ef..4580528 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,18 @@ All notable changes to the [PSTK](https://github.com/Akaizoku/PSTK) project will The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [1.2.0](https://github.com/Akaizoku/PSTK/releases/tag/1.1.0) - 2019-09-12 +## [1.2.1](https://github.com/Akaizoku/PSTK/releases/tag/1.2.1) - 2019-10-01 + +Hotfix to enable overwriting empty properties. + +### Changed +The following functions have been updated: +- Get-Properties +- Import-Properties + +## [1.2.0](https://github.com/Akaizoku/PSTK/releases/tag/1.2.0) - 2019-09-12 + +Expansion ### Added The following functions have been added: diff --git a/PSTK.psd1 b/PSTK.psd1 index 32a91eb..69d136a 100644 --- a/PSTK.psd1 +++ b/PSTK.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSTK.psm1' # Version number of this module.s -ModuleVersion = '1.2.0' +ModuleVersion = '1.2.1' # Supported PSEditions # CompatiblePSEditions = @() @@ -151,6 +151,9 @@ PrivateData = @{ # ReleaseNotes of this module ReleaseNotes = @' +## 1.2.1 +Fixed an issue with empty properties not being overwritten as expected + ## 1.2.0 Added support for global preferences Expanded existing functions diff --git a/Tests/Add-Offset.ps1 b/Tests/Add-Offset.ps1 deleted file mode 100644 index 9d307b4..0000000 --- a/Tests/Add-Offset.ps1 +++ /dev/null @@ -1,79 +0,0 @@ -<# - .SYNOPSIS - Add-Offset Unit Testing - - .DESCRIPTION - Unit Test for Add-Offset function from PSTK module - - .NOTES - File name: Add-Offset.ps1 - Author: Florian Carrier - Creation date: 15/10/2018 - Last modified: 15/10/2018 -#> - -# ------------------------------------------------------------------------------ -# Initialisation -# ------------------------------------------------------------------------------ -$Path = Split-Path -Path (Split-Path -Path $MyInvocation.MyCommand.Definition) -Parent -$Repository = Join-Path -Path $Path -ChildPath "Private" -# Import functions -$Scripts = @( - $MyInvocation.MyCommand.Name, - "Test-Alphanumeric.ps1" -) -foreach ($Script in $Scripts) { - $Link = Join-Path -Path $Repository -ChildPath $Script - . $Link -} -# ------------------------------------------------------------------------------ -# Test objects -# ------------------------------------------------------------------------------ -# Reference -$Reference = @( - "a1", - "b2", - "g7", - "z26" -) - -# + 2 -$Positive = @( - "a3", - "b4", - "g9", - "z28" -) - -# - 3 -$Negative = @( - "a0", - "b1", - "g6", - "z25" -) - -# ------------------------------------------------------------------------------ -# Test -# ------------------------------------------------------------------------------ -$PositiveCounter = 0 -$NegativeCounter = 0 -for ($i=0; $i -lt $Reference.Length; $i++) { - $NewPositiveValue = Add-Offset -Alphanumeric $Reference[$i] -Offset 2 - if ($NewPositiveValue -eq $Positive[$i]) { $PositiveCounter += 1 } - $NewNegativeValue = Add-Offset -Alphanumeric $Reference[$i] -Offset -1 - if ($NewNegativeValue -eq $Negative[$i]) { $NegativeCounter += 1 } -} -if ($PositiveCounter -eq $Reference.Length) { $CheckPositive = $true } -else { $CheckPositive = $false } -if ($NegativeCounter -eq $Reference.Length) { $CheckNegative = $true } -else { $CheckNegative = $false } - -# ------------------------------------------------------------------------------ -# Check outcome -# ------------------------------------------------------------------------------ -if ($CheckPositive -And $CheckNegative) { - return $true -} else { - return $false -} diff --git a/Tests/Compare-Hashtable.ps1 b/Tests/Compare-Hashtable.ps1 deleted file mode 100644 index 3758d17..0000000 --- a/Tests/Compare-Hashtable.ps1 +++ /dev/null @@ -1,67 +0,0 @@ -<# - .SYNOPSIS - Compare-Hashtable Unit Testing - - .DESCRIPTION - Unit Test for Compare-Hashtable function from PSTK module - - .NOTES - File name: Compare-Hashtable.ps1 - Author: Florian Carrier - Creation date: 31/08/2018 - Last modified: 04/10/2018 -#> - -# ------------------------------------------------------------------------------ -# Initialisation -# ------------------------------------------------------------------------------ -$Path = Split-Path $MyInvocation.MyCommand.Definition -$Repository = Split-Path $Path -Parent -# Import toolbox -Import-Module "$Repository\PSTK" -Force - -# ------------------------------------------------------------------------------ -# Test objects -# ------------------------------------------------------------------------------ -# Reference -$Reference = [ordered]@{ - Property1 = 1 - Property2 = 2 - Property3 = 3 - Property4 = 4 - Property5 = 5 -} -# Exact match -$Exact = [ordered]@{ - Property1 = 1 - Property2 = 2 - Property3 = 3 - Property4 = 4 - Property5 = 5 -} -# No match -$Inexact = [ordered]@{ - Property1 = 5 - Property2 = 4 - Property3 = 3 - Property4 = 2 - Property5 = 1 -} -# Empty hashtable -$Empty = [ordered]@{} - -# ------------------------------------------------------------------------------ -# Test -# ------------------------------------------------------------------------------ -$CheckExact = Compare-Hashtable -Reference $Reference -Difference $Exact -$CheckInexact = Compare-Hashtable -Reference $Reference -Difference $Inexact -$CheckEmpty = Compare-Hashtable -Reference $Reference -Difference $Empty - -# ------------------------------------------------------------------------------ -# Check outcome -# ------------------------------------------------------------------------------ -if ($CheckExact -And !$CheckInexact -And !$CheckEmpty) { - return $true -} else { - return $false -} diff --git a/Tests/ConvertTo-PDF.ps1 b/Tests/ConvertTo-PDF.ps1 deleted file mode 100644 index 4479f3d..0000000 --- a/Tests/ConvertTo-PDF.ps1 +++ /dev/null @@ -1,51 +0,0 @@ -<# - .SYNOPSIS - ConvertTo-PDF Unit Testing - - .DESCRIPTION - Unit Test for ConvertTo-PDF function from PSTK module - - .NOTES - File name: ConvertTo-PDF.ps1 - Author: Florian Carrier - Creation date: 26/09/2018 - Last modified: 26/09/2018 -#> - -# ------------------------------------------------------------------------------ -# Initialisation -# ------------------------------------------------------------------------------ -$Path = Split-Path $MyInvocation.MyCommand.Definition -$Repository = Split-Path $Path -Parent -# Import toolbox -Import-Module "$Repository\PSTK" -Force - -# ------------------------------------------------------------------------------ -# Test objects -# ------------------------------------------------------------------------------ -$DocumentPath = Join-Path -Path $Path -ChildPath ".\res" -$PDF = "*.pdf" -$Expected = @("Test Word 97-2003 Document.pdf", "Test Word Document.pdf") - -# ------------------------------------------------------------------------------ -# Test -# ------------------------------------------------------------------------------ -$Check1 = ConvertTo-PDF -Path $DocumentPath -$Generated = Get-ChildItem -Path $DocumentPath -Filter $PDF | Select -Expand "Name" -$Compare = Compare-Object -ReferenceObject $Generated -DifferenceObject $Expected -PassThru -if ($Compare -eq $null) { - $Check2 = $true -} else { - $Check2 = $false -} -# Clean-up -Remove-Item -Path "$DocumentPath\*" -Filter $PDF - -# ------------------------------------------------------------------------------ -# Check outcome -# ------------------------------------------------------------------------------ -if ($Check1 -And $Check2) { - return $true -} else { - return $false -} diff --git a/Tests/ConvertTo-TitleCase.ps1 b/Tests/ConvertTo-TitleCase.ps1 deleted file mode 100644 index 970385d..0000000 --- a/Tests/ConvertTo-TitleCase.ps1 +++ /dev/null @@ -1,63 +0,0 @@ -<# - .SYNOPSIS - ConvertTo-TitleCase Unit Testing - - .DESCRIPTION - Unit Test for ConvertTo-TitleCase function from PSTK module - - .NOTES - File name: ConvertTo-TitleCase.ps1 - Author: Florian Carrier - Creation date: 05/10/2018 - Last modified: 16/10/2018 -#> - -# ------------------------------------------------------------------------------ -# Initialisation -# ------------------------------------------------------------------------------ -$Path = Split-Path -Path (Split-Path -Path $MyInvocation.MyCommand.Definition) -Parent -$Repository = Join-Path -Path $Path -ChildPath "Private" -# Import functions -$Scripts = @( - $MyInvocation.MyCommand.Name -) -foreach ($Script in $Scripts) { - $Link = Join-Path -Path $Repository -ChildPath $Script - . $Link -} - -# ------------------------------------------------------------------------------ -# Test objects -# ------------------------------------------------------------------------------ -$Strings = [Ordered]@{ - Letter = "L" - Word = "Lorem" - Sentence = "Lorem ipsum dolor sit amet, consectetur adipiscing elit." - Test = "lOrEm" -} -$Expected = [Ordered]@{ - Letter = "L" - Word = "Lorem" - Sentence = "Lorem Ipsum Dolor Sit Amet, Consectetur Adipiscing Elit." - Test = "Lorem" -} - - -# ------------------------------------------------------------------------------ -# Test -# ------------------------------------------------------------------------------ -$Check = $true -foreach ($Entry in $Strings.GetEnumerator()) { - $Key = $Entry.Key - $String = $Entry.Value - $FormattedString = ConvertTo-TitleCase -String $String - if ($FormattedString -ne $Expected.$Key) { - $Check = $false - break - } -} - -# ------------------------------------------------------------------------------ -# Check outcome -# ------------------------------------------------------------------------------ -return $Check diff --git a/Tests/Copy-OrderedHashtable.ps1 b/Tests/Copy-OrderedHashtable.ps1 deleted file mode 100644 index 40ef29f..0000000 --- a/Tests/Copy-OrderedHashtable.ps1 +++ /dev/null @@ -1,68 +0,0 @@ -<# - .SYNOPSIS - Copy-OrderedHashtable Unit Testing - - .DESCRIPTION - Unit Test for Copy-OrderedHashtable function from PSTK module - - .NOTES - File name: Copy-OrderedHashtable.ps1 - Author: Florian Carrier - Creation date: 31/08/2018 - Last modified: 04/10/2018 -#> - -# ------------------------------------------------------------------------------ -# Initialisation -# ------------------------------------------------------------------------------ -$Path = Split-Path $MyInvocation.MyCommand.Definition -$Repository = Split-Path $Path -Parent -# Import toolbox -Import-Module "$Repository\PSTK" -Force - -# ------------------------------------------------------------------------------ -# Test objects -# ------------------------------------------------------------------------------ -# Simple -$Simple = [ordered]@{ - Property1 = 1 - Property2 = 2 - Property3 = 3 - Property4 = 4 - Property5 = 5 -} -# Complex -$Complex = [ordered]@{ - Section1 = [ordered]@{ - Property1 = 1 - Property2 = 2 - } - Property3 = 3 - Section2 = [ordered]@{ - Property4 = 4 - Property5 = 5 - } -} -# Empty hashtable -$Empty = [ordered]@{} - -# ------------------------------------------------------------------------------ -# Test -# ------------------------------------------------------------------------------ -$CloneSimple = Copy-OrderedHashtable -Hashtable $Simple -$CheckSimple = Compare-Hashtable -Reference $CloneSimple -Difference $Simple - -$CloneComplex = Copy-OrderedHashtable -Hashtable $Complex -$CheckComplex = Compare-Hashtable -Reference $CloneComplex -Difference $Complex - -$CloneEmpty = Copy-OrderedHashtable -Hashtable $Empty -$CheckEmpty = Compare-Hashtable -Reference $CloneEmpty -Difference $Empty - -# ------------------------------------------------------------------------------ -# Check outcome -# ------------------------------------------------------------------------------ -if ($CloneSimple -And $CheckComplex -And $CheckEmpty) { - return $true -} else { - return $false -} diff --git a/Tests/Format-String.ps1 b/Tests/Format-String.ps1 deleted file mode 100644 index 9a87573..0000000 --- a/Tests/Format-String.ps1 +++ /dev/null @@ -1,99 +0,0 @@ -<# - .SYNOPSIS - Format-String Unit Testing - - .DESCRIPTION - Unit Test for Format-String function from PSTK module - - .NOTES - File name: Format-String.ps1 - Author: Florian Carrier - Creation date: 05/10/2018 - Last modified: 05/10/2018 -#> - -# ------------------------------------------------------------------------------ -# Initialisation -# ------------------------------------------------------------------------------ -$Path = Split-Path $MyInvocation.MyCommand.Definition -$Repository = Split-Path $Path -Parent -# Import toolbox -Import-Module "$Repository\PSTK" -Force - -# ------------------------------------------------------------------------------ -# Test objects -# ------------------------------------------------------------------------------ -$Strings = [Ordered]@{ - Letter = "L" - Word = "Lorem" - Sentence = "Lorem ipsum dolor sit amet, consectetur adipiscing elit." - Test = "lOrEm" -} -$Expected = [Ordered]@{ - Letter = [Ordered]@{ - CamelCase = "l" - KebabCase = "l" - LowerCase = "l" - PaslcalCase = "L" - SentenceCase = "L" - SnakeCase = "l" - TitleCase = "L" - TrainCase = "L" - UpperCase = "L" - } - Word = [Ordered]@{ - CamelCase = "lorem" - KebabCase = "lorem" - LowerCase = "lorem" - PaslcalCase = "Lorem" - SentenceCase = "Lorem" - SnakeCase = "lorem" - TitleCase = "Lorem" - TrainCase = "Lorem" - UpperCase = "LOREM" - } - Sentence = [Ordered]@{ - CamelCase = "loremIpsumDolorSitAmetConsecteturAdipiscingElit" - KebabCase = "lorem-ipsum-dolor-sit-amet-consectetur-adipiscing-elit" - LowerCase = "lorem ipsum dolor sit amet, consectetur adipiscing elit." - PaslcalCase = "LoremIpsumDolorSitAmetConsecteturAdipiscingElit" - SentenceCase = "Lorem ipsum dolor sit amet, consectetur adipiscing elit." - SnakeCase = "lorem_ipsum_dolor_sit_amet_consectetur_adipiscing_elit" - TitleCase = "Lorem Ipsum Dolor Sit Amet, Consectetur Adipiscing Elit." - TrainCase = "Lorem_Ipsum_Dolor_Sit_Amet_Consectetur_Adipiscing_Elit" - UpperCase = "LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT." - } - Test = [Ordered]@{ - CamelCase = "lorem" - KebabCase = "lorem" - LowerCase = "lorem" - PaslcalCase = "Lorem" - SentenceCase = "Lorem" - SnakeCase = "lorem" - TitleCase = "Lorem" - TrainCase = "Lorem" - UpperCase = "LOREM" - } -} - - -# ------------------------------------------------------------------------------ -# Test -# ------------------------------------------------------------------------------ -$Check = $true -foreach ($Entry in $Strings.GetEnumerator()) { - $Key = $Entry.Key - $String = $Entry.Value - foreach ($Format in $Expected.$Key.Keys) { - $FormattedString = Format-String -String $String -Format $Format - if ($FormattedString -ne $Expected.$Key.$Format) { - $Check = $false - break - } - } -} - -# ------------------------------------------------------------------------------ -# Check outcome -# ------------------------------------------------------------------------------ -return $Check diff --git a/Tests/Read-Properties.ps1 b/Tests/Read-Properties.ps1 deleted file mode 100644 index 55460ef..0000000 --- a/Tests/Read-Properties.ps1 +++ /dev/null @@ -1,88 +0,0 @@ -<# - .SYNOPSIS - Read-Properties Unit Testing - - .DESCRIPTION - Unit Test for Read-Properties function from PSTK module - - .NOTES - File name: Read-Properties.ps1 - Author: Florian Carrier - Creation date: 31/08/2018 - Last modified: 16/10/2018 - TODO Fix -#> - -# ------------------------------------------------------------------------------ -# Initialisation -# ------------------------------------------------------------------------------ -$Path = Split-Path -Path $MyInvocation.MyCommand.Definition -$Repository = Split-Path -Path $Path -Parent -$PrivateDirectory = Join-Path -Path $Repository -ChildPath "Private" -# Import module and private functions -Import-Module -Name "$Repository\PSTK" -Force -$Scripts = @( - $MyInvocation.MyCommand.Name, - "Read-Property.ps1" -) -foreach ($Script in $Scripts) { - $Link = Join-Path -Path $PrivateDirectory -ChildPath $Script - . $Link -} -# ------------------------------------------------------------------------------ -# Expected results -# ------------------------------------------------------------------------------ -$PropertyFile = "properties.ini" -# Without Sections -$Expected1 = [Ordered]@{ - "Property1" = "1" - "Property2" = "2" - "Property3" = "3" - "Property4" = "4" - "Property5" = "5" - "Property6" = "6" - "Property7" = "7" - "Property8" = "8" - "Property9" = "9" - "Property10" = "10" -} - -# With Sections -$Expected2 = [Ordered]@{ - "Section1" = [Ordered]@{ - "Property1" = "1" - "Property2" = "2" - "Property3" = "3" - "Property4" = "4" - "Property5" = "5" - } - "Section2" = [Ordered]@{ - "Property6" = "6" - "Property7" = "7" - "Property8" = "8" - "Property9" = "9" - "Property10" = "10" - } -} - -# ------------------------------------------------------------------------------ -# Test -# ------------------------------------------------------------------------------ -# Without Sections -$Properties1 = Read-Properties -File $PropertyFile -Directory "$Path\res" -$Check1 = Compare-Hashtable -Reference $Expected1 -Difference $Properties1 - -# With Sections -$Properties2 = Read-Properties -File $PropertyFile -Directory "$Path\res" -Section -$Check2 = Compare-Hashtable -Reference $Expected2 -Difference $Properties2 - -# ------------------------------------------------------------------------------ -# Check outcome -# ------------------------------------------------------------------------------ -if ($Check1 -And $Check2) { - return $true -} else { - return $false -} - -# Y U NO WORK diff --git a/Tests/Read-Property.ps1 b/Tests/Read-Property.ps1 deleted file mode 100644 index 4184b27..0000000 --- a/Tests/Read-Property.ps1 +++ /dev/null @@ -1,61 +0,0 @@ -<# - .SYNOPSIS - Read-Property Unit Testing - - .DESCRIPTION - Unit Test for Read-Property function from PSTK module - - .NOTES - File name: Read-Property.ps1 - Author: Florian Carrier - Creation date: 31/08/2018 - Last modified: 16/10/2018 -#> - -# ------------------------------------------------------------------------------ -# Initialisation -# ------------------------------------------------------------------------------ -$Path = Split-Path -Path (Split-Path -Path $MyInvocation.MyCommand.Definition) -Parent -$Repository = Join-Path -Path $Path -ChildPath "Private" -# Import functions -$Scripts = @( - $MyInvocation.MyCommand.Name -) -foreach ($Script in $Scripts) { - $Link = Join-Path -Path $Repository -ChildPath $Script - . $Link -} - -# ------------------------------------------------------------------------------ -# Expected results -# ------------------------------------------------------------------------------ -$Expected = [ordered]@{ - Key = "Property Name" - Value = "Property Value" -} - -# ------------------------------------------------------------------------------ -# Test -# ------------------------------------------------------------------------------ -$Property1 = Read-Property -Content "Property Name = Property Value" -$Property2 = Read-Property -Content "Property Name Property Value" -$Property3 = Read-Property -Content "Property Name = Property=Value" -$Property4 = Read-Property -Content "Property Name =Property Value" -$Property5 = Read-Property -Content "Property Name=Property Value" -$Property6 = Read-Property -Content "Property Name= Property Value" - -$Check1 = Compare-Hashtable -Reference $Expected -Difference $Property1 -$Check2 = Compare-Hashtable -Reference $Expected -Difference $Property2 -$Check3 = Compare-Hashtable -Reference $Expected -Difference $Property3 -$Check4 = Compare-Hashtable -Reference $Expected -Difference $Property4 -$Check5 = Compare-Hashtable -Reference $Expected -Difference $Property5 -$Check6 = Compare-Hashtable -Reference $Expected -Difference $Property6 - -# ------------------------------------------------------------------------------ -# Check outcome -# ------------------------------------------------------------------------------ -if ($Check1 -And !$Check2 -And !$Check3 -And $Check4 -And $Check5 -And $Check6) { - return $true -} else { - return $false -} diff --git a/Tests/Write-Log.ps1 b/Tests/Write-Log.ps1 deleted file mode 100644 index e35045a..0000000 --- a/Tests/Write-Log.ps1 +++ /dev/null @@ -1,71 +0,0 @@ -<# - .SYNOPSIS - Write-Log Unit Testing - - .DESCRIPTION - Unit Test for Write-Log procedure from PSTK module - - .NOTES - File name: Write-Log.ps1 - Author: Florian Carrier - Creation date: 16/10/2018 - Last modified: 16/10/2018 - TODO Does not work, find workaround -#> - -# ------------------------------------------------------------------------------ -# Initialisation -# ------------------------------------------------------------------------------ -$Path = Split-Path -Path (Split-Path -Path $MyInvocation.MyCommand.Definition) -Parent -$Repository = Join-Path -Path $Path -ChildPath "Private" -# Import toolbox -Import-Module "$Path\PSTK" -Force -# Import functions -$Scripts = @( - "Select-WriteHost.ps1" -) -foreach ($Script in $Scripts) { - $Link = Join-Path -Path $Repository -ChildPath $Script - . $Link -} - -# ------------------------------------------------------------------------------ -# Test objects -# ------------------------------------------------------------------------------ -$File = "$($MyInvocation.MyCommand.Name).log" -$Outputs = [Ordered]@{ - "CHECK" = "This is a checkpoint message." - "ERROR" = "This is an error message." - "INFO" = "This is an informational message." - "WARN" = "This is a warning message." -} -# Expected output -$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" -$Expected = @" -$Timestamp`tCHECK`tThis is a checkpoint message. -$Timestamp`tERROR`tThis is an error message. -$Timestamp`tINFO`tThis is an informational message. -$Timestamp`tWARN`tThis is a warning message. -"@ - -# ------------------------------------------------------------------------------ -# Test -# ------------------------------------------------------------------------------ -# Generate log -foreach ($Output in $Outputs.GetEnumerator()) { - $null = Select-WriteHost -ScriptBlock { Write-Log -Type $Output.Name -Message $Output.Value } -OutputFile $File -Quiet -} -# Check output -$FileContent = Get-Content -Path $File -Raw -if ($FileContent -eq $Expected) { - $Check = $true -} else { - $Check = $false -} -# Clean-up -Remove-Item -Path $File - -# ------------------------------------------------------------------------------ -# Check outcome -# ------------------------------------------------------------------------------ -return $Check diff --git a/Tests/res/Test Word 97-2003 Document.doc b/Tests/res/Test Word 97-2003 Document.doc deleted file mode 100644 index a19672d..0000000 Binary files a/Tests/res/Test Word 97-2003 Document.doc and /dev/null differ diff --git a/Tests/res/Test Word Document.docx b/Tests/res/Test Word Document.docx deleted file mode 100644 index 2329e2e..0000000 Binary files a/Tests/res/Test Word Document.docx and /dev/null differ diff --git a/Tests/res/properties.ini b/Tests/res/properties.ini deleted file mode 100644 index e83d9c4..0000000 --- a/Tests/res/properties.ini +++ /dev/null @@ -1,15 +0,0 @@ -# Some properties -[Section1] -Property1 = 1 -Property2 = 2 -Property3 = 3 -Property4 = 4 -Property5 = 5 - -; Some more properties -[Section2] -Property6 = 6 -Property7 = 7 -Property8 = 8 -Property9 = 9 -Property10 = 10