Top Level Namespace

Defined Under Namespace

Classes: GemfileRewrite, PuppetLint, String

Instance Method Summary collapse

Instance Method Details

#run_cmd(message, *cmd) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet-lint/tasks/release_test.rb', line 5

def run_cmd(message, *cmd)
  print("  #{message}... ")

  if Open3.respond_to?(:capture2e)
    output, status = Open3.capture2e(*cmd)
  else
    output = ''

    Open3.popen3(*cmd) do |stdin, stdout, stderr|
      stdin.close
      output += stdout.read
      output += stderr.read
    end
    status = $CHILD_STATUS.dup
  end

  if status.success?
    puts 'Done'
  else
    puts 'FAILED'
  end

  [output.strip, status.success?]
end

#with_puppet_lint_headObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/puppet-lint/tasks/release_test.rb', line 30

def with_puppet_lint_head
  print('  Updating Gemfile to use puppet-lint HEAD... ')

  buffer = Parser::Source::Buffer.new('Gemfile')
  buffer.source = File.read('Gemfile')
  parser = Parser::CurrentRuby.new
  ast = parser.parse(buffer)

  modified_gemfile = GemfileRewrite.new.rewrite(buffer, ast)
  if modified_gemfile == buffer.source
    puppet_lint_root = File.expand_path(File.join(__FILE__, '..', '..', '..', '..'))
    File.open('Gemfile', 'a') do |f|
      f.puts "gem 'puppet-lint', :path => '#{puppet_lint_root}'"
    end
  else
    File.open('Gemfile', 'w') do |f|
      f.puts modified_gemfile
    end
  end

  puts 'Done'

  Bundler.with_clean_env { yield }

  run_cmd('Restoring Gemfile', 'git', 'checkout', '--', 'Gemfile')
end