From c3ee66e5c5966acf38507a745d91304018714b30 Mon Sep 17 00:00:00 2001 From: Johan Holmberg Date: Wed, 16 Nov 2016 17:47:03 +0100 Subject: [PATCH] detect mixed line ending on Windows --- lib/cmdtest/util.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/cmdtest/util.rb b/lib/cmdtest/util.rb index 00295eb..d5a2b2b 100644 --- a/lib/cmdtest/util.rb +++ b/lib/cmdtest/util.rb @@ -91,7 +91,21 @@ module Cmdtest if ! extern_text.valid_encoding? raise AssertFailed, "ERROR: unexpected encoding: #{@name} not '#{encoding}'" end - return extern_text.encode('utf-8') + str = extern_text.encode('utf-8') + if Util.windows? + has_nl = str.gsub("\n", "") != str + has_crnl = str.gsub("\r\n", "") != str + + if has_nl && ! has_crnl + raise AssertFailed, "ERROR: UNIX line ending: #{@name}" + elsif str.gsub("\r", "").gsub("\n", "") == str.gsub("\r\n", "") + return str.gsub("\r\n", "\n") + else + raise AssertFailed, "ERROR: mixed line ending: #{@name}" + end + else + return str + end end end