Skip to content

Commit

Permalink
(PDOC-228) some test fixing and puppet_5? function
Browse files Browse the repository at this point in the history
  • Loading branch information
eputnam committed Mar 24, 2018
1 parent ecfb9d2 commit 0559a21
Show file tree
Hide file tree
Showing 10 changed files with 1,175 additions and 102 deletions.
4 changes: 4 additions & 0 deletions lib/puppet-strings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def self.generate(search_patterns = DEFAULT_SEARCH_PATTERNS, options = {})
end
end

def self.puppet_5?
Puppet::Util::Package.versioncmp(Puppet.version, "5.0.0") >= 0
end

def self.render_json(path)
require 'puppet-strings/json'
PuppetStrings::Json.render(path)
Expand Down
1 change: 1 addition & 0 deletions lib/puppet-strings/yard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def stats_for_puppet_tasks
end

def stats_for_puppet_plans
return unless PuppetStrings.puppet_5?
output 'Puppet Plans', *type_statistics_all(:puppet_plan)
end

Expand Down
10 changes: 5 additions & 5 deletions lib/puppet-strings/yard/parsers/puppet/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def initialize(source, filename)
def parse
begin
Puppet[:tasks] = true if Puppet.settings.include?(:tasks)
@statements ||= (@visitor.visit(::Puppet::Pops::Parser::Parser.new.parse_string(source)) || []).compact
rescue ::Puppet::ParseError => ex
if Puppet::Util::Package.versioncmp(Puppet.version, "5.0.0") < 0 && @file.to_s.match(/^plans\//)
log.error "Failed to parse #{@file}: #{ex.message}. Puppet Plans require Puppet 5 or greater."
else
log.error "Failed to parse #{@file}: #{ex.message}"
log.warn "Skipping #{@file}: Puppet Plans require Puppet 5 or greater."
return
end
@statements ||= (@visitor.visit(::Puppet::Pops::Parser::Parser.new.parse_string(source)) || []).compact
rescue ::Puppet::ParseError => ex
log.error "Failed to parse #{@file}: #{ex.message}"
@statements = []
end
@statements.freeze
Expand Down
39 changes: 1 addition & 38 deletions spec/fixtures/unit/json/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -647,43 +647,6 @@
}
],
"puppet_plans": [
{
"name": "plann",
"file": "(stdin)",
"line": 19,
"docstring": {
"text": "A simple plan.",
"tags": [
{
"tag_name": "param",
"text": "First param.",
"types": [
"String"
],
"name": "param1"
},
{
"tag_name": "param",
"text": "Second param.",
"types": [
"Any"
],
"name": "param2"
},
{
"tag_name": "param",
"text": "Third param.",
"types": [
"Integer"
],
"name": "param3"
}
]
},
"defaults": {
"param3": "1"
},
"source": "plan plann(String $param1, $param2, Integer $param3 = 1) {\n}"
}

]
}
Loading

0 comments on commit 0559a21

Please sign in to comment.