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

(#240) Fix output of default values that are expressions #315

Merged
merged 1 commit into from
Sep 29, 2022

Conversation

danielparks
Copy link
Contributor

Previously, parameters with a default value that was an expression were not outputted into the documentation correctly. For example,

Integer $param = 1 + 1,

Would be shown in the documentation to have a default value of “+”.

This switches to using extract_tree_text instead of extract_text to get the text representation of the parsed Puppet code.

This also gets rid of the dependency on Puppet::Pops::Adapters::SourcePosAdapter, which was deprecated in 2017.

Unfortunately, it appears that there is a bug in Puppet (PUP-11632) that sometimes returns the incorrect default value. This adds two skipped tests that demonstrate the issue.

@danielparks danielparks requested a review from a team as a code owner September 27, 2022 01:03
@danielparks
Copy link
Contributor Author

I was going to let this sit until I heard back about PUP-11632, but I figured that this was an improvement even with the bug.

@chelnak
Copy link
Contributor

chelnak commented Sep 28, 2022

I like this change. I'm just trying to weigh up the behaviour change.

Does it put users in a better position? Or would this only occur some of the time?

@danielparks danielparks marked this pull request as draft September 29, 2022 09:05
Previously, parameters with a default value that was an expression were
not outputted into the documentation correctly. For example,

    Integer $param = 1 + 1,

Would be shown in the documentation to have a default value of “+”.

This switches to using `extract_tree_text` instead of `extract_text` to
get the text representation of the parsed Puppet code.

This also gets rid of the dependency on
`Puppet::Pops::Adapters::SourcePosAdapter`, which was [deprecated in
2017](puppetlabs/puppet@68498ad).

Unfortunately, it appears that there is a bug in Puppet ([PUP-11632][])
that sometimes returns the incorrect default value. This adds two
skipped tests that demonstrate the issue.

[PUP-11632]: https://tickets.puppetlabs.com/browse/PUP-11632
@danielparks danielparks marked this pull request as ready for review September 29, 2022 09:10
@danielparks
Copy link
Contributor Author

You’re asking how often the PUP-11632 bug occurs and gives a bad default value?

It seems fairly rare. So far I’ve only found two cases, which are both documented in the bug and in the unit tests attached to this PR.

It seems to have much less impact than the bug this PR fixes. As is, you often get what appears to be an incomprehensible fragment of the default value, e.g. + instead of 1 + 1, or (': ')[0] instead of split($name, ': ')[0].

With this PR you get a few munged values, but so far it’s only been a missing final character, e.g. $foo.func( instead of $foo.func().

@chelnak
Copy link
Contributor

chelnak commented Sep 29, 2022

@danielparks thanks for the explanation .. it's much clearer now.

I'm happy to get this merged!

@chelnak chelnak added the bug label Sep 29, 2022
@chelnak chelnak self-assigned this Sep 29, 2022
@chelnak chelnak merged commit f98873d into puppetlabs:main Sep 29, 2022
@danielparks danielparks deleted the fix_default_expressions branch September 29, 2022 11:18
@chelnak chelnak added bugfix and removed bug labels Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants