Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration option reports originalvalue true after modification #1971

Closed
fflaten opened this issue Jun 5, 2021 · 4 comments · Fixed by #1994
Closed

Configuration option reports originalvalue true after modification #1971

fflaten opened this issue Jun 5, 2021 · 4 comments · Fixed by #1994
Milestone

Comments

@fflaten
Copy link
Collaborator

fflaten commented Jun 5, 2021

General summary of the issue

Options in the PesterConfiguration-object includes a IsOriginalValue() to indicate if they have been modified by the user, even if the option currently has equal value to the default.

If a user directly modifies the Value-property which holds the current value on a option, this flag isn't flipped like it should be. This affects any "auto" logic for options and merging of configuration.

Describe your environment

Pester version : 5.2.0 C:\Users\Frode\Documents\PowerShell\Modules\pester\5.2.0\Pester.psm1
PowerShell version : 7.1.3
OS version : Microsoft Windows NT 10.0.19042.0

Also in latest 5.3.0 alpha.

Steps to reproduce

$c = (New-PesterConfiguration)
$c.Run.Path; write-Host "Original: $($c.Run.Path.IsOriginalValue())" -ForegroundColor Yellow

Original: True
Default Description                                                                                 Value
------- -----------                                                                                 -----
{.}     Directories to be searched for tests, paths directly to test files, or combination of both. {.}

$c.Run.Path.Value = 'Something new'
$c.Run.Path; write-Host "Original: $($c.Run.Path.IsOriginalValue())" -ForegroundColor Yellow

Original: True
Default Description                                                                                 Value
------- -----------                                                                                 -----
{.}     Directories to be searched for tests, paths directly to test files, or combination of both. {Something new}

Expected Behavior

IsOriginalValue() should not say true when value has been modified

Current Behavior

IsOriginalValue() says true when it should be false

Possible Solution? (optional)

This is caused by the assumption that all values is set using the option-property itself which uses constructors to cast values of different types and not that the user can modify the Value-property directly. The logic that flips the _isOriginalValue flag is only done in the constructors. Two possible solutions:

Having access to modify Value makes it easy to modify some array-options, but it's not critical. Ex.

$c.Debug.WriteDebugMessagesFrom.Value += 'MyForgottenCategory'
# vs
$c.Debug.WriteDebugMessagesFrom = $c.Debug.WriteDebugMessagesFrom.Value + @('MyForgottenCategory')
@nohwnd
Copy link
Member

nohwnd commented Jun 5, 2021

OK on making the value setter private, imho that is a good solution.

@nohwnd nohwnd added this to the 5.3 milestone Jun 5, 2021
@indented-automation
Copy link
Contributor

This will likely break my deserializer. There are tests for the deserializer, but it currently depends on being able to set Value.

@fflaten
Copy link
Collaborator Author

fflaten commented Jun 13, 2021

This will likely break my deserializer. There are tests for the deserializer, but it currently depends on being able to set Value.

Replacing section.configurationItem.Value = ... with section.configurationItem = ... should fix that. Accepted values types will be casted and assigned to the Value-property automatically.

Update: Rewrote as concept-/pseudocode

@indented-automation
Copy link
Contributor

Great, I've removed use of .Value on set away in my PR.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants