summaryrefslogtreecommitdiffstats
path: root/test/lib/puppettest/fileparsing.rb
blob: bd4f9e1525bef2ff210b39a652c50b61951e4ef5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
require 'test/unit'

module PuppetTest::FileParsing
  # Run an isomorphism test on our parsing process.
  def fakedataparse(*files)
    files.each do |file|
      @provider.stubs(:default_target).returns(file)

      @provider.prefetch

      text = @provider.to_file(@provider.target_records(file))
      text.gsub!(/^# HEADER.+\n/, '')

      yield if block_given?

      oldlines = File.readlines(file)
      newlines = text.chomp.split "\n"
      oldlines.zip(newlines).each do |old, new|
        if self.is_a?(Test::Unit::TestCase)
          assert_equal(old.chomp.gsub(/\s+/, ''), new.gsub(/\s+/, ''), "File was not written back out correctly")
        else
          new.gsub(/\s+/, '').should == old.chomp.gsub(/\s+/, '')
        end
      end
    end
  end
end