Skip to content

(#307) Always enable plan parsing #312

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

Merged
merged 3 commits into from
Sep 29, 2022

Conversation

danielparks
Copy link
Contributor

This is an alternate to #311, which fixes this same problem in a different way. I like this solution better.

Catch parse failures in PuppetStrings::Json tests

Previously, the tests for PuppetStrings::Json (in json_spec.rb) parsed a variety of code samples and then queried YARD to test the results. Ifa sample failed to parse, an error might be outputted (see issue #307), but no failure was registered by the testing harness.

This adds simple checks to verify that the parses actually succeed.

Unfortunately, one of the samples currently fails to parse, so this commit introduces a testing error. The subbsequent commit will fix it.

(#307) Fix plan parsing in JSON spec tests

Previously, the parsing code activated task support in Puppet when it detected that it was parsing a file in a plans/ directory. This casued the JSON spec test for plans to fail because it parsed a string, which naturally had no file name to check.

This turns on task support (and thus enables parsing plans) whenever the parser starts (assuming that task support is available).

This helps avoid surprises to future users who need to parse plans from ruby code, such as in tests.

Add a plan test to parser_spec.rb

Previously, none of the examples in parser_spec.rb included a Puppet plan. This adds a plan and verifies that it parses correctly.

@chelnak
Copy link
Contributor

chelnak commented Sep 28, 2022

I think I like this version too. I can't immediately think of anything negative that would come out of it..

@danielparks danielparks marked this pull request as draft September 29, 2022 09:18
Previously, the tests for `PuppetStrings::Json` (in json_spec.rb) parsed
a variety of code samples and then queried YARD to test the results. If
a sample failed to parse, an error might be outputted (see [issue
puppetlabs#307][puppetlabs#307]), but no failure was registered by the testing harness.

This adds simple checks to verify that the parses actually succeed.

Unfortunately, one of the samples currently fails to parse, so this
commit introduces a testing error. The subbsequent commit will fix it.

[puppetlabs#307]: puppetlabs#307
Previously, the parsing code activated task support in Puppet when it
detected that it was parsing a file in a plans/ directory. This casued
the JSON spec test for plans to fail because it parsed a string, which
naturally had no file name to check.

This turns on task support (and thus enables parsing plans) whenever the
parser starts (assuming that task support is available).

This helps avoid surprises to future users who need to parse plans from
ruby code, such as in tests.
Previously, none of the examples in parser_spec.rb included a Puppet
plan. This adds a plan and verifies that it parses correctly.
# The parsing code actually checks this and sets a global (Puppet[:tasks]).
# Plan parsing will fail if it hasn't yet encountered a file under plans/.
let(:file) { 'plans/test.pp' }
let(:source) { <<~'SOURCE' }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m using a slightly different style with this heredoc. It seems close to the recommended Ruby style (e.g. foo(<<EOF)), though the Ruby style guide doesn’t say anything about single line blocks.

I’m happy to switch over to wrapping it with the block more like above if that’s what’s preferred. Something like:

let(:source) do
  <<~'SOURCE'
    # . . .
  SOURCE
end

I figured the squiggly heredoc is better regardless (it’s been supported since Ruby 2.3). I can update all the other heredocs in the tests in a separate PR if you’re interested — I didn’t want to pollute this one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds sensible. I think the work would be a good candidate for a fresh PR 👍

@danielparks
Copy link
Contributor Author

I’m going to go ahead and close #311 (thought I’ll keep I’ll keep the branch around until this is merged).

@danielparks danielparks marked this pull request as ready for review September 29, 2022 09:35
@chelnak chelnak self-assigned this Sep 29, 2022
@chelnak chelnak added the bug label Sep 29, 2022
@chelnak chelnak merged commit ece8be7 into puppetlabs:main Sep 29, 2022
@danielparks danielparks deleted the fix_plan_parsing 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