File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed
Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ def run
6565 end
6666
6767 next unless PuppetLint . configuration . fix && l . problems . none? { |r | r [ :check ] == :syntax }
68- File . open ( f , 'w ' ) do |fd |
68+ File . open ( f , 'wb ' ) do |fd |
6969 fd . write ( l . manifest )
7070 end
7171 end
Original file line number Diff line number Diff line change 11require 'spec_helper'
22require 'rspec/mocks'
33require 'optparse'
4+ require 'tempfile'
45
56class CommandRun
67 attr_accessor :stdout , :stderr , :exitstatus
@@ -442,4 +443,50 @@ def initialize(args)
442443
443444 its ( :stdout ) { is_expected . to match ( %r{WARNING: lint:ignore:140chars comment on line 2 with no closing lint:endignore comment} ) }
444445 end
446+
447+ context 'when fixing a file with \n line endings' do
448+ before ( :context ) do
449+ @windows_file = Tempfile . new ( 'windows' )
450+ @posix_file = Tempfile . new ( 'posix' )
451+
452+ @windows_file . binmode
453+ @posix_file . binmode
454+
455+ @windows_file . write ( "\r \n " )
456+ @posix_file . write ( "\n " )
457+
458+ @windows_file . close
459+ @posix_file . close
460+ end
461+
462+ after ( :context ) do
463+ @windows_file . unlink
464+ @posix_file . unlink
465+ end
466+
467+ let ( :args ) do
468+ [
469+ '--fix' ,
470+ @posix_file . path ,
471+ @windows_file . path ,
472+ ]
473+ end
474+
475+ its ( :exitstatus ) { is_expected . to eq ( 0 ) }
476+
477+ it 'does not change the line endings' do
478+ File . open ( @posix_file . path , 'rb' ) do |f |
479+ data = f . read
480+
481+ expect ( data ) . to match ( %r{\n \Z }m )
482+ expect ( data ) . to_not match ( %r{\r \n \Z }m )
483+ end
484+
485+ File . open ( @windows_file . path , 'rb' ) do |f |
486+ data = f . read
487+
488+ expect ( data ) . to match ( %r{\r \n \Z }m )
489+ end
490+ end
491+ end
445492end
You can’t perform that action at this time.
0 commit comments